Skip to content
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

Merged
merged 12 commits into from
Oct 3, 2016
Merged

Fix bad web search error messages #2034

merged 12 commits into from
Oct 3, 2016

Conversation

chriba
Copy link
Contributor

@chriba chriba commented Sep 22, 2016

Fixes #1542

I rewrote the error messages when the fetchers fail (or added them).

Copy link
Contributor

@boceckts boceckts left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

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."),
Copy link
Contributor

@boceckts boceckts Sep 23, 2016

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace with citations.isEmpty().

Copy link
Contributor Author

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

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.

Copy link
Contributor Author

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);
Copy link
Contributor

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 IOExceptions and maybe InterruptedExceptions for the fetchers, but I think the error message doesn't make sense when an SAXException occurs!?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

@boceckts boceckts Sep 23, 2016

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 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@boceckts boceckts added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 26, 2016
@boceckts boceckts changed the title [WIP] Fix bad web search error messages Fix bad web search error messages Sep 26, 2016
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());
Copy link
Member

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)

Copy link
Contributor Author

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());
Copy link
Member

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");
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

@Siedlerchr Siedlerchr left a 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;
}
Copy link
Member

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?

Copy link
Contributor Author

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 + " " +
Copy link
Member

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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")))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StandardCharsets.UTF-8

Copy link
Contributor Author

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+]*")) {
Copy link
Member

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?

Copy link
Contributor Author

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 + " " +
Copy link
Member

@Siedlerchr Siedlerchr Sep 27, 2016

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

Copy link
Contributor Author

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);
Copy link
Member

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

Copy link
Contributor Author

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 + " " +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as earlier

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see above

@matthiasgeiger matthiasgeiger removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 28, 2016
@boceckts boceckts added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Sep 29, 2016
Copy link
Member

@lenhard lenhard left a 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.

fetcher

@tobiasdiez
Copy link
Member

@zellerdev currently rewrites the medline fetcher #2066.
Probably the strange error message automatically disappears when the medline fetcher is ported to the new interface.
Thus I think it is ok to merge this PR (and double check before merging #2066).

@tobiasdiez tobiasdiez merged commit 816d30c into JabRef:master Oct 3, 2016
@matthiasgeiger
Copy link
Member

Uhm... the change in GeneralFetcher.java causes a quite weird exception:

Exception in thread "JabRef CachedThreadPool" java.lang.IndexOutOfBoundsException: Index: 3, Size: 3
    at java.util.ArrayList.rangeCheck(ArrayList.java:653)
    at java.util.ArrayList.get(ArrayList.java:429)
    at java.awt.Container.createHierarchyEvents(Container.java:1441)
    at java.awt.Container.createHierarchyEvents(Container.java:1441)
    at java.awt.Container.createHierarchyEvents(Container.java:1441)
    at java.awt.Container.createHierarchyEvents(Container.java:1441)
    at java.awt.Container.createHierarchyEvents(Container.java:1441)
    at java.awt.Dialog.conditionalShow(Dialog.java:953)
    at java.awt.Dialog.show(Dialog.java:1037)
    at java.awt.Component.show(Component.java:1673)
    at java.awt.Component.setVisible(Component.java:1625)
    at java.awt.Window.setVisible(Window.java:1014)
    at java.awt.Dialog.setVisible(Dialog.java:1005)
    at net.sf.jabref.gui.importer.fetcher.GeneralFetcher.lambda$actionPerformed$171(GeneralFetcher.java:220)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

Occurs on (successful) searches with an internet connection in my branch for #2101

Has anyone else this problem?

@matthiasgeiger
Copy link
Member

matthiasgeiger commented Oct 4, 2016

... 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?

@chriba
Copy link
Contributor Author

chriba commented Oct 4, 2016

I'll look into it tomorrow evening.

@chriba chriba deleted the fixBadWebSearchErrorMessages branch October 4, 2016 18:13
@matthiasgeiger
Copy link
Member

To get the fetchers back working I just reverted your change in GeneralFetcher.java (see 6daa5b5)

Why have you changed it in your PR?

@chriba
Copy link
Contributor Author

chriba commented Oct 5, 2016

To not show the fetcher dialog if the fetching was not successful.
Now fetcher dialog opens, the error message is on top of that and closes when the error message gets closed.

Siedlerchr added a commit that referenced this pull request Oct 9, 2016
* 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
zesaro pushed a commit to zesaro/jabref that referenced this pull request Nov 22, 2016
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants