Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions temporal_capi/bindings/c/TemporalError.d.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions temporal_capi/bindings/cpp/temporal_rs/TemporalError.d.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions temporal_capi/bindings/cpp/temporal_rs/TemporalError.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 16 additions & 1 deletion temporal_capi/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
use alloc::borrow::Cow;

#[diplomat::bridge]
#[diplomat::abi_rename = "temporal_rs_{0}"]
#[diplomat::attr(auto, namespace = "temporal_rs")]
pub mod ffi {
use diplomat_runtime::{DiplomatOption, DiplomatUtf8StrSlice};

#[diplomat::enum_convert(temporal_rs::error::ErrorKind)]
pub enum ErrorKind {
Generic,
Expand All @@ -14,28 +18,39 @@ pub mod ffi {
// In the future we might turn this into an opaque type with a msg() field
pub struct TemporalError {
pub kind: ErrorKind,
pub msg: DiplomatOption<DiplomatUtf8StrSlice<'static>>,
}

impl TemporalError {
// internal
pub(crate) fn syntax() -> Self {
TemporalError {
kind: ErrorKind::Syntax,
msg: None.into(),
}
}

pub(crate) fn range() -> Self {
TemporalError {
kind: ErrorKind::Range,
msg: None.into(),
}
}
}
}

impl From<temporal_rs::TemporalError> for ffi::TemporalError {
fn from(other: temporal_rs::TemporalError) -> Self {
let kind = other.kind().into();
let msg = other.into_message();
let msg = if let Cow::Borrowed(s) = msg {
Some(s)
} else {
None
};
Self {
kind: other.kind().into(),
kind,
msg: msg.map(Into::into).into(),
}
}
}