Replace bare except with specific exceptions in api layer (#783) (#1039)

This commit is contained in:
01AtharvR 2026-07-13 16:36:23 +05:30 committed by GitHub
parent 40f01c123b
commit b1d1833234
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 11 additions and 11 deletions

View file

@ -25,7 +25,7 @@ def check_error(response):
try:
msg = response["error"]["message"]
tp = response["error"]["type"]
except:
except KeyError:
raise ApplicationException(response["error"])
raise ApplicationException(f"{tp}: {msg}")
@ -208,7 +208,7 @@ class Api:
try:
# Parse the response as JSON
object = resp.json()
except:
except ValueError:
raise ProtocolException(f"Expected JSON response")
check_error(object)

View file

@ -25,7 +25,7 @@ def check_error(response):
try:
msg = response["error"]["message"]
tp = response["error"]["type"]
except:
except KeyError:
raise ApplicationException(response["error"])
raise ApplicationException(f"{tp}: {msg}")
@ -88,7 +88,7 @@ class AsyncFlow:
try:
obj = await resp.json()
except:
except (ValueError, aiohttp.ContentTypeError):
raise ProtocolException(f"Expected JSON response")
check_error(obj)

View file

@ -142,7 +142,7 @@ class AsyncSocketClient:
for queue in self._pending.values():
try:
await queue.put({"error": str(e)})
except:
except asyncio.CancelledError :
pass
finally:
self._connected = False

View file

@ -201,7 +201,7 @@ class BulkClient:
finally:
try:
loop.run_until_complete(async_gen.aclose())
except:
except Exception:
pass
async def _export_triples_async(self, flow: str) -> Iterator[Triple]:
@ -299,7 +299,7 @@ class BulkClient:
finally:
try:
loop.run_until_complete(async_gen.aclose())
except:
except Exception:
pass
async def _export_graph_embeddings_async(self, flow: str) -> Iterator[Dict[str, Any]]:
@ -393,7 +393,7 @@ class BulkClient:
finally:
try:
loop.run_until_complete(async_gen.aclose())
except:
except Exception:
pass
async def _export_document_embeddings_async(self, flow: str) -> Iterator[Dict[str, Any]]:
@ -517,7 +517,7 @@ class BulkClient:
finally:
try:
loop.run_until_complete(async_gen.aclose())
except:
except Exception:
pass
async def _export_entity_contexts_async(self, flow: str) -> Iterator[Dict[str, Any]]:

View file

@ -254,7 +254,7 @@ class Config:
)
for v in object["values"]
]
except:
except (KeyError, TypeError):
raise ProtocolException(f"Response not formatted correctly")
def get_values_all_workspaces(self, type):
@ -330,6 +330,6 @@ class Config:
try:
return object["config"], object["version"]
except:
except KeyError:
raise ProtocolException(f"Response not formatted correctly")