@@ -169,27 +169,30 @@ auto sourcemeta::jsonschema::validate(const sourcemeta::core::Options &options)
169169 read_configuration (options, configuration_path, schema_config_base)};
170170 const auto dialect{default_dialect (options, configuration)};
171171
172- sourcemeta::core:: JSON schema{
173- schema_from_stdin ? read_from_stdin ().document
174- : sourcemeta::core::read_yaml_or_json (schema_path)} ;
172+ auto schema = schema_from_stdin
173+ ? read_from_stdin ().document
174+ : sourcemeta::core::read_yaml_or_json (schema_path);
175175
176176 if (options.contains (" path" ) && !options.at (" path" ).empty ()) {
177- // Invalid pointer syntax is handled by to_pointer(), consistent with
178- // --entrypoint behavior.
179- const auto path_string{std::string{options.at (" path" ).front ()}};
180- const auto pointer{sourcemeta::core::to_pointer (path_string)};
181- const auto *const result{sourcemeta::core::try_get (schema, pointer)};
182- // We intentionally reuse NotSchemaError here to align with existing CLI
183- // error semantics without introducing a new error type.
177+ sourcemeta::core::Pointer pointer;
178+ try {
179+ pointer = sourcemeta::core::to_pointer (
180+ std::string{options.at (" path" ).front ()});
181+ } catch (const sourcemeta::core::PointerParseError &) {
182+ throw PositionalArgumentError{
183+ " The JSON Pointer is not valid" ,
184+ " jsonschema validate path/to/schema.json path/to/instance.json "
185+ " --path '/components/schemas/User'" };
186+ }
187+
188+ const auto *const result = sourcemeta::core::try_get (schema, pointer);
184189 if (!result) {
185- throw NotSchemaError{schema_resolution_base};
190+ throw PathResolutionError{schema_resolution_base,
191+ sourcemeta::core::to_string (pointer)};
186192 }
187- // Note: extracting a sub-schema may break $ref references outside the
188- // selected subtree. This is expected behavior for --path given the current
189- // CLI design.
193+
190194 // `result` points into `schema`, so we must copy before reassigning to
191- // avoid a use-after-free (the copy assignment destroys schema's storage
192- // before reading from other when they alias).
195+ // avoid a use-after-free.
193196 sourcemeta::core::JSON subschema{*result};
194197 schema = std::move (subschema);
195198 }
0 commit comments