11import os
2- from typing import List , Optional , Union
2+ from typing import Optional , Union
33
44import mujoco
55
@@ -40,7 +40,8 @@ def _resolve_asset_paths(self, spec: mujoco.MjSpec, xml_path: str):
4040 def load_base_scene (self , xml_path : str ):
4141 """Loads the base world XML."""
4242 if not os .path .exists (xml_path ):
43- raise FileNotFoundError (f"Base scene XML not found: { xml_path } " )
43+ msg = f"Base scene XML not found: { xml_path } "
44+ raise FileNotFoundError (msg )
4445 self .spec = mujoco .MjSpec .from_file (xml_path )
4546 self ._resolve_asset_paths (self .spec , xml_path )
4647
@@ -53,7 +54,7 @@ def _find_site(self, name: str) -> Optional[mujoco._specs.MjsSite]:
5354 def _find_body (self , name : str ) -> Optional [mujoco ._specs .MjsBody ]:
5455 try :
5556 return self .spec .find_body (name )
56- except :
57+ except ValueError :
5758 return None
5859
5960 def add_robot (
@@ -63,7 +64,8 @@ def add_robot(
6364 Attaches a robot MJCF at a specific pose.
6465 """
6566 if not os .path .exists (xml_path ):
66- raise FileNotFoundError (f"Robot MJCF not found: { xml_path } " )
67+ msg = f"Robot MJCF not found: { xml_path } "
68+ raise FileNotFoundError (msg )
6769
6870 child_spec = mujoco .MjSpec .from_file (xml_path )
6971 self ._resolve_asset_paths (child_spec , xml_path )
@@ -78,7 +80,8 @@ def add_robot(
7880
7981 robot_root = self ._find_body (prefixed_root_name )
8082 if not robot_root :
81- raise ValueError (f"Could not find robot root body '{ prefixed_root_name } ' after attachment." )
83+ msg = f"Could not find robot root body '{ prefixed_root_name } ' after attachment."
84+ raise ValueError (msg )
8285
8386 # 3. Apply the pose directly to the body
8487 robot_root .pos = pos
@@ -94,7 +97,8 @@ def add_gripper(self, xml_path: str, robot_prefix: str, gripper_prefix: str = "g
9497 attachment_site = self ._find_site (site_name )
9598
9699 if not attachment_site :
97- raise ValueError (f"Attachment site '{ site_name } ' not found." )
100+ msg = f"Attachment site '{ site_name } ' not found."
101+ raise ValueError (msg )
98102
99103 gripper_spec = mujoco .MjSpec .from_file (xml_path )
100104 self ._resolve_asset_paths (gripper_spec , xml_path )
@@ -110,7 +114,8 @@ def add_object_from_xml(
110114 Assumes the XML contains only one root body in the worldbody.
111115 """
112116 if not os .path .exists (xml_path ):
113- raise FileNotFoundError (f"Object MJCF not found: { xml_path } " )
117+ msg = f"Object MJCF not found: { xml_path } "
118+ raise FileNotFoundError (msg )
114119
115120 # Load the child spec
116121 child_spec = mujoco .MjSpec .from_file (xml_path )
@@ -126,7 +131,8 @@ def add_object_from_xml(
126131
127132 obj_root = self ._find_body (prefixed_root_name )
128133 if not obj_root :
129- raise ValueError (f"Could not find object root body '{ prefixed_root_name } ' after attachment." )
134+ msg = f"Could not find object root body '{ prefixed_root_name } ' after attachment."
135+ raise ValueError (msg )
130136
131137 # Apply the pose
132138 obj_root .pos = pos
0 commit comments