Skip to content

Commit

Permalink
Fix crash when component parameters are invalid (#16735)
Browse files Browse the repository at this point in the history
# Objective

Fix the following crash when using BRP to insert a malformed component:

```
thread 'main' panicked at /home/purplg/workspaces/evtc-replay/bevy/crates/bevy_remote/src/builtin_methods.rs:926:18:
called `Result::unwrap()` on an `Err` value: Error("invalid type: map, expected f32", line: 0, column: 0)
```

## Solution

Return an error instead of unwrapping.

## Testing

Tested by sending this malformed payload before and after implementing
the fix:

```json
{
    "jsonrpc": "2.0",
    "id": 0,
    "method": "bevy/insert",
    "params": {
        "entity": 4294967307,
        "components": {
            "bevy_transform::components::transform::Transform": {
                "rotation": [
                    0.0,
                    0.0,
                    0.0,
                    1.0
                ],
                "scale": [
                    1.0,
                    1.0,
                    1.0
                ],
                "translation": [
                    {},
                    0.0,
                    0.0
                ]
            }
        }
    }
}
```

After implementing the fix, I receive the following response instead of
a crash:

```json
{
    "jsonrpc": "2.0",
    "id": 0,
    "error": {
        "code": -23402,
        "message": "bevy_transform::components::transform::Transform is invalid: invalid type: map, expected f32"
    }
}
```
  • Loading branch information
purplg authored Dec 10, 2024
1 parent d6ebc0e commit 7662b4f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/bevy_remote/src/builtin_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ fn deserialize_components(
let reflected: Box<dyn PartialReflect> =
TypedReflectDeserializer::new(component_type, type_registry)
.deserialize(&component)
.unwrap();
.map_err(|err| anyhow!("{component_path} is invalid: {err}"))?;
reflect_components.push(reflected);
}

Expand Down

0 comments on commit 7662b4f

Please sign in to comment.