Skip to content

Commit

Permalink
chore: improve panic messages
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Nov 22, 2023
1 parent a1f4384 commit 648e1ac
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions yara-x/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ impl TypeValue {
.as_bstr()
} else {
panic!(
"called `as_bstr` on TypeValue that is not TypeValue::String"
"called `as_bstr` on a TypeValue that is not TypeValue::String, it is: {:?}",
self
)
}
}
Expand All @@ -295,23 +296,32 @@ impl TypeValue {
if let TypeValue::Array(array) = self {
array.clone()
} else {
panic!("called `as_array` on a TypeValue that is not TypeValue::Array")
panic!(
"called `as_array` on a TypeValue that is not TypeValue::Array, it is: {:?}",
self
)
}
}

pub fn as_struct(&self) -> Rc<Struct> {
if let TypeValue::Struct(structure) = self {
structure.clone()
} else {
panic!("called `as_struct` on a TypeValue that is not TypeValue::Struct")
panic!(
"called `as_struct` on a TypeValue that is not TypeValue::Struct, it is: {:?}",
self
)
}
}

pub fn as_map(&self) -> Rc<Map> {
if let TypeValue::Map(map) = self {
map.clone()
} else {
panic!("called `as_map` on a TypeValue that is not TypeValue::Map")
panic!(
"called `as_map` on a TypeValue that is not TypeValue::Map, it is: {:?}",
self
)
}
}

Expand All @@ -320,7 +330,8 @@ impl TypeValue {
func.clone()
} else {
panic!(
"called `as_func` on a TypeValue that is not TypeValue::Func"
"called `as_func` on a TypeValue that is not TypeValue::Func, it is: {:?}",
self
)
}
}
Expand All @@ -332,7 +343,10 @@ impl TypeValue {
.cloned()
.expect("TypeValue doesn't have an associated value")
} else {
panic!("called `as_integer` on a TypeValue that is not TypeValue::Integer")
panic!(
"called `as_integer` on a TypeValue that is not TypeValue::Integer, it is: {:?}",
self
)
}
}

Expand All @@ -343,7 +357,10 @@ impl TypeValue {
.cloned()
.expect("TypeValue doesn't have an associated value")
} else {
panic!("called `as_float` on a TypeValue that is not TypeValue::Float")
panic!(
"called `as_float` on a TypeValue that is not TypeValue::Float, it is: {:?}",
self
)
}
}

Expand All @@ -355,7 +372,8 @@ impl TypeValue {
.expect("TypeValue doesn't have an associated value")
} else {
panic!(
"called `as_bool` on a TypeValue that is not TypeValue::Bool"
"called `as_bool` on a TypeValue that is not TypeValue::Bool, it is: {:?}",
self
)
}
}
Expand Down

0 comments on commit 648e1ac

Please sign in to comment.