From 9cdb5e17a440bd7b88c6b36c64c29f8460af2176 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Thu, 11 Jan 2024 19:50:16 +0200 Subject: [PATCH] fix(tvix/eval): fix JSON error types The error message is misleading. The errors we return can happen both during serialization or deserialization, though the messages suggested the latter only. Change-Id: I2dafe17ec78ee75cab5937a3a81540fda3175eac Reviewed-on: https://cl.tvl.fyi/c/depot/+/10603 Autosubmit: flokli Reviewed-by: tazjin Tested-by: BuildkiteCI --- tvix/eval/src/errors.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index 4ba93a0aa..1bd2e47e9 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -163,8 +163,8 @@ pub enum ErrorKind { error: Rc, }, - /// Errors converting JSON to a value - FromJsonError(String), + /// Errors parsing JSON, or serializing as JSON. + JsonError(String), /// Nix value that can not be serialised to JSON. NotSerialisableToJson(&'static str), @@ -263,7 +263,7 @@ impl From for ErrorKind { impl From for ErrorKind { fn from(err: serde_json::Error) -> Self { // Can't just put the `serde_json::Error` in the ErrorKind since it doesn't impl `Clone` - Self::FromJsonError(format!("error in JSON serialization: {err}")) + Self::JsonError(err.to_string()) } } @@ -444,8 +444,8 @@ to a missing value in the attribute set(s) included via `with`."#, write!(f, "{error}") } - ErrorKind::FromJsonError(msg) => { - write!(f, "Error converting JSON to a Nix value: {msg}") + ErrorKind::JsonError(msg) => { + write!(f, "Error converting JSON to a Nix value or back: {msg}") } ErrorKind::NotSerialisableToJson(_type) => { @@ -771,7 +771,7 @@ impl Error { | ErrorKind::ImportParseError { .. } | ErrorKind::ImportCompilerError { .. } | ErrorKind::IO { .. } - | ErrorKind::FromJsonError(_) + | ErrorKind::JsonError(_) | ErrorKind::NotSerialisableToJson(_) | ErrorKind::FromTomlError(_) | ErrorKind::Xml(_) @@ -811,7 +811,7 @@ impl Error { ErrorKind::ImportParseError { .. } => "E027", ErrorKind::ImportCompilerError { .. } => "E028", ErrorKind::IO { .. } => "E029", - ErrorKind::FromJsonError { .. } => "E030", + ErrorKind::JsonError { .. } => "E030", ErrorKind::UnexpectedArgument { .. } => "E031", ErrorKind::RelativePathResolution(_) => "E032", ErrorKind::DivisionByZero => "E033",