diff --git a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java index 2c9bc4769c5..b4317e4d322 100644 --- a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java +++ b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFieldLayout.java @@ -202,6 +202,9 @@ public static AprilTagFieldLayout loadFromResource(String resourcePath) throws I try (InputStream stream = AprilTagFieldLayout.class.getResourceAsStream(resourcePath); InputStreamReader reader = new InputStreamReader(stream)) { return new ObjectMapper().readerFor(AprilTagFieldLayout.class).readValue(reader); + } catch (NullPointerException e) { + // Class.getResourceAsStream() returns null if the resource does not exist. + throw new IOException("Could not locate resource: " + resourcePath + "\n"); } } diff --git a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFields.java b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFields.java index be9caecb9ee..89d256e1a4a 100644 --- a/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFields.java +++ b/apriltag/src/main/java/edu/wpi/first/apriltag/AprilTagFields.java @@ -5,6 +5,7 @@ package edu.wpi.first.apriltag; import java.io.IOException; +import java.io.UncheckedIOException; public enum AprilTagFields { k2022RapidReact("2022-rapidreact.json"), @@ -25,9 +26,13 @@ public enum AprilTagFields { * Get a {@link AprilTagFieldLayout} from the resource JSON. * * @return AprilTagFieldLayout of the field - * @throws IOException If the layout does not exist + * @throws UncheckedIOException If the layout does not exist */ - public AprilTagFieldLayout loadAprilTagLayoutField() throws IOException { - return AprilTagFieldLayout.loadFromResource(m_resourceFile); + public AprilTagFieldLayout loadAprilTagLayoutField() { + try { + return AprilTagFieldLayout.loadFromResource(m_resourceFile); + } catch (IOException e) { + throw new UncheckedIOException("Could not load AprilTagFieldLayout from " + m_resourceFile, e); + } } }