Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improcess error hanling in getJsonSchema - never squash exceptions #372

Open
Johnlon opened this issue Apr 26, 2021 · 0 comments
Open

Improcess error hanling in getJsonSchema - never squash exceptions #372

Johnlon opened this issue Apr 26, 2021 · 0 comments

Comments

@Johnlon
Copy link

Johnlon commented Apr 26, 2021

The "Cannot happen" happens often enough in actual use when the user passes in a bad value for the definition pointer.
For example one without a leading "/".

The code should deal with use input more conveniently by making some up front sanit checks perhaps, or at the very least don't just squash the JSONPointerException that comes from Jackson code as exception squashing is pure evil (if you don't mind me sayting so).

I'm trying to use this in a validator where folk provide a configurator and this kind of error handling means I have to check things up front where this library or it's transitive shoujld be doing it elegantly (nice error messages) instead.

public JsonSchema getJsonSchema(final JsonNode schema, final String ptr)
        throws ProcessingException
    {
        BUNDLE.checkNotNull(schema, "nullSchema");
        CORE_BUNDLE.checkNotNull(ptr, "nullPointer");
        final JsonPointer pointer;
        try {
            pointer = new JsonPointer(ptr);
            return validator.buildJsonSchema(schema, pointer);
        } catch (JsonPointerException ignored) {
            // Cannot happen
        }
        throw new IllegalStateException("How did I get there??");
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant