From c011a6130cd4f0486539f8e98f0aef5d64e32d90 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 10 Jan 2023 02:06:57 +0300 Subject: refactor(tvix/eval): impl Display for ErrorKind This just shuffles the Display implementations around so that ErrorKind itself is displayable, which is useful in some situations where errors under construction need to be type-converted. Change-Id: I7b633d03d0dc34f345c4f20676e0023ecb1db0c4 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7802 Autosubmit: tazjin Reviewed-by: edef Tested-by: BuildkiteCI --- tvix/eval/src/errors.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'tvix/eval/src/errors.rs') diff --git a/tvix/eval/src/errors.rs b/tvix/eval/src/errors.rs index 2cef36f757..416a4b23c0 100644 --- a/tvix/eval/src/errors.rs +++ b/tvix/eval/src/errors.rs @@ -223,9 +223,9 @@ pub struct Error { pub span: Span, } -impl Display for Error { +impl Display for ErrorKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match &self.kind { + match &self { ErrorKind::Throw(msg) => write!(f, "error thrown: {}", msg), ErrorKind::Abort(msg) => write!(f, "evaluation aborted: {}", msg), ErrorKind::AssertionFailed => write!(f, "assertion failed"), @@ -409,6 +409,12 @@ to a missing value in the attribute set(s) included via `with`."#, } } +impl Display for Error { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.kind) + } +} + pub type EvalResult = Result; /// Human-readable names for rnix syntaxes. -- cgit 1.4.1