From ace046624d2e23fba67564a86af7f03ed8a48eae Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Thu, 29 Feb 2024 21:05:10 -0500 Subject: remove unwraps, fix utf8 --- matrix-lang/src/value/exception.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'matrix-lang/src/value/exception.rs') diff --git a/matrix-lang/src/value/exception.rs b/matrix-lang/src/value/exception.rs index 0df6f5c..c4ae606 100644 --- a/matrix-lang/src/value/exception.rs +++ b/matrix-lang/src/value/exception.rs @@ -1,4 +1,4 @@ -use std::{fmt::{Debug, Display}, error::Error}; +use std::{fmt::{Debug, Display}, error::Error, io}; use crate::prelude::*; #[macro_export] @@ -76,3 +76,24 @@ impl From for Result { Err(value) } } + +impl From for Exception { + fn from(value: io::Error) -> Self { + exception!(IO_EXCEPTION, "{value}") + } +} + +pub trait Except { + type Output; + fn exception(self) -> Result; +} + +impl Except for std::result::Result { + type Output = T; + + fn exception(self) -> Result { + self.map_err(|e| { + Exception::msg("unknown", format!("{e}").as_str()) + }) + } +} -- cgit v1.2.3-freya