Skip to content

Commit

Permalink
improved error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Guy Davenport committed Nov 11, 2024
1 parent 83d0c0d commit efd4706
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group = 'org.brapi'
version = '0.9.0-SNAPSHOT'
version = '0.10.0-SNAPSHOT'
sourceCompatibility = JavaVersion.VERSION_21
targetCompatibility = JavaVersion.VERSION_21

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.brapi.schematools.core.utils.StringUtils;

import java.io.IOException;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.ArrayList;
Expand Down Expand Up @@ -65,10 +66,14 @@ public BrAPISchemaReader() {
* @return a response containing a list of BrAPIClass with one type per JSON Schema or validation errors
*/
public Response<List<BrAPIClass>> readDirectories(Path schemaDirectory) {
try {
return dereferenceAndValidate(find(schemaDirectory, 3, this::schemaPathMatcher).map(this::createBrAPISchemas).collect(Response.mergeLists()));
} catch (RuntimeException | IOException e) {
return fail(Response.ErrorType.VALIDATION, schemaDirectory, e.getMessage());

try (Stream<Path> schemas = find(schemaDirectory, 3, this::schemaPathMatcher)) {
return dereferenceAndValidate(schemas.map(this::createBrAPISchemas).collect(Response.mergeLists()));
} catch (NoSuchFileException noSuchFileException) {
return fail(Response.ErrorType.VALIDATION, String.format("The schema directory '%s' does not exist", schemaDirectory));
}
catch (RuntimeException | IOException e) {
return fail(Response.ErrorType.VALIDATION, schemaDirectory, String.format("%s: %s", e.getClass().getSimpleName(), e.getMessage()));
}
}

Expand Down

0 comments on commit efd4706

Please sign in to comment.