From 87abe282dd4ebd6b94d0e3e62c40ede5bc8b8d1f Mon Sep 17 00:00:00 2001 From: Gary O'Neall Date: Sun, 9 Apr 2023 12:28:29 -0700 Subject: [PATCH] Catch JSON exceptions in verify Improves error messages. Previously, a JSON parsing error would be reported as a file I/O error. Signed-off-by: Gary O'Neall --- src/main/java/org/spdx/tools/Verify.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/spdx/tools/Verify.java b/src/main/java/org/spdx/tools/Verify.java index 24ea84d..378f79f 100644 --- a/src/main/java/org/spdx/tools/Verify.java +++ b/src/main/java/org/spdx/tools/Verify.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Objects; +import com.fasterxml.jackson.core.JsonParseException; import org.spdx.library.InvalidSPDXAnalysisException; import org.spdx.library.Version; import org.spdx.library.model.SpdxDocument; @@ -126,6 +127,8 @@ public static List verify(String filePath, SerFileType fileType) throws doc = SpdxToolsHelper.readDocumentFromFile(store, file); } catch (FileNotFoundException e) { throw new SpdxVerificationException("File "+filePath+ " not found.",e); + } catch (JsonParseException e) { + throw new SpdxVerificationException("Invalid JSON file: "+e.getMessage(), e); } catch (IOException e) { throw new SpdxVerificationException("IO Error reading SPDX file",e); } catch (InvalidSPDXAnalysisException e) {