Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: rustler update to v0.35.0 #221

Merged
merged 5 commits into from
Oct 20, 2024
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
8 changes: 4 additions & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ jobs:
fail-fast: false
matrix:
include:
- otp: 26
elixir: 1.15.4
- otp: 27
elixir: 1.17.3
lint: true
- otp: 25
elixir: 1.14.3
- otp: 26
elixir: 1.16.3

env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
Expand Down
107 changes: 57 additions & 50 deletions native/rhai_rustler/Cargo.lock

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

2 changes: 1 addition & 1 deletion native/rhai_rustler/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn engine_register_custom_operator(

match engine.register_custom_operator(keyword, precedence) {
Ok(_) => Ok(()),
Err(message) => Err(RhaiRustlerError::CustomOperatorError { message }),
Err(message) => Err(RhaiRustlerError::CustomOperator { message }),
}
}

Expand Down
30 changes: 22 additions & 8 deletions native/rhai_rustler/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::panic::RefUnwindSafe;

use thiserror::Error;

use rhai::{EvalAltResult, ParseError};
Expand Down Expand Up @@ -49,22 +51,34 @@ pub enum ScopeError {
ErrorCannotUpdateValueOfConstant,
}

#[derive(Error, Debug)]
#[error(transparent)]
pub struct EvaluationError(pub Box<EvalAltResult>);

impl RefUnwindSafe for EvaluationError {}

impl From<Box<EvalAltResult>> for RhaiRustlerError {
fn from(err: Box<EvalAltResult>) -> Self {
RhaiRustlerError::Evaluation(EvaluationError(err))
}
}

#[derive(Error, Debug)]
pub enum RhaiRustlerError {
#[error("Error in evaluation: {0}.")]
EvalAltResult(#[from] Box<EvalAltResult>),
Evaluation(#[from] EvaluationError),
#[error("Error when parsing a script: {0}.")]
ParseError(#[from] ParseError),
Parse(#[from] ParseError),
#[error("Error when accessing a scope: {0}.")]
ScopeError(#[from] ScopeError),
Scope(#[from] ScopeError),
#[error("Error when defining a custom operator: {message}.")]
CustomOperatorError { message: String },
CustomOperator { message: String },
}

impl Encoder for RhaiRustlerError {
fn encode<'a>(&self, env: Env<'a>) -> Term<'a> {
match self {
RhaiRustlerError::EvalAltResult(err) => {
RhaiRustlerError::Evaluation(EvaluationError(err)) => {
let error_atom = match err.unwrap_inner() {
EvalAltResult::ErrorSystem(_, _) => atoms::system(),
EvalAltResult::ErrorParsing(_, _) => atoms::parsing(),
Expand Down Expand Up @@ -108,10 +122,10 @@ impl Encoder for RhaiRustlerError {

make_reason_tuple(env, error_atom, err.to_string())
}
RhaiRustlerError::ParseError(err) => {
RhaiRustlerError::Parse(err) => {
make_reason_tuple(env, atoms::parsing(), err.to_string())
}
RhaiRustlerError::ScopeError(err) => {
RhaiRustlerError::Scope(err) => {
let error_atom = match err {
ScopeError::ErrorScopeIsEmpty => atoms::scope_is_empty(),
ScopeError::ErrorCannotUpdateValueOfConstant => {
Expand All @@ -121,7 +135,7 @@ impl Encoder for RhaiRustlerError {

make_reason_tuple(env, error_atom, err.to_string())
}
RhaiRustlerError::CustomOperatorError { message } => {
RhaiRustlerError::CustomOperator { message } => {
make_reason_tuple(env, atoms::custom_operator(), message.to_owned())
}
}
Expand Down
Loading
Loading