Skip to content

Commit 9a7be5d

Browse files
committed
Make felt_from_number report errors properly
instead of returning Ok(None) in case of an error
1 parent 6e32e71 commit 9a7be5d

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#### Upcoming Changes
44

5+
* Fix felt_from_number not properly returning parse errors [#1012](https://github.com/lambdaclass/cairo-rs/pull/1012)
6+
57
* Implement hints on field_arithmetic lib (Part 2) [#1004](https://github.com/lambdaclass/cairo-rs/pull/1004)
68

79
`BuiltinHintProcessor` now supports the following hint:

src/serde/deserialize_program.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,10 @@ where
162162
D: Deserializer<'de>,
163163
{
164164
let n = Number::deserialize(deserializer)?;
165-
Ok(Felt252::parse_bytes(n.to_string().as_bytes(), 10))
165+
match Felt252::parse_bytes(n.to_string().as_bytes(), 10) {
166+
Some(x) => Ok(Some(x)),
167+
None => Err(String::from("felt_from_number parse error")).map_err(de::Error::custom),
168+
}
166169
}
167170

168171
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
@@ -1345,4 +1348,18 @@ mod tests {
13451348
"()"
13461349
);
13471350
}
1351+
1352+
#[test]
1353+
#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)]
1354+
fn deserialize_nonbase10_number_errors() {
1355+
let valid_json = r#"
1356+
{
1357+
"value" : 0x123
1358+
}"#;
1359+
1360+
1361+
let iden: Result<Identifier,serde_json::Error> = serde_json::from_str(valid_json);
1362+
assert!(iden.err().is_some());
1363+
}
1364+
13481365
}

0 commit comments

Comments
 (0)