rogue_machines 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa693def3e755cd4a8d319468e8d79a034365846fbebc48f46045fa68d302738
4
- data.tar.gz: 2e26d2e9a9f8acbc4313c3ddc0774c2bad386505ba7e60e415afe278c8dd8ae2
3
+ metadata.gz: c2fd4172fc4b5d0916de7b314c5fb63734eaca6322081e9a765dcdf603f5f3c2
4
+ data.tar.gz: '063865c73fa28cde9bf8dde2431a01b51cb216a08f928447b462849700272e7d'
5
5
  SHA512:
6
- metadata.gz: b805b2dca79f7c64ec8bee0ac52d56e72e8146e013fc601441293b402d56685b3d113c0b1e825aba9403ecbd861d49fe088834f0271ee3002f57cc2d760678dd
7
- data.tar.gz: fc6198e1dc7e83c2e490d7ba059e656c114bfc5f2673e943a797b56468e9ab0d70fcf0d6807c295988558b8da0aafbb7ac640884c676fa6026e4f30d41d29977
6
+ metadata.gz: 0b60b14e47a1babc34a59493f52e2c68622360a6b51723c23fcb6a30257bbc4da24c983f8b169f05dd2cc14d9c6dedff8b026c78dde8ce11e59d8060f6150a0c
7
+ data.tar.gz: 676a7fd1e0d8917f7d7d09c61ef2676693b8415ba9dfc90d91458796919f9d63a7bc14b54e69d08a0e15aa87353a8ea595b61785e8ba5bab93602e413f9df5e3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.1.3](https://github.com/seuros/rogue_machines/compare/rogue_machines/v0.1.2...rogue_machines/v0.1.3) (2026-11-06)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * extract arg_error and range error helpers in ffi ([ee6ccf4](https://github.com/seuros/rogue_machines/commit/ee6ccf4ef0caef9f5ef7b4496ee0ccdb633ddc1e))
9
+ * keep test modules out of the packaged crate ([425cf81](https://github.com/seuros/rogue_machines/commit/425cf81b4e94ea2abd8de21ec74426c71338c11c))
10
+
3
11
  ## [0.1.2](https://github.com/seuros/rogue_machines/compare/rogue_machines/v0.1.1...rogue_machines/v0.1.2) (2026-11-01)
4
12
 
5
13
 
data/Cargo.lock CHANGED
@@ -228,11 +228,11 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
228
228
 
229
229
  [[package]]
230
230
  name = "rogue-machines"
231
- version = "0.2.0"
231
+ version = "0.2.1"
232
232
 
233
233
  [[package]]
234
234
  name = "rogue_machines_native"
235
- version = "0.1.1"
235
+ version = "0.1.2"
236
236
  dependencies = [
237
237
  "magnus",
238
238
  "rb-sys",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "rogue-machines"
3
- version = "0.2.0"
3
+ version = "0.2.1"
4
4
  edition.workspace = true
5
5
  rust-version.workspace = true
6
6
  authors = ["Abdelkader Boudih <oss@seuros.com>"]
@@ -10,7 +10,7 @@ repository = "https://github.com/seuros/rogue_machines"
10
10
  keywords = ["fault-injection", "chaos-engineering", "resilience", "testing", "no-std"]
11
11
  categories = ["no-std", "development-tools::testing"]
12
12
  readme = "README.md"
13
-
13
+ exclude = ["src/**/tests.rs", "tests/"]
14
14
  [lib]
15
15
  name = "rogue_machines"
16
16
  crate-type = ["lib"]
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "rogue_machines_native"
3
- version = "0.1.1"
3
+ version = "0.1.2"
4
4
  edition.workspace = true
5
5
  rust-version.workspace = true
6
6
  authors = ["Abdelkader Boudih <oss@seuros.com>"]
@@ -10,6 +10,8 @@
10
10
  mod injection;
11
11
  mod registry;
12
12
 
13
+ use std::borrow::Cow;
14
+ use std::fmt::Display;
13
15
  use std::sync::OnceLock;
14
16
 
15
17
  use magnus::value::Opaque;
@@ -38,15 +40,15 @@ pub(crate) const LONGEST_DELAY: f64 = 5.0 * 60.0;
38
40
  #[expect(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
39
41
  pub(crate) fn duration(ruby: &Ruby, name: &str, seconds: f64, longest: f64) -> Result<u64, Error> {
40
42
  if !seconds.is_finite() || seconds <= 0.0 || seconds > longest {
41
- return Err(Error::new(
42
- ruby.exception_arg_error(),
43
+ return Err(arg_error(
44
+ ruby,
43
45
  format!("{name} must be above 0 and at most {longest} seconds, got {seconds}"),
44
46
  ));
45
47
  }
46
48
  let nanoseconds = seconds * f64::from(NS_PER_SECOND);
47
49
  if nanoseconds < 1.0 {
48
- return Err(Error::new(
49
- ruby.exception_arg_error(),
50
+ return Err(arg_error(
51
+ ruby,
50
52
  format!("{name} of {seconds} is below the one nanosecond resolution"),
51
53
  ));
52
54
  }
@@ -59,15 +61,9 @@ pub(crate) fn duration(ruby: &Ruby, name: &str, seconds: f64, longest: f64) -> R
59
61
  /// range: magnus would reject that with its own `RangeError`, which would
60
62
  /// leak out of a protected call site as something the gem never documents.
61
63
  pub(crate) fn reading(ruby: &Ruby, name: &str, value: Value) -> Result<u64, Error> {
62
- whole(ruby, name, value)?.to_u64().map_err(|_| {
63
- Error::new(
64
- ruby.exception_arg_error(),
65
- format!(
66
- "{name} must be a non-negative Integer of at most {}",
67
- u64::MAX
68
- ),
69
- )
70
- })
64
+ whole(ruby, name, value)?
65
+ .to_u64()
66
+ .map_err(|_| above(ruby, name, u64::MAX))
71
67
  }
72
68
 
73
69
  /// A draw below [`PER_MILLION`].
@@ -76,14 +72,14 @@ pub(crate) fn reading(ruby: &Ruby, name: &str, value: Value) -> Result<u64, Erro
76
72
  /// `rand` returns a Float would inject on every call instead of none.
77
73
  pub(crate) fn draw(ruby: &Ruby, value: Value) -> Result<u32, Error> {
78
74
  let drawn = whole(ruby, "draw", value)?.to_u32().map_err(|_| {
79
- Error::new(
80
- ruby.exception_arg_error(),
75
+ arg_error(
76
+ ruby,
81
77
  format!("draw must be a non-negative Integer below {PER_MILLION}"),
82
78
  )
83
79
  })?;
84
80
  if drawn >= PER_MILLION {
85
- return Err(Error::new(
86
- ruby.exception_arg_error(),
81
+ return Err(arg_error(
82
+ ruby,
87
83
  format!("draw must be below {PER_MILLION}, got {drawn}"),
88
84
  ));
89
85
  }
@@ -92,51 +88,53 @@ pub(crate) fn draw(ruby: &Ruby, value: Value) -> Result<u32, Error> {
92
88
 
93
89
  /// A generation tag.
94
90
  pub(crate) fn counted(ruby: &Ruby, name: &str, value: Value) -> Result<u32, Error> {
95
- whole(ruby, name, value)?.to_u32().map_err(|_| {
96
- Error::new(
97
- ruby.exception_arg_error(),
98
- format!(
99
- "{name} must be a non-negative Integer of at most {}",
100
- u32::MAX
101
- ),
102
- )
103
- })
91
+ whole(ruby, name, value)?
92
+ .to_u32()
93
+ .map_err(|_| above(ruby, name, u32::MAX))
94
+ }
95
+
96
+ /// Refuses an Integer that is negative or larger than `max`.
97
+ fn above(ruby: &Ruby, name: &str, max: impl Display) -> Error {
98
+ arg_error(
99
+ ruby,
100
+ format!("{name} must be a non-negative Integer of at most {max}"),
101
+ )
104
102
  }
105
103
 
106
104
  fn whole(ruby: &Ruby, name: &str, value: Value) -> Result<Integer, Error> {
107
- Integer::from_value(value).ok_or_else(|| {
108
- Error::new(
109
- ruby.exception_arg_error(),
110
- format!("{name} must be an Integer"),
111
- )
112
- })
105
+ Integer::from_value(value).ok_or_else(|| arg_error(ruby, format!("{name} must be an Integer")))
113
106
  }
114
107
 
115
108
  /// A share of calls, rejecting one outside a whole or too small to express.
116
109
  #[expect(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
117
110
  pub(crate) fn share(ruby: &Ruby, given: f64) -> Result<Fraction, Error> {
118
111
  if !given.is_finite() || !(0.0..=1.0).contains(&given) {
119
- return Err(Error::new(
120
- ruby.exception_arg_error(),
112
+ return Err(arg_error(
113
+ ruby,
121
114
  format!("share must be between 0 and 1, got {given}"),
122
115
  ));
123
116
  }
124
117
  let millionths = given * f64::from(PER_MILLION);
125
118
  if given > 0.0 && millionths < 1.0 {
126
- return Err(Error::new(
127
- ruby.exception_arg_error(),
119
+ return Err(arg_error(
120
+ ruby,
128
121
  format!("share of {given} is below the one millionth resolution"),
129
122
  ));
130
123
  }
131
124
  let millionths = millionths.round() as u32;
132
125
  Fraction::new(millionths).ok_or_else(|| {
133
- Error::new(
134
- ruby.exception_arg_error(),
126
+ arg_error(
127
+ ruby,
135
128
  format!("share of {millionths} millionths is not a whole"),
136
129
  )
137
130
  })
138
131
  }
139
132
 
133
+ /// An `ArgumentError` carrying `message`.
134
+ pub(crate) fn arg_error(ruby: &Ruby, message: impl Into<Cow<'static, str>>) -> Error {
135
+ Error::new(ruby.exception_arg_error(), message)
136
+ }
137
+
140
138
  pub(crate) fn error(ruby: &Ruby, message: String) -> Error {
141
139
  ERROR.get().map_or_else(
142
140
  || {
@@ -8,7 +8,9 @@ use magnus::{Error, RArray, RHash, RModule, Ruby, Value, function, method, prelu
8
8
  use rogue_machines::{Decision, EXPERIMENTS, Experiment, Fault, Rogue, Slot};
9
9
 
10
10
  use crate::injection::injection;
11
- use crate::{LONGEST_DELAY, LONGEST_EXPERIMENT, counted, draw, duration, error, reading, share};
11
+ use crate::{
12
+ LONGEST_DELAY, LONGEST_EXPERIMENT, arg_error, counted, draw, duration, error, reading, share,
13
+ };
12
14
 
13
15
  /// The core registry, and the names standing in for its slot indices.
14
16
  #[magnus::wrap(class = "RogueMachines::Rogue", free_immediately, size)]
@@ -105,10 +107,7 @@ impl Wrapper {
105
107
  LONGEST_EXPERIMENT,
106
108
  )?)
107
109
  .ok_or_else(|| {
108
- Error::new(
109
- ruby.exception_arg_error(),
110
- "expires_in puts the expiry past the end of the clock",
111
- )
110
+ arg_error(ruby, "expires_in puts the expiry past the end of the clock")
112
111
  })?;
113
112
  let fraction = share(ruby, given_share)?;
114
113
  let fault = fault(ruby, &named, delay)?;
@@ -254,18 +253,14 @@ fn fault(ruby: &Ruby, named: &str, delay: Option<f64>) -> Result<Fault, Error> {
254
253
  "raise" => Ok(Fault::Raise),
255
254
  "garble" => Ok(Fault::Garble),
256
255
  "delay" => {
257
- let seconds = delay.ok_or_else(|| {
258
- Error::new(
259
- ruby.exception_arg_error(),
260
- "a :delay fault needs delay: in seconds",
261
- )
262
- })?;
256
+ let seconds =
257
+ delay.ok_or_else(|| arg_error(ruby, "a :delay fault needs delay: in seconds"))?;
263
258
  Ok(Fault::Delay {
264
259
  ns: duration(ruby, "delay", seconds, LONGEST_DELAY)?,
265
260
  })
266
261
  }
267
- other => Err(Error::new(
268
- ruby.exception_arg_error(),
262
+ other => Err(arg_error(
263
+ ruby,
269
264
  format!("fault must be :raise, :delay or :garble, got {other:?}"),
270
265
  )),
271
266
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RogueMachines
4
- VERSION = '0.1.2'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rogue_machines
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih