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

Better implement human friendly validate error messages #11

Merged
merged 1 commit into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEPENDENCIES
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
vendorpull https://github.com/sourcemeta/vendorpull dea311b5bfb53b6926a4140267959ae334d3ecf4
noa https://github.com/sourcemeta/noa 5ff4024902642afc9cc2f9a9e02ae9dff9d15d4f
jsontoolkit https://github.com/sourcemeta/jsontoolkit dc7e1e21853f2b26cac572d5dc4c3dc50eeda935
jsontoolkit https://github.com/sourcemeta/jsontoolkit 2775ccc05af7be64dd2532694bb17274185aeec1
13 changes: 8 additions & 5 deletions src/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,23 @@ auto parse_options(const std::span<const std::string> &arguments,

auto pretty_evaluate_callback(
bool result,
const sourcemeta::jsontoolkit::SchemaCompilerTemplate::value_type &,
const sourcemeta::jsontoolkit::SchemaCompilerTemplate::value_type &step,
const sourcemeta::jsontoolkit::Pointer &evaluate_path,
const sourcemeta::jsontoolkit::Pointer &instance_location,
const sourcemeta::jsontoolkit::JSON &,
const sourcemeta::jsontoolkit::JSON &) -> void {
if (result) {
return;
}

// TODO: Improve this pretty terrible output
std::cerr << " \"";
std::cerr << "error: " << sourcemeta::jsontoolkit::describe(step) << "\n";
std::cerr << " at instance location \"";
sourcemeta::jsontoolkit::stringify(instance_location, std::cerr);
std::cerr << "\" at evaluate path (\"";
std::cerr << "\"\n";

std::cerr << " at evaluate path \"";
sourcemeta::jsontoolkit::stringify(evaluate_path, std::cerr);
std::cerr << "\")\n";
std::cerr << "\"\n";
}

auto resolver(const std::map<std::string, std::vector<std::string>> &options)
Expand Down
2 changes: 2 additions & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define INTELLIGENCE_JSONSCHEMA_CLI_UTILS_H_

#include <sourcemeta/jsontoolkit/json.h>
#include <sourcemeta/jsontoolkit/jsonpointer.h>
#include <sourcemeta/jsontoolkit/jsonschema.h>

#include <filesystem> // std::filesystem
Expand Down Expand Up @@ -37,6 +38,7 @@ auto pretty_evaluate_callback(
const sourcemeta::jsontoolkit::SchemaCompilerTemplate::value_type &,
const sourcemeta::jsontoolkit::Pointer &evaluate_path,
const sourcemeta::jsontoolkit::Pointer &instance_location,
const sourcemeta::jsontoolkit::JSON &,
const sourcemeta::jsontoolkit::JSON &) -> void;

auto resolver(const std::map<std::string, std::vector<std::string>> &options)
Expand Down
1 change: 1 addition & 0 deletions test/validate_fail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ trap clean EXIT
cat << 'EOF' > "$TMP/schema.json"
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"foo": {
"type": "string"
Expand Down
1 change: 1 addition & 0 deletions vendor/jsontoolkit/Makefile.uk

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/jsontoolkit/src/jsonschema/CMakeLists.txt

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

111 changes: 111 additions & 0 deletions vendor/jsontoolkit/src/jsonschema/compile_describe.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions vendor/jsontoolkit/src/jsonschema/compile_evaluate.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions vendor/jsontoolkit/src/jsonschema/compile_json.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading