-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bad web search error messages #2034
Fix bad web search error messages #2034
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor changes are needed otherwise it looks good to me 👍
@@ -43,6 +43,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# | |||
- [#2012](https://github.com/JabRef/jabref/issues/2012) Implemented integrity check for `month` field: Should be an integer or normalized (BibLaTeX), Should be normalized (BibTeX) | |||
|
|||
### Fixed | |||
- Improved error messages when using fetcher |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would put it in the changed section, also please add the issue number and url to your description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's up for debate. Before the error messages didn't work as intended (or didn't work at all).
status.showMessage(e.getMessage(), | ||
LOGGER.error("Error while fetching from " + getTitle(), e); | ||
status.showMessage(Localization.lang("Error while fetching from %0", getTitle()) +"\n"+ | ||
Localization.lang("Please try again later and/or check your network connection."), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You use this code fragment in all the fetchers, which is why I would extract it to a (dialog) utility class, I'm not sure if there already exists one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I exported them into the two main Dialog classes.
@@ -82,14 +83,22 @@ public boolean processQueryGetPreview(String query, FetcherPreviewDialog preview | |||
hasRunConfig = true; | |||
} | |||
Map<String, JLabel> citations = getCitations(query); | |||
if (citations.size() == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replace with citations.isEmpty()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
for (Map.Entry<String, JLabel> linkEntry : citations.entrySet()) { | ||
preview.addEntry(linkEntry.getKey(), linkEntry.getValue()); | ||
} | ||
|
||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put this block in the else statement and set one return false
at the end of the method instead of the two.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return false; | ||
int numberToFetch = result.count; | ||
if (numberToFetch > MedlineFetcher.PACING) { | ||
while (true) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use a variable and just set it to false
instead of using break
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
status.setStatus(Localization.lang("Error while fetching from %0", "OAI2")); | ||
LOGGER.error("Error while fetching from OAI2", e); | ||
} catch (IOException | SAXException | InterruptedException e) { | ||
LOGGER.error("Error while fetching from " + getTitle(), e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me this this too much generalization, use the same error message for all IOException
s and maybe InterruptedException
s for the fetchers, but I think the error message doesn't make sense when an SAXException
occurs!?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it have any additional value for the user if they know that is was a SAX exception?
They can't do anything about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my opinion yes, a SAXException
won't be resolved by retrying or checking the internet connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now the SAXException
will be shown to the user.
@@ -302,4 +303,10 @@ public void showMessage(String message, String title, int msgType) { | |||
public void showMessage(String message) { | |||
JOptionPane.showMessageDialog(this, message); | |||
} | |||
|
|||
public void showErrorMessage(EntryFetcher fetcher) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would change the interface to public void showFetchingErrorMessage(String fetcherName)
since you don't need the whole fetcher object and the name is more specific for the fetchers. When creating public utility methods it's also good to have a javadoc comment describing it's functionality as it should also be used by others in the future. Other than that I'm fine with your changes 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
status.setStatus(e.getLocalizedMessage()); | ||
LOGGER.error("Error while fetching from" + fetcher.getName(), e); | ||
LOGGER.error("Error while fetching from " + getTitle(), e); | ||
((ImportInspectionDialog)inspector).showErrorMessage(this.getTitle()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You completely ignore the exception details when you call showErrorMessage
, thus the user gets just a standard message although the FetcherException contains all the necessary details about what went wrong (e.getLocalizedMessage
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know how much additional value the end user has from : java.net.UnknownHostException: doaj.org
, but I appended the localized message to the dialog nonetheless.
status.setStatus(e.getLocalizedMessage()); | ||
LOGGER.error("Error while fetching from" + fetcher.getName(), e); | ||
LOGGER.error("Error while fetching from " + getTitle(), e); | ||
((ImportInspectionDialog)inspector).showErrorMessage(this.getTitle()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above: exception information is ignored
Assert.assertEquals(Optional.of("Javier López Peña and Gabriel Navarro"), be.getField("author")); | ||
Assert.assertEquals(Optional.of("2007"), be.getField("year")); | ||
} catch (IOException | SAXException e) { | ||
LOGGER.error("Test probably failed due internet problems"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't catch exceptions in tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved them to the method signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general looks good. Apart from the UTF8 thing, rest is minor. 👍
LOGGER.warn("Problem with ACM Portal", e); | ||
LOGGER.error("Error while fetching from " + getTitle(), e); | ||
preview.showErrorMessage(this.getTitle(), e.getLocalizedMessage()); | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the return false moved inside the catch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like to return immediately in general so I forget that branch.
If someone now breaks out of the try-catch (which shouldn't be done) he is forced to deal with it later down.
if (numberToFetch > MAX_PER_PAGE) { | ||
boolean numberEntered = false; | ||
do { | ||
String strCount = JOptionPane.showInputDialog(Localization.lang("References found") +": " + numberToFetch + " " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String.Format would look cleaner here, etc, use %1s, %2s for the arguments
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be best to bind the number to the translation, but then it has to be re-translated b/c the number isn't always at the same spot in every language.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In correspondence with @koppor I combined it to a single translation.
For the user it will change nothing.
|
||
ParserResult pr = BibtexParser.parse(reader, Globals.prefs.getImportFormatPreferences()); | ||
try (INSPIREBibtexFilterReader reader = new INSPIREBibtexFilterReader( | ||
new InputStreamReader(inputStream, Charset.forName("UTF-8")))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StandardCharsets.UTF-8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
|
||
String searchTerm = toSearchTerm(query); | ||
String cleanQuery = query.trim().replace(';', ','); | ||
if (cleanQuery.matches("\\d+[,\\d+]*")) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please extract that to a Pattern, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
if (numberToFetch > MedlineFetcher.PACING) { | ||
boolean numberEntered = false; | ||
do { | ||
String strCount = JOptionPane.showInputDialog(Localization.lang("References found") + ": " + numberToFetch + " " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, String.format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
iIDialog.addEntry(entry); | ||
List<BibEntry> bibs = fetchMedline(result.ids, status); | ||
for (BibEntry entry : bibs) { | ||
dialog.addEntry(entry); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just curious, does the dialog object has a method which accepts a Collection/list of BibEntries?
(Not scope of this PR to add one, but would be nice to have such a method
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it does not.
if (numberToFetch > MAX_PER_PAGE) { | ||
boolean numberEntered = false; | ||
do { | ||
String strCount = JOptionPane.showInputDialog(Localization.lang("References found") +": "+ numberToFetch + " " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as earlier
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I disabled my internet connection and tried out all fetcher. Overall, the error messages are streamlined now, good job!
I was able to find one remaining inconsistency. When you use medline, first a message box pops up (see screenshot). When you close that message box, the error message as for the other messages appears. That box should not be shown, but apart from that the PR is fine.
Uhm... the change in
Occurs on (successful) searches with an internet connection in my branch for #2101 Has anyone else this problem? |
... and there is another problem caused by the same change: The whole UI freezes after some consecutive searches, e.g., using the IEEE fetcher. @bartsch-dev Can you investigate this issues? |
I'll look into it tomorrow evening. |
To get the fetchers back working I just reverted your change in Why have you changed it in your PR? |
To not show the fetcher dialog if the fetching was not successful. |
* upstream/master: (102 commits) Removed unused test code (#2140) Fix main table bug when creating a duplicate (#2135) Remove explicit author and add SPDX-License-Identifier Remove GPL from README.md and CONTRIBUTING.md fix preview update (#2125) Remove some UnicodeToLatex uses (#2132) Fix mixup in french/farsi localization FetcherException should extend JabRefException Fix exception when opening preference dialog (#2127) Unify ParserException and ParseException (#2124) Small refactoring in Importer package (#2053) Implement Datepicker "none"-button (#2122) revert change from 816d30c Change title/tooltip of source panel in biblatex mode (#2120) Refactoring: completey typed metadata and add detailed travis output (#2112) RTFchars fix (#2097) Fix NPE in Medline fetcher on missing ISSN (#2113) Ctrl-s parsing error message (#2114) Fix bad web search error messages (#2034) parse error freeze (#2106) ... # Conflicts: # src/main/java/net/sf/jabref/collab/FileUpdateMonitor.java # src/main/java/net/sf/jabref/gui/externalfiles/DownloadExternalFile.java # src/main/java/net/sf/jabref/gui/externalfiles/DroppedFileHandler.java # src/main/java/net/sf/jabref/gui/externalfiles/MoveFileAction.java # src/main/java/net/sf/jabref/logic/cleanup/RenamePdfCleanup.java # src/main/java/net/sf/jabref/logic/exporter/FileSaveSession.java # src/main/java/net/sf/jabref/logic/util/io/FileUtil.java # src/main/java/net/sf/jabref/preferences/JabRefPreferences.java
* fix bad web search error messages * add changelog * fix localization * fix issues * add JavaDoc, change parameter type of showErrorMessage * show sax error to user * print localized message * remove unused variable * reformat * fix issues
Fixes #1542
I rewrote the error messages when the fetchers fail (or added them).