Add error handling to mj_recompile.
This CL adds error handling to the mj_recompile function. If the recompile fails, the function will return -1 and set the error message in the spec. The Python wrapper for mj_recompile will catch the error and raise a ValueError exception. PiperOrigin-RevId: 666784579 Change-Id: I225eca1769ea839c782be3c03fc4ff1ea5885a48
This commit is contained in:
committed by
Copybara-Service
parent
088079eff0
commit
505d01a1c1
@@ -352,5 +352,29 @@ class SpecsTest(absltest.TestCase):
|
||||
self.assertEqual(model.nplugin, 1)
|
||||
self.assertEqual(model.body_plugin[1], 0)
|
||||
|
||||
def test_recompile_error(self):
|
||||
main_xml = """
|
||||
<mujoco>
|
||||
<worldbody>
|
||||
<body>
|
||||
<geom size="0.1"/>
|
||||
</body>
|
||||
</worldbody>
|
||||
</mujoco>
|
||||
"""
|
||||
|
||||
spec = mujoco.MjSpec()
|
||||
spec.from_string(main_xml)
|
||||
model = spec.compile()
|
||||
data = mujoco.MjData(model)
|
||||
|
||||
spec.add_material().name = 'yellow'
|
||||
spec.add_material().name = 'yellow'
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
ValueError, "Error: repeated name 'yellow' in material"
|
||||
):
|
||||
spec.recompile(model, data)
|
||||
|
||||
if __name__ == '__main__':
|
||||
absltest.main()
|
||||
|
||||
Reference in New Issue
Block a user