Skip to content
This repository was archived by the owner on May 27, 2025. It is now read-only.

Commit a0f0b78

Browse files
nievespg1Gabriel Nieves-Ponce
andauthored
Gnievesponce/remove verbose exceptions (#32)
Co-authored-by: Gabriel Nieves-Ponce <[email protected]>
1 parent f6cf4b6 commit a0f0b78

File tree

11 files changed

+78
-87
lines changed

11 files changed

+78
-87
lines changed

backend/src/api/common.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ def validate_index_file_exist(index_name: str, file_name: str):
5252
)
5353
)
5454
container_store_client.read_item(index_name, index_name)
55-
except Exception as e:
55+
except Exception:
5656
raise ValueError(
57-
f"Container {index_name} is not a valid index.\nDetails: {str(e)}"
57+
f"Container {index_name} is not a valid index."
5858
)
5959
# check for file existence
6060
index_container_client = blob_service_client.get_container_client(index_name)

backend/src/api/data.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ async def get_all_data_storage_containers():
6262
for item in container_store_client.read_all_items():
6363
if item["type"] == "data":
6464
items.append(item["human_readable_name"])
65-
except Exception as e:
65+
except Exception:
6666
reporter = ReporterSingleton().get_instance()
67-
reporter.on_error("Error getting list of blob containers.\nDetails: " + str(e))
67+
reporter.on_error("Error getting list of blob containers.")
6868
raise HTTPException(
6969
status_code=500, detail="Error getting list of blob containers."
7070
)
@@ -185,9 +185,9 @@ async def upload_files(
185185
}
186186
)
187187
return BaseResponse(status="File upload successful.")
188-
except Exception as e:
188+
except Exception:
189189
reporter.on_error(
190-
"Error uploading files.", details={"ErrorDetails": str(e), "files": files}
190+
"Error uploading files.", details={"files": files}
191191
)
192192
raise HTTPException(
193193
status_code=500,
@@ -219,11 +219,11 @@ async def delete_files(storage_name: str):
219219
item=sanitized_storage_name,
220220
partition_key=sanitized_storage_name,
221221
)
222-
except Exception as e:
222+
except Exception:
223223
reporter = ReporterSingleton().get_instance()
224224
reporter.on_error(
225225
f"Error deleting container {storage_name}.",
226-
details={"ErrorDetails": str(e), "Container": storage_name},
226+
details={"Container": storage_name},
227227
)
228228
raise HTTPException(
229229
status_code=500, detail=f"Error deleting container '{storage_name}'."

backend/src/api/experimental.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ def task():
189189
stream_response(report_df=report_df, query=request.query),
190190
media_type="application/json",
191191
)
192-
except Exception as e:
192+
except Exception:
193193
# temporary logging of errors until reporters are in place
194-
print(e)
195-
print(traceback.format_exc())
196-
raise HTTPException(status_code=500, detail=str(e))
194+
raise HTTPException(status_code=500, detail=None)

backend/src/api/graph.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ async def retrieve_graphml_file(index_name: str):
5454
media_type="application/octet-stream",
5555
headers={"Content-Disposition": f"attachment; filename={graphml_filename}"},
5656
)
57-
except Exception as e:
57+
except Exception:
5858
reporter = ReporterSingleton().get_instance()
59-
reporter.on_error(f"Could not retrieve graphml file: {str(e)}")
59+
reporter.on_error("Could not retrieve graphml file")
6060
raise HTTPException(
6161
status_code=500,
6262
detail=f"Could not retrieve graphml file for index '{index_name}'.",
@@ -80,9 +80,9 @@ async def retrieve_graph_stats(index_name: str):
8080
bytes_io = BytesIO(blob_data)
8181
g = nx.read_graphml(bytes_io)
8282
return GraphDataResponse(nodes=len(g.nodes), edges=len(g.edges))
83-
except Exception as e:
83+
except Exception:
8484
reporter = ReporterSingleton().get_instance()
85-
reporter.on_error(f"Could not retrieve graph data file: {str(e)}")
85+
reporter.on_error("Could not retrieve graph data file")
8686
raise HTTPException(
8787
status_code=500,
8888
detail=f"Could not retrieve graph statistics for index '{index_name}'.",

backend/src/api/index.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -198,21 +198,21 @@ async def setup_indexing_pipeline(
198198
batch_v1.create_namespaced_job(
199199
body=job_manifest, namespace=os.environ["AKS_NAMESPACE"]
200200
)
201-
except ApiException as e:
201+
except ApiException:
202202
raise HTTPException(
203203
status_code=500,
204-
detail=f"exception when calling BatchV1Api->create_namespaced_job: {str(e)}",
204+
detail="exception when calling BatchV1Api->create_namespaced_job",
205205
)
206206
return BaseResponse(status="indexing operation has been scheduled.")
207-
except Exception as e:
207+
except Exception:
208208
reporter = ReporterSingleton().get_instance()
209209
job_details = {
210210
"storage_name": storage_name,
211211
"index_name": index_name,
212212
}
213213
reporter.on_error(
214214
"Error creating a new index",
215-
details={"error_details": str(e), "job_details": job_details},
215+
details={"job_details": job_details},
216216
)
217217
raise HTTPException(
218218
status_code=500,
@@ -336,26 +336,25 @@ async def _start_indexing_pipeline(index_name: str):
336336
if pipeline_job.status == PipelineJobState.FAILED:
337337
exit(1) # signal to AKS that indexing job failed
338338

339-
except Exception as e:
339+
except Exception:
340340
pipeline_job.status = PipelineJobState.FAILED
341341

342342
# update failed state in cosmos db
343343
error_details = {
344-
"error_details": str(e),
345344
"error_message": "Indexing pipeline failed.",
346345
}
347346
# log error in local index directory logs
348347
workflow_callbacks.on_error(
349348
message=f"Index Name: {index_name}, Container Name: {storage_name}\n",
350-
cause=e,
351-
stack=traceback.format_exc(),
349+
cause=None,
350+
stack=None,
352351
details=error_details,
353352
)
354353
# log error in global index directory logs
355354
reporter.on_error(
356355
f"Index Name: {index_name}, Container Name: {storage_name}\n {str(e)} \n",
357356
cause=str(e),
358-
stack=traceback.format_exc(),
357+
stack=None,
359358
details=error_details,
360359
)
361360
raise HTTPException(
@@ -405,9 +404,9 @@ async def get_all_indexes():
405404
for item in container_store_client.read_all_items():
406405
if item["type"] == "index":
407406
items.append(item["human_readable_name"])
408-
except Exception as e:
407+
except Exception:
409408
reporter = ReporterSingleton().get_instance()
410-
reporter.on_error(f"Error retrieving index names: {str(e)}")
409+
reporter.on_error("Error retrieving index names")
411410
return IndexNameList(index_name=items)
412411

413412

@@ -437,21 +436,21 @@ def _delete_k8s_job(job_name: str, namespace: str) -> None:
437436
try:
438437
batch_v1 = client.BatchV1Api()
439438
batch_v1.delete_namespaced_job(name=job_name, namespace=namespace)
440-
except Exception as e:
439+
except Exception:
441440
reporter.on_error(
442441
f"Error deleting k8s job {job_name}.",
443-
details={"error_details": str(e), "Container": job_name},
442+
details={"Container": job_name},
444443
)
445444
pass
446445
try:
447446
core_v1 = client.CoreV1Api()
448447
job_pod = _get_pod_name(job_name, os.environ["AKS_NAMESPACE"])
449448
if job_pod:
450449
core_v1.delete_namespaced_pod(job_pod, namespace=namespace)
451-
except Exception as e:
450+
except Exception:
452451
reporter.on_error(
453452
f"Error deleting k8s pod for job {job_name}.",
454-
details={"error_details": str(e), "Container": job_name},
453+
details={"Container": job_name},
455454
)
456455
pass
457456

@@ -510,11 +509,11 @@ async def delete_index(index_name: str):
510509
if ai_search_index_name in index_client.list_index_names():
511510
index_client.delete_index(ai_search_index_name)
512511

513-
except Exception as e:
512+
except Exception:
514513
reporter.on_error(
515514
message=f"Error encountered while deleting all data for index {index_name}.",
516-
stack=traceback.format_exc(),
517-
details={"error_details": str(e), "container": index_name},
515+
stack=None,
516+
details={"container": index_name},
518517
)
519518
raise HTTPException(
520519
status_code=500, detail=f"Error deleting index '{index_name}'."

backend/src/api/index_configuration.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ async def get_all_entitys():
6161
)
6262
for item in entity_container.read_all_items():
6363
items.append(item["human_readable_name"])
64-
except Exception as e:
64+
except Exception:
6565
reporter = ReporterSingleton.get_instance()
66-
reporter.on_error(f"Error getting all entity configurations: {str(e)}")
66+
reporter.on_error("Error getting all entity configurations")
6767
return EntityNameList(entity_configuration_name=items)
6868

6969

@@ -147,8 +147,8 @@ async def update_entity(request: EntityConfiguration):
147147
item=sanitized_config_name,
148148
partition_key=sanitized_config_name,
149149
)
150-
except Exception as e:
151-
reporter.on_error(f"Error getting entity type: {str(e)}")
150+
except Exception:
151+
reporter.on_error("Error getting entity type")
152152
reporter.on_error(
153153
f"Item with entity configuration name '{request.entity_configuration_name}' not found."
154154
)
@@ -181,8 +181,8 @@ async def update_entity(request: EntityConfiguration):
181181
for i in request.entity_examples
182182
]
183183
entity_container.replace_item(sanitized_config_name, existing_item)
184-
except Exception as e:
185-
reporter.on_error(f"Error updating entity type: {str(e)}")
184+
except Exception:
185+
reporter.on_error("Error updating entity type")
186186
return BaseResponse(status="Success.")
187187

188188

@@ -210,8 +210,8 @@ async def get_entity(entity_configuration_name: str):
210210
entity_types=existing_item["entity_types"],
211211
entity_examples=existing_item["entity_examples"],
212212
)
213-
except Exception as e:
214-
reporter.on_error(f"Error getting entity type: {str(e)}")
213+
except Exception:
214+
reporter.on_error("Error getting entity type")
215215
reporter.on_error(
216216
f"Item with entity configuration name '{entity_configuration_name}' not found."
217217
)
@@ -240,8 +240,8 @@ async def delete_entity(entity_configuration_name: str):
240240
partition_key=sanitized_entity_config_name,
241241
)
242242
return BaseResponse(status="Success")
243-
except Exception as e:
244-
reporter.on_error(f"Error deleting entity: {str(e)}")
243+
except Exception:
244+
reporter.on_error("Error deleting entity")
245245
reporter.on_error(
246246
f"Item with entity configuration name '{entity_configuration_name}' not found."
247247
)

backend/src/api/query.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@ async def global_query(request: GraphRequest):
131131
]
132132

133133
return GraphResponse(result=result.response, context_data=result.context_data)
134-
except Exception as e:
134+
except Exception:
135135
reporter = ReporterSingleton().get_instance()
136-
reporter.on_error(f"Could not perform global search. Exception: {str(e)}")
137-
raise HTTPException(status_code=500, detail=str(e))
136+
reporter.on_error("Could not perform global search.")
137+
raise HTTPException(status_code=500, detail=None)
138138

139139

140140
@query_route.post(

backend/src/api/source.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ async def get_report_info(index_name: str, report_id: str):
6262
)
6363
row = report_table[report_table.community == report_id]
6464
return ReportResponse(text=row["full_content"].values[0])
65-
except Exception as e:
65+
except Exception:
6666
reporter = ReporterSingleton().get_instance()
67-
reporter.on_error(f"Could not get report. Exception: {str(e)}")
67+
reporter.on_error("Could not get report.")
6868
raise HTTPException(
6969
status_code=500,
7070
detail=f"Error retrieving report '{report_id}' from index '{index_name}'.",
@@ -104,9 +104,9 @@ async def get_chunk_info(index_name: str, text_unit_id: str):
104104
return TextUnitResponse(
105105
text=row["chunk"].values[0], source_document=row["source_doc"].values[0]
106106
)
107-
except Exception as e:
107+
except Exception:
108108
reporter = ReporterSingleton().get_instance()
109-
reporter.on_error(f"Could not get text chunk. Exception: {str(e)}")
109+
reporter.on_error("Could not get text chunk.")
110110
raise HTTPException(
111111
status_code=500,
112112
detail=f"Error retrieving text chunk '{text_unit_id}' from index '{index_name}'.",
@@ -134,9 +134,9 @@ async def get_entity_info(index_name: str, entity_id: int):
134134
description=row["description"].values[0],
135135
text_units=row["text_unit_ids"].values[0].tolist(),
136136
)
137-
except Exception as e:
137+
except Exception:
138138
reporter = ReporterSingleton().get_instance()
139-
reporter.on_error(f"Could not get entity. Exception: {str(e)}")
139+
reporter.on_error("Could not get entity")
140140
raise HTTPException(
141141
status_code=500,
142142
detail=f"Error retrieving entity '{entity_id}' from index '{index_name}'.",
@@ -179,9 +179,9 @@ async def get_claim_info(index_name: str, claim_id: int):
179179
text_unit_id=row["text_unit_id"].values[0],
180180
document_ids=row["document_ids"].values[0].tolist(),
181181
)
182-
except Exception as e:
182+
except Exception:
183183
reporter = ReporterSingleton().get_instance()
184-
reporter.on_error(f"Could not get claim. Exception: {str(e)}")
184+
reporter.on_error("Could not get claim.")
185185
raise HTTPException(
186186
status_code=500,
187187
detail=f"Error retrieving claim '{claim_id}' from index '{index_name}'.",
@@ -225,9 +225,9 @@ async def get_relationship_info(index_name: str, relationship_id: int):
225225
x[0] for x in row["text_unit_ids"].to_list()
226226
], # extract text_unit_ids from a list of panda series
227227
)
228-
except Exception as e:
228+
except Exception:
229229
reporter = ReporterSingleton().get_instance()
230-
reporter.on_error(f"Could not get relationship. Exception: {str(e)}")
230+
reporter.on_error("Could not get relationship.")
231231
raise HTTPException(
232232
status_code=500,
233233
detail=f"Error retrieving relationship '{relationship_id}' from index '{index_name}'.",

backend/src/main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ async def catch_all_exceptions_middleware(request: Request, call_next):
3838
try:
3939
return await call_next(request)
4040
except Exception:
41-
print(traceback.format_exc())
4241
return Response("Unexpected internal server error", status_code=500)
4342

4443

0 commit comments

Comments
 (0)