Skip to content

Commit efd4706

Browse files
author
Guy Davenport
committed
improved error message
1 parent 83d0c0d commit efd4706

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

java/buildSrc/src/main/groovy/brapi.schema-tools.java-conventions.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group = 'org.brapi'
6-
version = '0.9.0-SNAPSHOT'
6+
version = '0.10.0-SNAPSHOT'
77
sourceCompatibility = JavaVersion.VERSION_21
88
targetCompatibility = JavaVersion.VERSION_21
99

java/core/src/main/java/org/brapi/schematools/core/brapischema/BrAPISchemaReader.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.brapi.schematools.core.utils.StringUtils;
1818

1919
import java.io.IOException;
20+
import java.nio.file.NoSuchFileException;
2021
import java.nio.file.Path;
2122
import java.nio.file.attribute.BasicFileAttributes;
2223
import java.util.ArrayList;
@@ -65,10 +66,14 @@ public BrAPISchemaReader() {
6566
* @return a response containing a list of BrAPIClass with one type per JSON Schema or validation errors
6667
*/
6768
public Response<List<BrAPIClass>> readDirectories(Path schemaDirectory) {
68-
try {
69-
return dereferenceAndValidate(find(schemaDirectory, 3, this::schemaPathMatcher).map(this::createBrAPISchemas).collect(Response.mergeLists()));
70-
} catch (RuntimeException | IOException e) {
71-
return fail(Response.ErrorType.VALIDATION, schemaDirectory, e.getMessage());
69+
70+
try (Stream<Path> schemas = find(schemaDirectory, 3, this::schemaPathMatcher)) {
71+
return dereferenceAndValidate(schemas.map(this::createBrAPISchemas).collect(Response.mergeLists()));
72+
} catch (NoSuchFileException noSuchFileException) {
73+
return fail(Response.ErrorType.VALIDATION, String.format("The schema directory '%s' does not exist", schemaDirectory));
74+
}
75+
catch (RuntimeException | IOException e) {
76+
return fail(Response.ErrorType.VALIDATION, schemaDirectory, String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage()));
7277
}
7378
}
7479

0 commit comments

Comments
 (0)