Skip to content

Commit fe9499d

Browse files
authored
Feat/value error on fail decode (#12)
* raise value error on fail to decode * raise valueerror on fail to get type id * bump ver
1 parent fca0cc1 commit fe9499d

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "bt_decode"
3-
version = "0.5.0-a0"
3+
version = "0.5.0-a1"
44
edition = "2021"
55

66
[lib]

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "bt-decode"
3-
version = "0.5.0-a0"
3+
version = "0.5.0-a1"
44
description = "A wrapper around the scale-codec crate for fast scale-decoding of Bittensor data structures."
55
readme = "README.md"
66
license = {file = "LICENSE"}

src/lib.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -1061,10 +1061,17 @@ mod bt_decode {
10611061
fill_memo_using_well_known_types(&mut memo, &curr_registry);
10621062

10631063
let type_id: u32 = get_type_id_from_type_string(&mut memo, type_string, &mut curr_registry)
1064-
.expect("Failed to get type id from type string");
1064+
.ok_or(PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
1065+
"Failed to get type id from type string: {:?}",
1066+
type_string
1067+
)))?;
10651068

1066-
let decoded =
1067-
decode_as_type(&mut &encoded[..], type_id, &curr_registry).expect("Failed to decode");
1069+
let decoded = decode_as_type(&mut &encoded[..], type_id, &curr_registry).map_err(|_e| {
1070+
PyErr::new::<pyo3::exceptions::PyValueError, _>(format!(
1071+
"Failed to decode type: {:?} with type id: {:?}",
1072+
type_string, type_id
1073+
))
1074+
})?;
10681075

10691076
value_to_pyobject(py, decoded)
10701077
}

0 commit comments

Comments
 (0)