Skip to content

Commit 9c8fd4c

Browse files
committed
added errors for interaction with environments
1 parent b27b84c commit 9c8fd4c

4 files changed

Lines changed: 26 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,19 @@ especially the [Rust flavour](https://doc.rust-lang.org/cargo/reference/semver.h
1616

1717
### Removed
1818

19-
## [0.2.0] - 2025-??-??
19+
## [0.2.0] - 2025-08-29
2020

2121
### Added
22+
- error handling necessary for interacting with `Environment`s
2223

2324
### Changed
2425
- contribution modalities
25-
- separated error handling for trait `Environment`
26+
- moved `Environment` into own submodule
2627

2728
### Fixed
2829
- solved open todo!()'s
2930
- non static lifetime for enum registration function
3031

31-
### Removed
32-
3332
## [0.1.4] - 2025-08-11
3433

3534
### Changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The implementation follows the pattern of `clox` as described in Part III of [cr
88
## Usage
99

1010
```rust
11-
use tinyscript::{Runtime, DefaultEnvironment};
11+
use tinyscript::{Runtime, environment::DefaultEnvironment};
1212

1313
fn main() -> Result<(), Box<dyn std::error::Error>> {
1414
let mut runtime = Runtime::default();

src/environment.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,22 @@ pub enum Error {
5353
/// Name of the variable
5454
name: ConstString,
5555
},
56+
57+
/// An external error when setting the variable.
58+
EnvVarSet {
59+
/// Name of the variable
60+
name: ConstString,
61+
/// Cause of error
62+
cause: ConstString,
63+
},
64+
65+
/// An error when casting the type of the variable.
66+
EnvVarTypeCast {
67+
/// Name of the variable
68+
name: ConstString,
69+
/// Expected type ofthe variable
70+
var_type: ConstString,
71+
},
5672
}
5773

5874
impl core::error::Error for Error {
@@ -74,6 +90,8 @@ impl core::fmt::Debug for Error {
7490
Self::EnvVarNotDefined { name } => write!(f, "EnvVarNotDefined({name})"),
7591
Self::EnvVarUnknownType { name } => write!(f, "EnvVarlUnknownTType({name})"),
7692
Self::EnvVarWrongType { name } => write!(f, "EnvVarWrongType({name})"),
93+
Self::EnvVarSet { name, cause } => write!(f, "EnvVarSet({name}, {cause})"),
94+
Self::EnvVarTypeCast { name, var_type } => write!(f, "EnvVarTypeCast({name}, {var_type})"),
7795
}
7896
}
7997
}
@@ -92,6 +110,10 @@ impl core::fmt::Display for Error {
92110
"the type of the environment variable {name} does not match its former definition"
93111
)
94112
}
113+
Self::EnvVarSet { name, cause } => {
114+
write!(f, "setting environment variable {name} failed: {cause}")
115+
}
116+
Self::EnvVarTypeCast { name, var_type } => write!(f, "cast of variable {name} to {var_type} failed"),
95117
}
96118
}
97119
}

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ pub mod execution;
1515
pub mod runtime;
1616

1717
// flatten
18-
pub use environment::{DefaultEnvironment, Environment};
1918
pub use error::Error;
2019
pub use execution::Chunk;
2120
pub use runtime::{Runtime, SharedRuntime};

0 commit comments

Comments
 (0)