Skip to content

Commit

Permalink
More error fixes ig
Browse files Browse the repository at this point in the history
  • Loading branch information
doonv committed Jan 8, 2024
1 parent 891805f commit 9c869cc
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 27 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# bevy_dev_console

`bevy_dev_console` is a [Source](https://en.wikipedia.org/wiki/Source_(game_engine))-like developer console plugin for the [Bevy Game Engine](https://github.com/bevyengine/bevy).
`bevy_dev_console` is a Source-inspired developer console plugin for the [Bevy Game Engine](https://github.com/bevyengine/bevy).

![Image of the developer console](doc/console.png)

Expand Down
37 changes: 20 additions & 17 deletions src/builtin_parser/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,25 +190,28 @@ fn eval_expression(
};
let Spanned { span, value } = *value_expr;
match value {
Expression::Variable(variable) => {
if enum_info.contains_variant(&variable) {
let new_enum = DynamicEnum::new(variable, ());

dyn_enum.apply(&new_enum);
} else {
Err(RunError::EnumVariantNotFound {
name: variable,
span,
})?
}
Expression::Variable(name) => {
let variant_info = match enum_info.variant(&name) {
Some(variant_info) => variant_info,
None => {
return Err(RunError::EnumVariantNotFound(span.wrap(name)))
}
};
let VariantInfo::Unit(_) = variant_info else {
return todo_error!("{variant_info:?}");
};

let new_enum = DynamicEnum::new(name, ());

dyn_enum.apply(&new_enum);
}
Expression::StructObject { name, map } => {
let variant_info = enum_info.variant(&name).ok_or(
RunError::EnumVariantNotFound {
name: name.clone(),
span: span.clone(),
},
)?;
let variant_info = match enum_info.variant(&name) {
Some(variant_info) => variant_info,
None => {
return Err(RunError::EnumVariantNotFound(span.wrap(name)))
}
};
let VariantInfo::Struct(variant_info) = variant_info else {
return todo_error!("{variant_info:?}");
};
Expand Down
18 changes: 11 additions & 7 deletions src/builtin_parser/runner/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ pub enum RunError {
actual: String,
span: Span,
},
EnumVariantNotFound {
name: String,
span: Span,
},
EnumVariantNotFound(Spanned<String>),
CannotMoveOutOfResource(Spanned<String>),
CannotNegateUnsignedInteger(Spanned<Number>),
IncompatibleNumberTypes {
Expand All @@ -53,7 +50,8 @@ pub enum RunError {
span: Span,
},
ExpectedVariableGotFunction(Spanned<String>),
CannotReflectReference(std::ops::Range<usize>),
CannotReflectReference(Span),
CannotReflectResource(Span),
}

impl RunError {
Expand All @@ -72,14 +70,15 @@ impl RunError {
VariableMoved(Spanned { span, .. }) => vec![span.clone()],
CannotBorrowValue(Spanned { span, .. }) => vec![span.clone()],
IncompatibleReflectTypes { span, .. } => vec![span.clone()],
EnumVariantNotFound { span, .. } => vec![span.clone()],
EnumVariantNotFound(Spanned { span, .. }) => vec![span.clone()],
EnumVariantStructFieldNotFound { span, .. } => vec![span.clone()],
CannotMoveOutOfResource(Spanned { span, .. }) => vec![span.clone()],
CannotNegateUnsignedInteger(Spanned { span, .. }) => vec![span.clone()],
IncompatibleNumberTypes { span, .. } => vec![span.clone()],
IncompatibleFunctionParameter { span, .. } => vec![span.clone()],
ExpectedVariableGotFunction(Spanned { span, .. }) => vec![span.clone()],
CannotReflectReference(span) => vec![span.clone()],
CannotReflectResource(span) => vec![span.clone()],
}
}
/// Returns all the hints for this error.
Expand Down Expand Up @@ -119,7 +118,9 @@ impl RunError {
"Cannot set incompatible reflect types. Expected `{expected}`, got `{actual}`"
)
.into(),
EnumVariantNotFound { name, span } => todo!(),
EnumVariantNotFound(Spanned { value: name, .. }) => {
format!("Enum variant `{name}` was not found.").into()
}
EnumVariantStructFieldNotFound {
field_name,
variant_name,
Expand Down Expand Up @@ -150,6 +151,9 @@ impl RunError {
CannotReflectReference(_) => {
"Cannot reflect a reference. Try dereferencing it instead.".into()
}
CannotReflectResource(_) => {
"Cannot reflecting resources is not possible at the moment.".into()
}
}
}
}
2 changes: 1 addition & 1 deletion src/builtin_parser/runner/reflection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn object_to_dynamic_struct(
let mut dynamic_struct = DynamicStruct::default();

for (key, (value, span, reflect)) in hashmap {
dynamic_struct.insert_boxed(&key, value.reflect(span, &reflect)?);
dynamic_struct.insert_boxed(&key, value.reflect(span, reflect)?);
}

Ok(dynamic_struct)
Expand Down
2 changes: 1 addition & 1 deletion src/builtin_parser/runner/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Value {

Ok(Box::new(dyn_struct))
}
Value::Resource(_) => todo!(),
Value::Resource(_) => Err(RunError::CannotReflectResource(span)),
}
}

Expand Down

0 comments on commit 9c869cc

Please sign in to comment.