stak_device/primitive_set/
error.rs1use core::{
2 error,
3 fmt::{self, Display, Formatter},
4};
5use stak_vm::Exception;
6
7#[derive(Clone, Debug, Eq, PartialEq)]
9pub enum PrimitiveError {
10 ReadInput,
12 Vm(stak_vm::Error),
14 WriteError,
16 WriteOutput,
18}
19
20impl Exception for PrimitiveError {
21 fn is_critical(&self) -> bool {
22 match self {
23 Self::ReadInput | Self::WriteError | Self::WriteOutput => false,
24 Self::Vm(error) => error.is_critical(),
25 }
26 }
27}
28
29impl error::Error for PrimitiveError {}
30
31impl Display for PrimitiveError {
32 fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
33 match self {
34 Self::ReadInput => write!(formatter, "failed to read input"),
35 Self::Vm(error) => write!(formatter, "{error}"),
36 Self::WriteError => write!(formatter, "failed to write error"),
37 Self::WriteOutput => write!(formatter, "failed to write output"),
38 }
39 }
40}
41
42impl From<stak_vm::Error> for PrimitiveError {
43 fn from(error: stak_vm::Error) -> Self {
44 Self::Vm(error)
45 }
46}