@@ -1084,7 +1084,7 @@ mod bt_decode {
1084
1084
to_encode : Py < PyAny > ,
1085
1085
) -> PyResult < Vec < u8 > > {
1086
1086
// Initialize logging
1087
- pyo3_log:: try_init ( ) ;
1087
+ let _ = pyo3_log:: try_init ( ) ;
1088
1088
1089
1089
// Create a memoization table for the type string to type id conversion
1090
1090
let mut memo = HashMap :: < String , u32 > :: new ( ) ;
@@ -1094,17 +1094,29 @@ mod bt_decode {
1094
1094
fill_memo_using_well_known_types ( & mut memo, & curr_registry) ;
1095
1095
1096
1096
let type_id: u32 = get_type_id_from_type_string ( & mut memo, type_string, & mut curr_registry)
1097
- . expect ( "Failed to get type id from type string" ) ;
1097
+ . ok_or ( PyErr :: new :: < pyo3:: exceptions:: PyValueError , _ > ( format ! (
1098
+ "Failed to get type id from type string: {:?}" ,
1099
+ type_string
1100
+ ) ) ) ?;
1098
1101
1099
- let ty = curr_registry
1100
- . resolve ( type_id)
1101
- . expect ( & format ! ( "Failed to resolve type (0): {:?}" , type_string) ) ;
1102
+ let ty = curr_registry. resolve ( type_id) . ok_or ( PyErr :: new :: <
1103
+ pyo3:: exceptions:: PyValueError ,
1104
+ _ ,
1105
+ > ( format ! (
1106
+ "Failed to resolve type (0): {:?}" ,
1107
+ type_string
1108
+ ) ) ) ?;
1102
1109
1103
1110
let as_value: Value < u32 > =
1104
1111
pyobject_to_value ( py, & to_encode, ty, type_id, portable_registry) ?;
1105
1112
1106
1113
let mut encoded: Vec < u8 > = Vec :: < u8 > :: new ( ) ;
1107
- encode_as_type ( & as_value, type_id, & curr_registry, & mut encoded) . expect ( "Failed to encode" ) ;
1114
+ encode_as_type ( & as_value, type_id, & curr_registry, & mut encoded) . map_err ( |_e| {
1115
+ PyErr :: new :: < pyo3:: exceptions:: PyValueError , _ > ( format ! (
1116
+ "Failed to encode type: {:?} with type id: {:?}" ,
1117
+ type_string, type_id
1118
+ ) )
1119
+ } ) ?;
1108
1120
1109
1121
Ok ( encoded)
1110
1122
}
0 commit comments