Improve error messages for named/indexed lookups in WASM bindings.

PiperOrigin-RevId: 862682001
Change-Id: I6381af64b724de0ab5aee43cdc89ce463b590cf1
This commit is contained in:
Google DeepMind
2026-01-29 04:52:48 -08:00
committed by Copybara-Service
parent f6796f36b2
commit 59c5017073
4 changed files with 118 additions and 5 deletions
+20 -1
View File
@@ -1879,7 +1879,26 @@ describe('MuJoCo WASM Bindings', () => {
it('should throw an error for invalid geom names in model', () => {
expect(() => {
model!.geom('badgeom');
}).toThrowError('MuJoCo Error: Invalid name, MjModel.geom not found');
})
.toThrowError(
`MuJoCo Error: Invalid name 'badgeom' for geom. Valid names: \['mybox', 'myplane'\]`);
});
// Corresponds to
// bindings_test.py:test_named_indexing_invalid_index_in_model
it('should throw an error for invalid geom indices in model', () => {
const numGeoms = model!.ngeom;
expect(() => {
model!.geom(numGeoms);
})
.toThrowError(
`MuJoCo Error: Invalid index 3 for geom. Valid indices from 0 to 2`);
expect(() => {
model!.geom(-1);
})
.toThrowError(
`MuJoCo Error: Invalid index -1 for geom. Valid indices from 0 to 2`);
});
// Corresponds to bindings_test.py:test_named_indexing_geom_size