Fix bad web search error messages#2034
Conversation
boceckts
left a comment
There was a problem hiding this comment.
Some minor changes are needed otherwise it looks good to me 👍
| - [#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.
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.
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.
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.
I exported them into the two main Dialog classes.
| hasRunConfig = true; | ||
| } | ||
| Map<String, JLabel> citations = getCitations(query); | ||
| if (citations.size() == 0) { |
There was a problem hiding this comment.
Replace with citations.isEmpty().
| preview.addEntry(linkEntry.getKey(), linkEntry.getValue()); | ||
| } | ||
|
|
||
| return true; |
There was a problem hiding this comment.
Put this block in the else statement and set one return false at the end of the method instead of the two.
| return false; | ||
| int numberToFetch = result.count; | ||
| if (numberToFetch > MedlineFetcher.PACING) { | ||
| while (true) { |
There was a problem hiding this comment.
Please use a variable and just set it to false instead of using break.
| 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.
For me this this too much generalization, use the same error message for all IOExceptions and maybe InterruptedExceptions for the fetchers, but I think the error message doesn't make sense when an SAXException occurs!?
There was a problem hiding this comment.
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.
In my opinion yes, a SAXException won't be resolved by retrying or checking the internet connection.
There was a problem hiding this comment.
Now the SAXException will be shown to the user.
| JOptionPane.showMessageDialog(this, message); | ||
| } | ||
|
|
||
| public void showErrorMessage(EntryFetcher fetcher) { |
There was a problem hiding this comment.
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 👍
| 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.
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.
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.
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.
Please don't catch exceptions in tests.
There was a problem hiding this comment.
Moved them to the method signature.
Siedlerchr
left a comment
There was a problem hiding this comment.
In general looks good. Apart from the UTF8 thing, rest is minor. 👍
| LOGGER.error("Error while fetching from " + getTitle(), e); | ||
| preview.showErrorMessage(this.getTitle(), e.getLocalizedMessage()); | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Why is the return false moved inside the catch?
There was a problem hiding this comment.
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.
String.Format would look cleaner here, etc, use %1s, %2s for the arguments
There was a problem hiding this comment.
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.
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")))) { |
|
|
||
| String searchTerm = toSearchTerm(query); | ||
| String cleanQuery = query.trim().replace(';', ','); | ||
| if (cleanQuery.matches("\\d+[,\\d+]*")) { |
There was a problem hiding this comment.
Could you please extract that to a Pattern, too?
| if (numberToFetch > MedlineFetcher.PACING) { | ||
| boolean numberEntered = false; | ||
| do { | ||
| String strCount = JOptionPane.showInputDialog(Localization.lang("References found") + ": " + numberToFetch + " " + |
There was a problem hiding this comment.
Same as above, String.format
| iIDialog.addEntry(entry); | ||
| List<BibEntry> bibs = fetchMedline(result.ids, status); | ||
| for (BibEntry entry : bibs) { | ||
| dialog.addEntry(entry); |
There was a problem hiding this comment.
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
| if (numberToFetch > MAX_PER_PAGE) { | ||
| boolean numberEntered = false; | ||
| do { | ||
| String strCount = JOptionPane.showInputDialog(Localization.lang("References found") +": "+ numberToFetch + " " + |
lenhard
left a comment
There was a problem hiding this comment.
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).