Skip to content

Commit

Permalink
Make FunctionError variants sound more error-y
Browse files Browse the repository at this point in the history
  • Loading branch information
MrGVSV committed Jun 29, 2024
1 parent 4088843 commit b8ed0a8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions crates/bevy_reflect/src/func/args/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ impl ArgInfo {
}

/// A representation of an argument.
///
/// This is primarily used for error reporting and debugging.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ArgId {
/// The index of the argument within its function.
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_reflect/src/func/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use thiserror::Error;
pub enum FunctionError {
/// An error occurred while converting an argument.
#[error(transparent)]
Arg(#[from] ArgError),
ArgError(#[from] ArgError),
/// The number of arguments provided does not match the expected number.
#[error("expected {expected} arguments but received {received}")]
ArgCount { expected: usize, received: usize },
InvalidArgCount { expected: usize, received: usize },
}
8 changes: 4 additions & 4 deletions crates/bevy_reflect/src/func/into_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ macro_rules! impl_into_function {

$crate::func::DynamicFunction::new(move |args, _info| {
if args.len() != COUNT {
return Err($crate::func::error::FunctionError::ArgCount {
return Err($crate::func::error::FunctionError::InvalidArgCount {
expected: COUNT,
received: args.len(),
});
Expand Down Expand Up @@ -186,7 +186,7 @@ macro_rules! impl_into_function {

$crate::func::DynamicFunction::new(move |args, _info| {
if args.len() != COUNT {
return Err($crate::func::error::FunctionError::ArgCount {
return Err($crate::func::error::FunctionError::InvalidArgCount {
expected: COUNT,
received: args.len(),
});
Expand Down Expand Up @@ -237,7 +237,7 @@ macro_rules! impl_into_function {

$crate::func::DynamicFunction::new(move |args, _info| {
if args.len() != COUNT {
return Err($crate::func::error::FunctionError::ArgCount {
return Err($crate::func::error::FunctionError::InvalidArgCount {
expected: COUNT,
received: args.len(),
});
Expand Down Expand Up @@ -288,7 +288,7 @@ macro_rules! impl_into_function {

$crate::func::DynamicFunction::new(move |args, _info| {
if args.len() != COUNT {
return Err($crate::func::error::FunctionError::ArgCount {
return Err($crate::func::error::FunctionError::InvalidArgCount {
expected: COUNT,
received: args.len(),
});
Expand Down
8 changes: 4 additions & 4 deletions crates/bevy_reflect/src/func/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ mod tests {
let result = func.call(args);
assert_eq!(
result.unwrap_err(),
FunctionError::ArgCount {
FunctionError::InvalidArgCount {
expected: 1,
received: 0
}
Expand All @@ -182,7 +182,7 @@ mod tests {
let result = func.call(args);
assert_eq!(
result.unwrap_err(),
FunctionError::ArgCount {
FunctionError::InvalidArgCount {
expected: 0,
received: 1
}
Expand All @@ -198,7 +198,7 @@ mod tests {
let result = func.call(args);
assert_eq!(
result.unwrap_err(),
FunctionError::Arg(ArgError::UnexpectedType {
FunctionError::ArgError(ArgError::UnexpectedType {
id: ArgId::Index(0),
expected: Cow::Borrowed(i32::type_path()),
received: Cow::Borrowed(u32::type_path())
Expand All @@ -215,7 +215,7 @@ mod tests {
let result = func.call(args);
assert_eq!(
result.unwrap_err(),
FunctionError::Arg(ArgError::InvalidOwnership {
FunctionError::ArgError(ArgError::InvalidOwnership {
id: ArgId::Index(0),
expected: Ownership::Ref,
received: Ownership::Owned
Expand Down

0 comments on commit b8ed0a8

Please sign in to comment.