Skip to content

Commit 7482e6d

Browse files
Removed error handling
1 parent 772c422 commit 7482e6d

14 files changed

+18
-183
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Changed
1111
- Filtering: moved to options
1212

13+
### Removed
14+
- Error handling: exceptions are now thrown instead of being handled by the renderer
15+
1316

1417
## [0.0.3] - 2025-09-21
1518

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ base/
7474
└─ landscape.jpeg
7575
```
7676

77+
> [!NOTE]
78+
> In case of error while reading directories or files, an [UncheckedIOException](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/io/UncheckedIOException.html) is thrown.
79+
7780
# Options
7881

7982
* [Tree format](#tree-format)

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/FileTreePrettyPrinter.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.github.computerdaddyguy.jfiletreeprettyprinter;
22

3+
import java.io.UncheckedIOException;
34
import java.nio.file.Path;
45
import org.jspecify.annotations.NullMarked;
56

@@ -17,15 +18,19 @@ public interface FileTreePrettyPrinter {
1718
*
1819
* @param path A directory or a file.
1920
* @param filter Filter for paths to retain, <code>null</code> will retain all files. Applies only on children paths, not root path.
21+
*
22+
* @throws UncheckedIOException If any IO error occurred
2023
*/
21-
String prettyPrint(Path path);
24+
String prettyPrint(Path path) throws UncheckedIOException;
2225

2326
/**
2427
* Pretty prints the given path.
2528
*
2629
* @param path A directory or a file.
30+
*
31+
* @throws UncheckedIOException If any IO error occurred
2732
*/
28-
default String prettyPrint(String path) {
33+
default String prettyPrint(String path) throws UncheckedIOException {
2934
return prettyPrint(Path.of(path));
3035
}
3136

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/renderer/DefaultLineRenderer.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.depth.DepthFormatter;
55
import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.file.FileFormatter;
66
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryEntry;
7-
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryExceptionTreeEntry;
87
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileEntry;
9-
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileReadingAttributesExceptionEntry;
108
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.MaxDepthReachEntry;
119
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.SkippedChildrenEntry;
1210
import java.nio.file.Path;
@@ -31,21 +29,11 @@ public String renderDirectoryBegin(Depth depth, DirectoryEntry dirEntry, List<Pa
3129
return treeFormatter.format(depth) + fileFormatter.formatDirectoryBegin(dirEntry, dirs);
3230
}
3331

34-
@Override
35-
public String renderDirectoryException(Depth depth, DirectoryExceptionTreeEntry dirExceptionEntry) {
36-
return treeFormatter.format(depth) + fileFormatter.formatDirectoryException(dirExceptionEntry);
37-
}
38-
3932
@Override
4033
public String renderFile(Depth depth, FileEntry fileEntry) {
4134
return treeFormatter.format(depth) + fileFormatter.formatFile(fileEntry);
4235
}
4336

44-
@Override
45-
public String renderFileException(Depth depth, FileReadingAttributesExceptionEntry fileReadingAttrsExceptionEntry) {
46-
return treeFormatter.format(depth) + fileFormatter.formatFileException(fileReadingAttrsExceptionEntry);
47-
}
48-
4937
@Override
5038
public @Nullable String renderChildLimitReached(Depth depth, SkippedChildrenEntry skippedChildrenEntry) {
5139
return treeFormatter.format(depth) + fileFormatter.formatChildLimitReached(skippedChildrenEntry);

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/renderer/DefaultTreeEntryRenderer.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.depth.DepthSymbol;
55
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry;
66
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryEntry;
7-
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryExceptionTreeEntry;
87
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileEntry;
9-
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileReadingAttributesExceptionEntry;
108
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.MaxDepthReachEntry;
119
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.SkippedChildrenEntry;
1210
import java.nio.file.Path;
@@ -40,8 +38,6 @@ public void renderTree(TreeEntry entry, Depth depth, StringBuilder buff) {
4038
case TreeEntry.FileEntry fileEntry -> renderFile(buff, depth, fileEntry);
4139
case TreeEntry.SkippedChildrenEntry skippedChildrenEntry -> renderSkippedChildrenEntry(buff, depth, skippedChildrenEntry);
4240
case TreeEntry.MaxDepthReachEntry maxDepthReachEntry -> renderMaxDepthReachEntry(buff, depth, maxDepthReachEntry);
43-
case TreeEntry.DirectoryExceptionTreeEntry dirExceptionEntry -> renderDirExceptionEntry(buff, depth, dirExceptionEntry);
44-
case TreeEntry.FileReadingAttributesExceptionEntry fileReadingAttrsException -> renderFileReadingAttributesExceptionEntry(buff, depth, fileReadingAttrsException);
4541
}
4642
}
4743

@@ -86,12 +82,4 @@ private void renderMaxDepthReachEntry(StringBuilder buff, Depth depth, MaxDepthR
8682
buff.append(lineRenderer.renderMaxDepthReached(depth, maxDepthReachEntry));
8783
}
8884

89-
private void renderDirExceptionEntry(StringBuilder buff, Depth depth, DirectoryExceptionTreeEntry dirExceptionEntry) {
90-
buff.append(lineRenderer.renderDirectoryException(depth, dirExceptionEntry));
91-
}
92-
93-
private void renderFileReadingAttributesExceptionEntry(StringBuilder buff, Depth depth, FileReadingAttributesExceptionEntry fileReadingAttrsException) {
94-
buff.append(lineRenderer.renderFileException(depth, fileReadingAttrsException));
95-
}
96-
9785
}

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/renderer/LineRenderer.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@
44
import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.depth.DepthFormatter;
55
import io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.file.FileFormatter;
66
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryEntry;
7-
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryExceptionTreeEntry;
87
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileEntry;
9-
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileReadingAttributesExceptionEntry;
108
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.MaxDepthReachEntry;
119
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.SkippedChildrenEntry;
1210
import java.nio.file.Path;
@@ -20,15 +18,9 @@ interface LineRenderer {
2018
@Nullable
2119
String renderDirectoryBegin(Depth depth, DirectoryEntry dirEntry, List<Path> dirs);
2220

23-
@Nullable
24-
String renderDirectoryException(Depth depth, DirectoryExceptionTreeEntry dirExceptionEntry);
25-
2621
@Nullable
2722
String renderFile(Depth depth, FileEntry fileEntry);
2823

29-
@Nullable
30-
String renderFileException(Depth depth, FileReadingAttributesExceptionEntry fileReadingAttrsExceptionEntry);
31-
3224
@Nullable
3325
String renderChildLimitReached(Depth depth, SkippedChildrenEntry skippedChildrenEntry);
3426

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/renderer/file/DefaultEmojiMapping.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.file;
22

3-
import java.io.IOException;
43
import java.nio.file.Path;
54
import java.util.Map;
65
import java.util.Objects;
@@ -14,17 +13,15 @@ class DefaultEmojiMapping implements EmojiMapping {
1413
private final String defaultFileEmoji;
1514
private final Map<String, String> exactFileNamesEmojis;
1615
private final Map<String, String> fileExtensionsEmojis;
17-
private final String errorEmoji;
1816

1917
public DefaultEmojiMapping(
20-
String directoryEmoji, String defaultFileEmoji, Map<String, String> exactFileNamesEmojis, Map<String, String> fileExtensionsEmojis, String errorEmoji
18+
String directoryEmoji, String defaultFileEmoji, Map<String, String> exactFileNamesEmojis, Map<String, String> fileExtensionsEmojis
2119
) {
2220
super();
2321
this.directoryEmoji = Objects.requireNonNull(directoryEmoji, "directoryEmoji is null");
2422
this.defaultFileEmoji = Objects.requireNonNull(defaultFileEmoji, "defaultFileEmoji is null");
2523
this.exactFileNamesEmojis = Objects.requireNonNull(exactFileNamesEmojis, "exactFileNamesEmojis is null");
2624
this.fileExtensionsEmojis = Objects.requireNonNull(fileExtensionsEmojis, "fileExtensionsEmojis is null");
27-
this.errorEmoji = Objects.requireNonNull(errorEmoji, "errorEmoji is null");
2825
}
2926

3027
@Override
@@ -49,11 +46,6 @@ private final String extractExtension(String fileName) {
4946
return dotIndex < 0 ? null : fileName.substring(dotIndex + 1);
5047
}
5148

52-
@Override
53-
public @Nullable String getErrorEmoji(Path file, IOException exc) {
54-
return errorEmoji;
55-
}
56-
5749
public static DefaultEmojiMappingBuilder builder() {
5850
return new DefaultEmojiMappingBuilder();
5951
}

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/renderer/file/DefaultEmojiMappingBuilder.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@
88
class DefaultEmojiMappingBuilder {
99

1010
private String directoryEmoji = "📂";
11-
private String errorEmoji = "❌";
1211
private String defaultFileEmoji = "📄";
1312
private Map<String, String> exactFileNamesEmojis = buildDefaultExactFileNamesEmojis();
1413
private Map<String, String> fileExtensionsEmojis = buildDefaultFileExtensionsEmojis();
1514

1615
EmojiMapping build() {
17-
return new DefaultEmojiMapping(directoryEmoji, defaultFileEmoji, exactFileNamesEmojis, fileExtensionsEmojis, errorEmoji);
16+
return new DefaultEmojiMapping(directoryEmoji, defaultFileEmoji, exactFileNamesEmojis, fileExtensionsEmojis);
1817
}
1918

2019
private Map<String, String> buildDefaultExactFileNamesEmojis() {

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/renderer/file/DefaultFileFormatter.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.file;
22

33
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryEntry;
4-
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryExceptionTreeEntry;
54
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileEntry;
6-
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileReadingAttributesExceptionEntry;
75
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.MaxDepthReachEntry;
86
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.SkippedChildrenEntry;
97
import java.nio.file.Path;
@@ -22,12 +20,6 @@ public String formatDirectoryBegin(DirectoryEntry dirEntry, List<Path> dirs) {
2220
.collect(Collectors.joining());
2321
}
2422

25-
@Override
26-
public String formatDirectoryException(DirectoryExceptionTreeEntry dirExceptionEntry) {
27-
return dirExceptionEntry.getDir().getFileName().toString() + "/: "
28-
+ dirExceptionEntry.getException().getMessage();
29-
}
30-
3123
@Override
3224
public String formatFile(FileEntry fileEntry) {
3325
var fileNameFormatted = fileEntry.getFile().getFileName().toString();
@@ -39,11 +31,6 @@ public String formatFile(FileEntry fileEntry) {
3931
return fileNameFormatted;
4032
}
4133

42-
@Override
43-
public String formatFileException(FileReadingAttributesExceptionEntry fileReadingAttrsException) {
44-
return fileReadingAttrsException.getFile().getFileName().toString() + ": " + fileReadingAttrsException.getException().getMessage();
45-
}
46-
4734
@Override
4835
public String formatChildLimitReached(SkippedChildrenEntry skippedChildrenEntry) {
4936
return "... (" + childrenAsString(skippedChildrenEntry.getSkippedChildren()) + " skipped)";

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/renderer/file/EmojiFileFormatter.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package io.github.computerdaddyguy.jfiletreeprettyprinter.renderer.file;
22

33
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryEntry;
4-
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.DirectoryExceptionTreeEntry;
54
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileEntry;
6-
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.FileReadingAttributesExceptionEntry;
75
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.MaxDepthReachEntry;
86
import io.github.computerdaddyguy.jfiletreeprettyprinter.scanner.TreeEntry.SkippedChildrenEntry;
9-
import java.io.IOException;
107
import java.nio.file.Path;
118
import java.util.List;
129
import java.util.Objects;
@@ -28,11 +25,6 @@ private String getFileEmojiPrefix(Path p) {
2825
return getEmojiPrefix(emoji);
2926
}
3027

31-
private String getErrorEmojiPrefix(Path file, IOException exc) {
32-
var emoji = emojiMapping.getErrorEmoji(file, exc);
33-
return getEmojiPrefix(emoji);
34-
}
35-
3628
private String getEmojiPrefix(String emoji) {
3729
if (emoji == null) {
3830
return "";
@@ -45,23 +37,11 @@ public String formatDirectoryBegin(DirectoryEntry dirEntry, List<Path> dirs) {
4537
return getFileEmojiPrefix(dirEntry.getDir()) + decorated.formatDirectoryBegin(dirEntry, dirs);
4638
}
4739

48-
@Override
49-
public String formatDirectoryException(DirectoryExceptionTreeEntry dirExceptionEntry) {
50-
return getErrorEmojiPrefix(dirExceptionEntry.getDir(), dirExceptionEntry.getException())
51-
+ decorated.formatDirectoryException(dirExceptionEntry);
52-
}
53-
5440
@Override
5541
public String formatFile(FileEntry fileEntry) {
5642
return getFileEmojiPrefix(fileEntry.getFile()) + decorated.formatFile(fileEntry);
5743
}
5844

59-
@Override
60-
public String formatFileException(FileReadingAttributesExceptionEntry fileReadingAttrsException) {
61-
return getErrorEmojiPrefix(fileReadingAttrsException.getFile(), fileReadingAttrsException.getException())
62-
+ decorated.formatFileException(fileReadingAttrsException);
63-
}
64-
6545
@Override
6646
public String formatChildLimitReached(SkippedChildrenEntry skippedChildrenEntry) {
6747
return decorated.formatChildLimitReached(skippedChildrenEntry);

0 commit comments

Comments
 (0)