diff --git a/src/command_decode.cc b/src/command_decode.cc index ef362a6f..15fda25b 100644 --- a/src/command_decode.cc +++ b/src/command_decode.cc @@ -5,7 +5,6 @@ #include #include -#include // assert #include // std::filesystem #include // std::ifstream @@ -55,11 +54,7 @@ auto sourcemeta::jsonschema::decode(const sourcemeta::core::Options &options) custom_resolver); const auto encoding{sourcemeta::jsonbinpack::load(schema)}; - std::ifstream input_stream{ - sourcemeta::core::weakly_canonical(options.positional().front()), - std::ios::binary}; - assert(!input_stream.fail()); - assert(input_stream.is_open()); + auto input_stream{sourcemeta::core::read_file(options.positional().front())}; const std::filesystem::path output{options.positional().at(1)}; std::ofstream output_stream(sourcemeta::core::weakly_canonical(output), diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index c1605c60..79a40914 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1196,6 +1196,7 @@ add_jsonschema_test(decode/pass_schema_less) add_jsonschema_test(decode/pass_schema_less_jsonl) add_jsonschema_test(decode/pass_schema_less_jsonl_verbose) add_jsonschema_test(decode/fail_no_document) +add_jsonschema_test(decode/fail_enoent) add_jsonschema_test(decode/fail_truncated_document) add_jsonschema_test(decode/fail_no_output) diff --git a/test/decode/fail_enoent.clitest b/test/decode/fail_enoent.clitest new file mode 100644 index 00000000..1ee04ea0 --- /dev/null +++ b/test/decode/fail_enoent.clitest @@ -0,0 +1,28 @@ +// A nonexistent input file is reported the same way every other command +// reports it, not as a bogus "truncated document" error + +// Other input error +RUN decode document.binpack decoded.json STDIN /dev/null IN . INTO result_0.txt EXPECTING 6 + +REPLACE $CWD WITH '[CWD]' IN result_0.txt + +WRITE expected_0.txt UNTIL EOF +2> error: No such file or directory +2> at file path [CWD]/document.binpack +EOF + +COMPARE result_0.txt AGAINST expected_0.txt + +// Other input error +RUN decode document.binpack decoded.json --json STDIN /dev/null IN . INTO result_1.txt EXPECTING 6 + +REPLACE $CWD WITH '[CWD]' IN result_1.txt + +WRITE expected_1.txt UNTIL EOF +1> { +1> "error": "No such file or directory", +1> "filePath": "[CWD]/document.binpack" +1> } +EOF + +COMPARE result_1.txt AGAINST expected_1.txt