@@ -78,10 +78,25 @@ def _parse_blockhash_response(self, response: Any, rpc_url: str) -> Optional[Has
7878 Hash object if valid blockhash found, None otherwise
7979 """
8080 try :
81+ # Debug logging for response structure
82+ logger .debug (f"Blockhash response from { rpc_url } : type={ type (response )} " )
83+ if hasattr (response , "__dict__" ):
84+ logger .debug (f"Response attributes: { list (response .__dict__ .keys ())} " )
85+
8186 # Check if response has expected structure
8287 if hasattr (response , "value" ) and response .value :
88+ logger .debug (f"Response.value type: { type (response .value )} " )
89+ if hasattr (response .value , "__dict__" ):
90+ logger .debug (
91+ f"Response.value attributes: "
92+ f"{ list (response .value .__dict__ .keys ())} "
93+ )
94+
8395 if hasattr (response .value , "blockhash" ):
8496 blockhash = response .value .blockhash
97+ logger .debug (
98+ f"Found blockhash: type={ type (blockhash )} , value={ blockhash } "
99+ )
85100 # Validate that blockhash is a Hash object (not int or other type)
86101 if isinstance (blockhash , Hash ):
87102 return blockhash
@@ -163,10 +178,21 @@ async def _get_fresh_blockhash(self, max_attempts: int = 3) -> Hash:
163178 )
164179
165180 except Exception as e :
166- logger .warning (
181+ # Log the specific error with more details
182+ error_msg = (
167183 f"Failed to get blockhash from { rpc_to_try } "
168- f"(attempt { attempt + 1 } /{ max_attempts } ): { e } "
184+ f"(attempt { attempt + 1 } /{ max_attempts } )"
169185 )
186+ if "429" in str (e ) or "Too Many Requests" in str (e ):
187+ logger .warning (f"{ error_msg } : Rate limited - { e } " )
188+ elif "connect" in str (e ).lower () or "dns" in str (e ).lower ():
189+ logger .warning (f"{ error_msg } : Connection error - { e } " )
190+ elif hasattr (e , "response" ) and hasattr (e .response , "status_code" ):
191+ logger .warning (f"{ error_msg } : HTTP { e .response .status_code } - { e } " )
192+ else :
193+ logger .warning (f"{ error_msg } : { e } " )
194+ # Log the full exception for debugging
195+ logger .debug (f"Full exception details: { repr (e )} " )
170196
171197 # Try next RPC endpoint on any error
172198 self ._current_rpc_index += 1
@@ -198,8 +224,13 @@ def client(self) -> AsyncClient:
198224 async def close (self ) -> None :
199225 """Close the RPC client connection."""
200226 if self ._client :
201- await self ._client .close ()
202- self ._client = None
227+ try :
228+ await self ._client .close ()
229+ except Exception as e :
230+ # Ignore close errors to prevent test failures due to cleanup issues
231+ logger .debug (f"Error closing RPC client: { e } " )
232+ finally :
233+ self ._client = None
203234
204235 async def health_check (self ) -> bool :
205236 """
@@ -220,13 +251,15 @@ async def health_check(self) -> bool:
220251 await self ._get_fresh_blockhash (max_attempts = 2 )
221252 logger .debug ("RPC connection health check passed" )
222253 return True
223- except ConnectionError :
224- logger .warning ("Failed to fetch fresh blockhash during health check" )
254+ except ConnectionError as e :
255+ logger .warning (
256+ f"Failed to fetch fresh blockhash during health check: { e } "
257+ )
225258 return False
226-
227259 except Exception as e :
228260 logger .warning (f"RPC health check failed: { e } " )
229261 return False
262+ return False
230263
231264 async def __aenter__ (self ) -> "SolanaAIRegistriesClient" :
232265 """Async context manager entry."""
0 commit comments