Skip to content

Commit c894619

Browse files
committed
Print error to info-label
1 parent 6b2273c commit c894619

File tree

13 files changed

+58
-24
lines changed

13 files changed

+58
-24
lines changed

src/main/java/de/nihas101/image_to_pdf_converter/gui/controller/DirectoryContentDisplayController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ private void startLoadImagesThread(ImageMap imageMap) {
9191
imageMap,
9292
directoryIterator,
9393
new TrivialProgressUpdater(),
94-
() -> {
94+
(success) -> {
9595
setupObservableList(directoryIterator, imageMap);
9696
return Unit.INSTANCE;
9797
});
@@ -158,7 +158,7 @@ public void buildPDF(ActionEvent actionEvent) {
158158

159159
CallClosure callClosure = new CallClosure(
160160
() -> Unit.INSTANCE,
161-
() -> {
161+
(success) -> {
162162
runLater(() -> {
163163
mainWindowController.buildProgressBar.setProgress(0);
164164
mainWindowController.notifyUser("Finished building: " + saveFile.getAbsolutePath(), GREEN);

src/main/java/de/nihas101/image_to_pdf_converter/gui/controller/MainWindowController.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private void startSetupIteratorFromDragAndDropThread(List<File> files) {
126126
disableInput(true);
127127
return Unit.INSTANCE;
128128
},
129-
() -> {
129+
(success) -> {
130130
runLater(() -> {
131131
addRemainingFiles(files);
132132
disableInput(false);
@@ -190,7 +190,7 @@ private void startSetupIteratorThread() {
190190
disableInput(true);
191191
return Unit.INSTANCE;
192192
},
193-
() -> {
193+
(success) -> {
194194
runLater(this::tryToSetupListView);
195195
return Unit.INSTANCE;
196196
});
@@ -230,7 +230,7 @@ private void startLoadImagesThread(DirectoryIterator directoryIterator) {
230230
mainWindow.imageMap,
231231
directoryIterator,
232232
createLoadProgressUpdater(directoryIterator),
233-
() -> {
233+
(success) -> {
234234
setupObservableList(directoryIterator);
235235
return Unit.INSTANCE;
236236
}
@@ -340,14 +340,16 @@ private void startPdfBuilderThread(PdfBuilder pdfBuilder) {
340340
runLater(() -> disableInput(true));
341341
return Unit.INSTANCE;
342342
},
343-
() -> {
343+
(success) -> {
344344
runLater(() -> {
345345
disableInput(false);
346-
notifyUser(
347-
"Finished building: "
348-
+ Objects.requireNonNull(mainWindow.imageToPdfOptions.getPdfOptions().getSaveLocation()).getAbsolutePath(),
349-
GREEN
350-
);
346+
if (success) {
347+
notifyUser(
348+
"Finished building: "
349+
+ Objects.requireNonNull(mainWindow.imageToPdfOptions.getPdfOptions().getSaveLocation()).getAbsolutePath(),
350+
GREEN
351+
);
352+
}
351353
});
352354
return Unit.INSTANCE;
353355
});

src/main/java/de/nihas101/image_to_pdf_converter/gui/sub_stages/DirectoryIteratorDisplayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private void displayDirectory(int index, MainWindowController mainWindowControll
8585
CallClosure callClosure = new CallClosure(() -> {
8686
runLater(() -> mainWindowController.disableInput(true));
8787
return Unit.INSTANCE;
88-
}, () -> {
88+
}, (success) -> {
8989
runLater(() -> {
9090
mainWindowController.buildProgressBar.setProgress(0);
9191
mainWindowController.notifyUser("Files: " + directoryIterator.numberOfFiles(), WHITE);

src/main/kotlin/de/nihas101/image_to_pdf_converter/pdf/builders/ImagePdfBuilder.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,14 @@ package de.nihas101.image_to_pdf_converter.pdf.builders
2121
import com.itextpdf.io.image.ImageDataFactory
2222
import com.itextpdf.layout.element.Image
2323
import de.nihas101.image_to_pdf_converter.directory_iterators.DirectoryIterator
24+
import de.nihas101.image_to_pdf_converter.directory_iterators.exceptions.NoMoreFilesException
2425
import de.nihas101.image_to_pdf_converter.pdf.ImagePdf
2526
import de.nihas101.image_to_pdf_converter.pdf.ImagePdf.ImagePdfFactory.createPdf
2627
import de.nihas101.image_to_pdf_converter.pdf.pdf_options.ImageToPdfOptions
2728
import de.nihas101.image_to_pdf_converter.util.JaKoLogger.createLogger
2829
import de.nihas101.image_to_pdf_converter.util.ProgressUpdater
2930
import java.io.File
31+
import java.io.IOException
3032

3133
class ImagePdfBuilder : PdfBuilder() {
3234
companion object ImagePdfBuilderFactory {
@@ -54,9 +56,12 @@ class ImagePdfBuilder : PdfBuilder() {
5456
addNextFileToPDF(file, imagePdf)
5557
file = directoryIterator.nextFile()
5658
}
57-
} catch (exception: Exception) {
59+
} catch (exception: IOException) {
60+
progressUpdater.reportError("An error occurred building: ${file.name}")
5861
logException(file, exception)
5962
wasSuccess = false
63+
} catch (exception: NoMoreFilesException) {
64+
// END WAS REACHED
6065
} finally {
6166
imagePdf.close()
6267
return wasSuccess
@@ -68,7 +73,7 @@ class ImagePdfBuilder : PdfBuilder() {
6873
args[0] = file.absolutePath
6974
args[1] = exception
7075

71-
logger.error("Exception caused by: {}\n{}", args)
76+
logger.error("Exception caused by: {}", args)
7277
}
7378

7479
private fun createFileAtSameLocation(directoryIterator: DirectoryIterator): File {

src/main/kotlin/de/nihas101/image_to_pdf_converter/tasks/BuildPdfTask.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ class BuildPdfTask private constructor(
3434

3535
override fun call() {
3636
callClosure.before()
37+
var wasSuccessful = false
3738
try {
38-
pdfBuilder.build(directoryIterator, imageToPdfOptions, progressUpdater)
39+
wasSuccessful = pdfBuilder.build(directoryIterator, imageToPdfOptions, progressUpdater)
3940
} catch (exception: InterruptedException) {
4041
/* The task was cancelled */
4142
logger.warn("{}", exception)
4243
}
43-
callClosure.after()
44+
callClosure.after(wasSuccessful)
4445
}
4546

4647
companion object BuildPdfTaskFactory {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package de.nihas101.image_to_pdf_converter.tasks
22

3-
data class CallClosure(val before: () -> Unit = {}, val after: () -> Unit = {})
3+
data class CallClosure(val before: () -> Unit = {}, val after: (Boolean) -> Unit = {})

src/main/kotlin/de/nihas101/image_to_pdf_converter/tasks/LoadImagesTask.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class LoadImagesTask private constructor(
3838
/* The task was cancelled */
3939
logger.warn("{}", exception)
4040
}
41-
callClosure.after()
41+
callClosure.after(true)
4242
}
4343

4444
companion object LoadImagesTaskFactory {
@@ -48,7 +48,7 @@ class LoadImagesTask private constructor(
4848
imageMap: ImageMap,
4949
directoryIterator: DirectoryIterator,
5050
progressUpdater: ProgressUpdater,
51-
after: () -> Unit
51+
after: (Boolean) -> Unit
5252
): LoadImagesTask {
5353
val callClosure = CallClosure(after = after)
5454
return LoadImagesTask(imageMap, directoryIterator, progressUpdater, callClosure)

src/main/kotlin/de/nihas101/image_to_pdf_converter/tasks/SetupIteratorTask.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ open class SetupIteratorTask protected constructor(
3232

3333
override fun call() {
3434
callClosure.before()
35+
var wasSuccess = true
3536
try {
3637
directoryIterator.addDirectory(directory, progressUpdater)
3738
} catch (exception: InterruptedException) {
3839
/* The task was cancelled */
40+
wasSuccess = false
3941
logger.warn("{}", exception)
4042
}
41-
callClosure.after()
43+
callClosure.after(wasSuccess)
4244
}
4345

4446
companion object SetupIteratorTaskFactory {

src/main/kotlin/de/nihas101/image_to_pdf_converter/ui/command_line_io/PdfBuilderCommandLineInterface.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ class PdfBuilderCommandLineInterface private constructor(
137137
if (progress == 1.toDouble()) pdfBuilderCommandLineOutput.printFinishedBuilding()
138138
else pdfBuilderCommandLineOutput.printProgress()
139139
}
140+
141+
override fun reportError(message: String) {
142+
/* DO NOTHING */
143+
}
140144
}
141145
}
142146

src/main/kotlin/de/nihas101/image_to_pdf_converter/ui/command_line_io/PdfBuilderCommandLineOutput.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ class PdfBuilderCommandLineOutput private constructor(private val printStream: P
4141

4242
fun printPdfModificationInstructions(pdfBuildInformation: PdfBuildInformation) {
4343
printStream.println("Instructions:")
44-
IteratorAction.getInstructions().forEach({ instruction -> printStream.println(instruction) })
44+
IteratorAction.getInstructions().forEach { instruction -> printStream.println(instruction) }
4545
printStream.println()
4646
printPdfContent(pdfBuildInformation)
4747
printMessage("")

0 commit comments

Comments
 (0)