@@ -265,27 +265,30 @@ auto sourcemeta::jsonschema::validate(const sourcemeta::core::Options &options)
265265 read_configuration (options, configuration_path, schema_config_base)};
266266 const auto dialect{default_dialect (options, configuration)};
267267
268- sourcemeta::core::JSON schema{
269- schema_from_stdin ? read_from_stdin ().document
270- : sourcemeta::core::read_yaml_or_json (schema_path)} ;
268+ auto schema = schema_from_stdin
269+ ? read_from_stdin ().document
270+ : sourcemeta::core::read_yaml_or_json (schema_path);
271271
272272 if (options.contains (" path" ) && !options.at (" path" ).empty ()) {
273- // Invalid pointer syntax is handled by to_pointer(), consistent with
274- // --entrypoint behavior.
275- const auto path_string{std::string{options.at (" path" ).front ()}};
276- const auto pointer{sourcemeta::core::to_pointer (path_string)};
277- const auto *const result{sourcemeta::core::try_get (schema, pointer)};
278- // We intentionally reuse NotSchemaError here to align with existing CLI
279- // error semantics without introducing a new error type.
273+ sourcemeta::core::Pointer pointer;
274+ try {
275+ pointer =
276+ sourcemeta::core::to_pointer (std::string{options.at (" path" ).front ()});
277+ } catch (const sourcemeta::core::PointerParseError &) {
278+ throw PositionalArgumentError{
279+ " The JSON Pointer is not valid" ,
280+ " jsonschema validate path/to/schema.json path/to/instance.json "
281+ " --path '/components/schemas/User'" };
282+ }
283+
284+ const auto *const result = sourcemeta::core::try_get (schema, pointer);
280285 if (!result) {
281- throw NotSchemaError{schema_resolution_base};
286+ throw PathResolutionError{schema_resolution_base,
287+ sourcemeta::core::to_string (pointer)};
282288 }
283- // Note: extracting a sub-schema may break $ref references outside the
284- // selected subtree. This is expected behavior for --path given the current
285- // CLI design.
289+
286290 // `result` points into `schema`, so we must copy before reassigning to
287- // avoid a use-after-free (the copy assignment destroys schema's storage
288- // before reading from other when they alias).
291+ // avoid a use-after-free.
289292 sourcemeta::core::JSON subschema{*result};
290293 schema = std::move (subschema);
291294 }
0 commit comments