Skip to content

Commit dc50cf2

Browse files
authored
Added error_message to detailed report
Signed-off-by: Praveen Kumar <praveen@zipstack.com>
1 parent fcb347c commit dc50cf2

File tree

1 file changed

+38
-25
lines changed

1 file changed

+38
-25
lines changed

main.py

+38-25
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def print_report():
262262
# Fetch required fields, including total_cost and total_tokens
263263
c.execute(
264264
"""
265-
SELECT file_name, execution_status, time_taken, total_embedding_cost, total_embedding_tokens, total_llm_cost, total_llm_tokens
265+
SELECT file_name, execution_status, time_taken, total_embedding_cost, total_embedding_tokens, total_llm_cost, total_llm_tokens, error_message
266266
FROM file_status
267267
"""
268268
)
@@ -274,36 +274,49 @@ def print_report():
274274
if report_data:
275275
# Tabulate the data with column headers
276276
headers = [
277-
textwrap.fill(header, width=20)
278-
for header in [
279-
"File Name",
280-
"Execution Status",
281-
"Time Elapsed (seconds)",
282-
"Total Embedding Cost",
283-
"Total Embedding Tokens",
284-
"Total LLM Cost",
285-
"Total LLM Tokens",
286-
]
277+
"File Name",
278+
"Execution Status",
279+
"Time Elapsed (seconds)",
280+
"Total Embedding Cost",
281+
"Total Embedding Tokens",
282+
"Total LLM Cost",
283+
"Total LLM Tokens",
284+
"Error Message"
287285
]
288-
286+
287+
column_widths = {
288+
"File Name": 30,
289+
"Execution Status": 20,
290+
"Time Elapsed (seconds)": 20,
291+
"Total Embedding Cost": 20,
292+
"Total Embedding Tokens": 20,
293+
"Total LLM Cost": 20,
294+
"Total LLM Tokens": 20,
295+
"Error Message": 30,
296+
}
289297

290298
formatted_data = []
291-
# Wrap text in each column to a specific width (e.g., 30 characters for file names and 20 for others) and return None if the value is NULL
299+
# Format and wrap each row's data to match column widths
292300
for row in report_data:
293-
formatted_row = [
294-
"None" if cell is None else
295-
textwrap.fill(str(cell), width=30) if isinstance(cell, str) else
296-
cell if idx == 2 else f"{cell:.8f}" if isinstance(cell, float) else cell
297-
for idx, cell in enumerate(row)
298-
]
299-
formatted_data.append(formatted_row)
300-
301+
formatted_row = []
302+
for idx, cell in enumerate(row):
303+
header = headers[idx]
304+
width = column_widths[header]
305+
cell_value = "None" if cell is None else str(cell)
306+
if header == "Error Message" and len(cell_value) > 50:
307+
# Truncate long error messages
308+
cell_value = textwrap.fill(cell_value[:100], width=width) + "..."
309+
else:
310+
cell_value = textwrap.fill(cell_value, width=width)
311+
formatted_row.append(cell_value)
312+
formatted_data.append(formatted_row)
313+
314+
# Print the table
301315
print(tabulate(formatted_data, headers=headers, tablefmt="pretty"))
302316
else:
303317
print("No records found in the database.")
304-
305-
# Suggest CSV report for error details
306-
print("\nNote: Use the `--export_csv` argument to generate a CSV report that includes error messages.")
318+
319+
print("\nNote: For more detailed error messages, use the CSV report argument.")
307320

308321
def export_report_to_csv(output_path):
309322
conn = sqlite3.connect(DB_NAME)
@@ -622,4 +635,4 @@ def main():
622635

623636

624637
if __name__ == "__main__":
625-
main()
638+
main()

0 commit comments

Comments
 (0)