Skip to content

Commit c1727c7

Browse files
committed
fix functino caller to catch exceptions
1 parent 7c39744 commit c1727c7

File tree

4 files changed

+39
-29
lines changed

4 files changed

+39
-29
lines changed

src/flowco/ui/page_files/base_page.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
from pprint import pformat
21
from flowco.dataflow.extended_type import schema_to_text
3-
from flowco.session.session import session
42
import uuid
53

64
from flowco.page.ama import AskMeAnything, VisibleMessage
7-
from flowco.session.session_file_system import fs_write
85
from flowco.ui import ui_help
96
from flowco.ui.authenticate import sign_out
107
import numpy as np
@@ -20,6 +17,7 @@
2017
from flowco.ui.ui_page import st_abstraction_level
2118
from flowco.ui.ui_util import (
2219
toggle,
20+
zip_bug,
2321
)
2422
import streamlit as st
2523

@@ -30,8 +28,7 @@
3028
from flowco.util.config import config
3129
from flowco.util.costs import inflight, total_cost
3230
from flowco.util.config import AbstractionLevel
33-
from flowco.util.files import create_zip_in_memory
34-
from flowco.util.output import Output, error, log, log_timestamp
31+
from flowco.util.output import error, log
3532

3633

3734
class FlowcoPage:
@@ -390,14 +387,6 @@ def bottom_bar(self):
390387
st.rerun()
391388

392389
def report_bug(self):
393-
ui_page = st.session_state.ui_page
394-
flowco_name = ui_page.page().file_name
395-
data_files = [
396-
file for file in ui_page.page().tables.all_files() if file.endswith(".csv")
397-
]
398-
time_stamp = log_timestamp()
399-
file_name = f"flowco-{time_stamp}.zip"
400-
401390
@st.dialog("Report Bug", width="small")
402391
def download_files():
403392

@@ -408,17 +397,7 @@ def download_files():
408397

409398
if text:
410399
with st.spinner("Creating ZIP file..."):
411-
zip_data = create_zip_in_memory(
412-
[flowco_name] + data_files,
413-
additional_entries={
414-
"description.txt": text,
415-
"logging.txt": session.get(
416-
"output", Output
417-
).get_full_output(),
418-
"session_state.json": pformat(dict(st.session_state)),
419-
},
420-
)
421-
fs_write(file_name, zip_data, "wb")
400+
file_name, zip_data = zip_bug(text)
422401

423402
st.write("Saved on server. Click below to download bug files locally.")
424403

src/flowco/ui/ui_main.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from flowco.ui.ui_init import st_init
77
from flowco.ui.ui_page import UIPage, set_ui_page
88
from flowco.ui.ui_st_pages import st_pages
9+
from flowco.ui.ui_util import zip_bug
910
from flowco.util.files import setup_flowco_files
1011
import streamlit as st
1112

@@ -63,6 +64,10 @@ def init_service():
6364
print(traceback.format_exc())
6465
st.error(e)
6566
st.exception(e)
67+
try:
68+
zip_bug(f"""{str(e)}\n{traceback.format_exc()}""")
69+
except Exception as e2:
70+
print("Error zipping bug report", e2)
6671
print("Restarting Session Components...")
6772
if os.path.isdir(st.session_state.args.page):
6873
page_path = os.path.abspath(st.session_state.args.page)

src/flowco/ui/ui_util.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
import functools
2-
import pandas as pd
1+
from pprint import pformat
32
import streamlit as st
43

5-
from typing import Any, Callable, Iterator, List
4+
from typing import Callable, Iterator, List
65
import uuid
76

87
from streamlit_extras.stylable_container import stylable_container
98

10-
from flowco.dataflow.dfg import Node
119
from flowco.dataflow.phase import Phase
10+
from flowco.session.session import session
11+
from flowco.session.session_file_system import fs_write
1212
from flowco.util.config import AbstractionLevel
13+
from flowco.util.files import create_zip_in_memory
14+
from flowco.util.output import Output, log_timestamp
1315

1416

1517
def editable_list(
@@ -173,3 +175,23 @@ def phase_for_last_shown_part() -> Phase:
173175
return Phase.requirements
174176
else:
175177
return Phase.clean
178+
179+
180+
def zip_bug(description):
181+
ui_page = st.session_state.ui_page
182+
flowco_name = ui_page.page().file_name
183+
data_files = [
184+
file for file in ui_page.page().tables.all_files() if file.endswith(".csv")
185+
]
186+
time_stamp = log_timestamp()
187+
file_name = f"flowco-{time_stamp}.zip"
188+
zip_data = create_zip_in_memory(
189+
[flowco_name] + data_files,
190+
additional_entries={
191+
"description.txt": description,
192+
"logging.txt": session.get("output", Output).get_full_output(),
193+
"session_state.json": pformat(dict(st.session_state)),
194+
},
195+
)
196+
fs_write(file_name, zip_data, "wb")
197+
return file_name, zip_data

src/llm/assistant.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,11 @@ def make_call(
241241

242242
self.logger.log(f"Tool call: {function_name}")
243243

244-
result = function_def.function(**args)
244+
try:
245+
result = function_def.function(**args)
246+
except Exception as e:
247+
self.logger.error(f"Error in tool call {function_name}: {e}")
248+
result = ToolCallResult(user_message=f"An error occurred: {e}")
245249

246250
self.logger.log(f"Tool result: {result}")
247251

0 commit comments

Comments
 (0)