@@ -72,7 +72,7 @@ async def read(self) -> str | bytes:
7272 else :
7373 return pydantic_core .to_json (result , fallback = str , indent = 2 ).decode ()
7474 except Exception as e :
75- raise ValueError (f"Error reading resource { self .uri } : { e } " )
75+ raise ValueError (f"Error reading resource { self .uri } : { e } " ) from e
7676
7777 @classmethod
7878 def from_function (
@@ -148,7 +148,7 @@ async def read(self) -> str | bytes:
148148 return await anyio .to_thread .run_sync (self .path .read_bytes )
149149 return await anyio .to_thread .run_sync (self .path .read_text )
150150 except Exception as e :
151- raise ValueError (f"Error reading file { self .path } : { e } " )
151+ raise ValueError (f"Error reading file { self .path } : { e } " ) from e
152152
153153
154154class HttpResource (Resource ):
@@ -193,7 +193,7 @@ def list_files(self) -> list[Path]: # pragma: no cover
193193 return list (self .path .glob (self .pattern )) if not self .recursive else list (self .path .rglob (self .pattern ))
194194 return list (self .path .glob ("*" )) if not self .recursive else list (self .path .rglob ("*" ))
195195 except Exception as e :
196- raise ValueError (f"Error listing directory { self .path } : { e } " )
196+ raise ValueError (f"Error listing directory { self .path } : { e } " ) from e
197197
198198 async def read (self ) -> str : # Always returns JSON string # pragma: no cover
199199 """Read the directory listing."""
@@ -202,4 +202,4 @@ async def read(self) -> str: # Always returns JSON string # pragma: no cover
202202 file_list = [str (f .relative_to (self .path )) for f in files if f .is_file ()]
203203 return json .dumps ({"files" : file_list }, indent = 2 )
204204 except Exception as e :
205- raise ValueError (f"Error reading directory { self .path } : { e } " )
205+ raise ValueError (f"Error reading directory { self .path } : { e } " ) from e
0 commit comments