From 5f6a440cb638aa62d6a7500000bdb8205da83a66 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Wed, 17 Jul 2019 17:28:34 +0200 Subject: [PATCH 1/4] Differentiate Causes of Errors --- .../gui/texparser/ParseTexDialogViewModel.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java b/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java index eab42881f6f..82d39506c36 100644 --- a/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java +++ b/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java @@ -1,6 +1,7 @@ package org.jabref.gui.texparser; import java.io.IOException; +import java.nio.file.FileSystemException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -117,7 +118,6 @@ public void searchButtonClicked() { noFilesFound.set(true); searchInProgress.set(true); successfulSearch.set(false); - }) .onFinished(() -> searchInProgress.set(false)) .onSuccess(newRoot -> { @@ -125,7 +125,19 @@ public void searchButtonClicked() { noFilesFound.set(false); successfulSearch.set(true); }) - .onFailure(dialogService::showErrorDialogAndWait) + .onFailure(exception -> { + root.set(null); + noFilesFound.set(true); + searchInProgress.set(false); + successfulSearch.set(false); + if (exception.getCause() instanceof FileSystemException) { + System.out.println(exception.getCause().getMessage()); + dialogService.showErrorDialogAndWait(String.format("JabRef does not have permission to access %s", exception.getCause().getMessage())); + } else { + dialogService.showErrorDialogAndWait(exception); + } + } + ) .executeWith(taskExecutor); } From b08d80f80a39f1f2ad7e517613c35c800f12ae08 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Thu, 18 Jul 2019 11:37:36 +0200 Subject: [PATCH 2/4] Refactor Failure Mode --- .../texparser/ParseTexDialogViewModel.java | 31 +++++++++++-------- src/main/resources/l10n/JabRef_en.properties | 1 + 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java b/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java index 82d39506c36..853bb337f21 100644 --- a/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java +++ b/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java @@ -7,6 +7,7 @@ import java.nio.file.Paths; import java.util.List; import java.util.Map; +import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -125,22 +126,26 @@ public void searchButtonClicked() { noFilesFound.set(false); successfulSearch.set(true); }) - .onFailure(exception -> { - root.set(null); - noFilesFound.set(true); - searchInProgress.set(false); - successfulSearch.set(false); - if (exception.getCause() instanceof FileSystemException) { - System.out.println(exception.getCause().getMessage()); - dialogService.showErrorDialogAndWait(String.format("JabRef does not have permission to access %s", exception.getCause().getMessage())); - } else { - dialogService.showErrorDialogAndWait(exception); - } - } - ) + .onFailure(handleFailure()) .executeWith(taskExecutor); } + private Consumer handleFailure() { + return exception -> { + root.set(null); + noFilesFound.set(true); + searchInProgress.set(false); + successfulSearch.set(false); + + final boolean permissionProblem = exception instanceof IOException && exception.getCause() instanceof FileSystemException && exception.getCause().getMessage().endsWith("Operation not permitted"); + if (permissionProblem) { + dialogService.showErrorDialogAndWait(String.format(Localization.lang("JabRef does not have permission to access %s"), exception.getCause().getMessage())); + } else { + dialogService.showErrorDialogAndWait(exception); + } + }; + } + private FileNodeViewModel searchDirectory(Path directory) throws IOException { if (directory == null || !directory.toFile().exists() || !directory.toFile().isDirectory()) { throw new IOException("An error occurred while searching an invalid directory."); diff --git a/src/main/resources/l10n/JabRef_en.properties b/src/main/resources/l10n/JabRef_en.properties index 21233729e74..a5a8b2306b2 100644 --- a/src/main/resources/l10n/JabRef_en.properties +++ b/src/main/resources/l10n/JabRef_en.properties @@ -1381,6 +1381,7 @@ Open\ %0\ file=Open %0 file Cannot\ delete\ file=Cannot delete file File\ permission\ error=File permission error +JabRef\ does\ not\ have\ permission\ to\ access\ %s=JabRef does not have permission to access %s Push\ to\ %0=Push to %0 Path\ to\ %0=Path to %0 Convert=Convert From 08bd82e6ebc1ad6b31bc271efb2a90acbf52dbb6 Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Thu, 18 Jul 2019 13:57:47 +0200 Subject: [PATCH 3/4] Remove unnecessary return --- .../texparser/ParseTexDialogViewModel.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java b/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java index 853bb337f21..c7c13994643 100644 --- a/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java +++ b/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java @@ -7,7 +7,6 @@ import java.nio.file.Paths; import java.util.List; import java.util.Map; -import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -126,24 +125,22 @@ public void searchButtonClicked() { noFilesFound.set(false); successfulSearch.set(true); }) - .onFailure(handleFailure()) + .onFailure(this::handleFailure) .executeWith(taskExecutor); } - private Consumer handleFailure() { - return exception -> { - root.set(null); - noFilesFound.set(true); - searchInProgress.set(false); - successfulSearch.set(false); - - final boolean permissionProblem = exception instanceof IOException && exception.getCause() instanceof FileSystemException && exception.getCause().getMessage().endsWith("Operation not permitted"); - if (permissionProblem) { - dialogService.showErrorDialogAndWait(String.format(Localization.lang("JabRef does not have permission to access %s"), exception.getCause().getMessage())); - } else { - dialogService.showErrorDialogAndWait(exception); - } - }; + private void handleFailure(Exception exception) { + root.set(null); + noFilesFound.set(true); + searchInProgress.set(false); + successfulSearch.set(false); + + final boolean permissionProblem = exception instanceof IOException && exception.getCause() instanceof FileSystemException && exception.getCause().getMessage().endsWith("Operation not permitted"); + if (permissionProblem) { + dialogService.showErrorDialogAndWait(String.format(Localization.lang("JabRef does not have permission to access %s"), exception.getCause().getMessage())); + } else { + dialogService.showErrorDialogAndWait(exception); + } } private FileNodeViewModel searchDirectory(Path directory) throws IOException { From f6790ca2192e9a22711a91c8054bb352af02702a Mon Sep 17 00:00:00 2001 From: Linus Dietz Date: Thu, 1 Aug 2019 13:21:37 +0200 Subject: [PATCH 4/4] Remove redundant lines --- .../org/jabref/gui/texparser/ParseTexDialogViewModel.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java b/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java index c7c13994643..46cbab70fa6 100644 --- a/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java +++ b/src/main/java/org/jabref/gui/texparser/ParseTexDialogViewModel.java @@ -130,11 +130,6 @@ public void searchButtonClicked() { } private void handleFailure(Exception exception) { - root.set(null); - noFilesFound.set(true); - searchInProgress.set(false); - successfulSearch.set(false); - final boolean permissionProblem = exception instanceof IOException && exception.getCause() instanceof FileSystemException && exception.getCause().getMessage().endsWith("Operation not permitted"); if (permissionProblem) { dialogService.showErrorDialogAndWait(String.format(Localization.lang("JabRef does not have permission to access %s"), exception.getCause().getMessage()));