1414from rich .console import Console
1515from rich .pretty import Pretty
1616
17- from .object_store import ObjectStore
17+ from .object_store import ObjectRef , ObjectStore
1818
1919
2020class RichExplorer :
@@ -58,21 +58,10 @@ def explore(self, obj_id: str, path: str = "") -> str:
5858 """Return a string preview of the requested object.
5959
6060 :param obj_id: Identifier obtained from the store.
61- :param path: Navigation path using ``.`` or ``[...]`` notation.
61+ :param path: Navigation path using ``.`` or ``[...]`` notation (e.g. ``@obj_001.path.to.attribute``) .
6262 :return: String representation of the object.
6363 """
64- obj = self .store .get (obj_id )
65- if obj is None :
66- return f"Object { obj_id } not found or expired"
67-
68- # Navigate to path if provided
69- if path :
70- try :
71- self ._validate_path (path )
72- obj = glom (obj , self ._parse_path (path ))
73- except GlomError as exc :
74- return f"Navigation error at { path } : { exc } "
75- # Let ValueError from _validate_path bubble up
64+ obj = self ._get_object_at_path (obj_id , path )
7665
7766 # Generate header and body
7867 header = self ._make_header (obj_id , path , obj )
@@ -90,8 +79,6 @@ def search(self, obj_id: str, pattern: str, path: str = "", case_sensitive: bool
9079 :return: Search results as formatted string.
9180 """
9281 obj = self ._get_object_at_path (obj_id , path )
93- if isinstance (obj , str ) and obj .startswith ("Object" ) and "not found" in obj :
94- return obj
9582
9683 # Generate header
9784 header = self ._make_header (obj_id , path , obj )
@@ -138,15 +125,13 @@ def search(self, obj_id: str, pattern: str, path: str = "", case_sensitive: bool
138125 def slice (self , obj_id : str , start : int = 0 , end : int | None = None , path : str = "" ) -> str :
139126 """Extract a slice from a string or list object.
140127
141- :param obj_id: Identifier obtained from the store .
128+ :param obj_id: Identifier of the object .
142129 :param start: Start index for slicing.
143130 :param end: End index for slicing (None for end of sequence).
144131 :param path: Navigation path to object to slice (optional).
145132 :return: String representation of the slice.
146133 """
147134 obj = self ._get_object_at_path (obj_id , path )
148- if isinstance (obj , str ) and obj .startswith ("Object" ) and "not found" in obj :
149- return obj
150135
151136 # Generate header
152137 header = self ._make_header (obj_id , path , obj )
@@ -193,17 +178,23 @@ def _get_object_at_path(self, obj_id: str, path: str) -> Any:
193178 :param path: Navigation path (optional).
194179 :return: Object at path or error string.
195180 """
196- obj = self .store .get (obj_id )
181+ ref = ObjectRef .parse (obj_id )
182+ # We accept @obj_001 as well as obj_001
183+ if ref is None :
184+ resolved_obj_id = obj_id
185+ else :
186+ resolved_obj_id = ref .obj_id
187+
188+ obj = self .store .get (resolved_obj_id )
197189 if obj is None :
198- return f"Object { obj_id } not found or expired"
190+ raise ValueError ( f"Object { obj_id } not found or expired." )
199191
200192 if path :
193+ self ._validate_path (path )
201194 try :
202- self ._validate_path (path )
203195 obj = glom (obj , self ._parse_path (path ))
204- except GlomError as exc :
205- return f"Navigation error at { path } : { exc } "
206- # Let ValueError from _validate_path bubble up
196+ except GlomError as e :
197+ raise ValueError (f"Object '{ obj_id } ' does not have a value at path '{ path } '." ) from e
207198
208199 return obj
209200
0 commit comments