mirror of
https://github.com/NixOS/nix
synced 2025-06-25 19:01:16 +02:00
Merge pull request #12127 from NaN-git/json-ser
toJSON: re-throw serialization exception
This commit is contained in:
commit
4f3960ea26
4 changed files with 17 additions and 1 deletions
|
@ -108,7 +108,11 @@ json printValueAsJSON(EvalState & state, bool strict,
|
||||||
void printValueAsJSON(EvalState & state, bool strict,
|
void printValueAsJSON(EvalState & state, bool strict,
|
||||||
Value & v, const PosIdx pos, std::ostream & str, NixStringContext & context, bool copyToStore)
|
Value & v, const PosIdx pos, std::ostream & str, NixStringContext & context, bool copyToStore)
|
||||||
{
|
{
|
||||||
|
try {
|
||||||
str << printValueAsJSON(state, strict, v, pos, context, copyToStore);
|
str << printValueAsJSON(state, strict, v, pos, context, copyToStore);
|
||||||
|
} catch (nlohmann::json::exception & e) {
|
||||||
|
throw JSONSerializationError("JSON serialization error: %s", e.what());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
json ExternalValueBase::printValueAsJSON(EvalState & state, bool strict,
|
json ExternalValueBase::printValueAsJSON(EvalState & state, bool strict,
|
||||||
|
|
|
@ -16,4 +16,7 @@ nlohmann::json printValueAsJSON(EvalState & state, bool strict,
|
||||||
void printValueAsJSON(EvalState & state, bool strict,
|
void printValueAsJSON(EvalState & state, bool strict,
|
||||||
Value & v, const PosIdx pos, std::ostream & str, NixStringContext & context, bool copyToStore = true);
|
Value & v, const PosIdx pos, std::ostream & str, NixStringContext & context, bool copyToStore = true);
|
||||||
|
|
||||||
|
|
||||||
|
MakeError(JSONSerializationError, Error);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
8
tests/functional/lang/eval-fail-toJSON-non-utf-8.err.exp
Normal file
8
tests/functional/lang/eval-fail-toJSON-non-utf-8.err.exp
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
error:
|
||||||
|
… while calling the 'toJSON' builtin
|
||||||
|
at /pwd/lang/eval-fail-toJSON-non-utf-8.nix:1:1:
|
||||||
|
1| builtins.toJSON "_invalid UTF-8: ÿ_"
|
||||||
|
| ^
|
||||||
|
2|
|
||||||
|
|
||||||
|
error: JSON serialization error: [json.exception.type_error.316] invalid UTF-8 byte at index 16: 0xFF
|
1
tests/functional/lang/eval-fail-toJSON-non-utf-8.nix
Normal file
1
tests/functional/lang/eval-fail-toJSON-non-utf-8.nix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
builtins.toJSON "_invalid UTF-8: ÿ_"
|
Loading…
Add table
Add a link
Reference in a new issue