Skip to main content

runmat_runtime/
runtime_error.rs

1pub use runmat_async::{
2    runtime_error as build_runtime_error, CallFrame, ErrorContext, RuntimeError,
3    RuntimeErrorBuilder,
4};
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub enum ReplayErrorKind {
8    UnsupportedSchema,
9    PayloadTooLarge,
10    DecodeFailed,
11    ExportRejected,
12    ImportRejected,
13}
14
15impl ReplayErrorKind {
16    pub fn identifier(self) -> &'static str {
17        match self {
18            Self::UnsupportedSchema => "RunMat:ReplayUnsupportedSchema",
19            Self::PayloadTooLarge => "RunMat:ReplayPayloadTooLarge",
20            Self::DecodeFailed => "RunMat:ReplayDecodeFailed",
21            Self::ExportRejected => "RunMat:ReplayExportRejected",
22            Self::ImportRejected => "RunMat:ReplayImportRejected",
23        }
24    }
25}
26
27pub fn replay_error(kind: ReplayErrorKind, message: impl Into<String>) -> RuntimeError {
28    build_runtime_error(message)
29        .with_builtin("replay")
30        .with_identifier(kind.identifier())
31        .build()
32}
33
34pub fn replay_error_with_source(
35    kind: ReplayErrorKind,
36    message: impl Into<String>,
37    source: impl std::error::Error + Send + Sync + 'static,
38) -> RuntimeError {
39    build_runtime_error(message)
40        .with_builtin("replay")
41        .with_identifier(kind.identifier())
42        .with_source(source)
43        .build()
44}