Skip to content

Commit

Permalink
wrap csv data fetch/parse with try/except
Browse files Browse the repository at this point in the history
  • Loading branch information
drewvolz authored Jan 13, 2025
1 parent 8ba863d commit c3be31c
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions webworker.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,20 @@ async function startDatasette(settings) {
table_names.add(bit)
if source_type == "csv":
tracker = TypeTracker()
response = await pyfetch(url)
with open("csv.csv", "wb") as fp:
fp.write(await response.bytes())
db[bit].insert_all(
tracker.wrap(rows_from_file(open("csv.csv", "rb"), Format.CSV)[0]),
alter=True
)
db[bit].transform(
types=tracker.types
)
try:
tracker = TypeTracker()
response = await pyfetch(url)
with open("csv.csv", "wb") as fp:
fp.write(await response.bytes())
db[bit].insert_all(
tracker.wrap(rows_from_file(open("csv.csv", "rb"), Format.CSV)[0]),
alter=True
)
db[bit].transform(
types=tracker.types
)
except Exception as error:
print(f"Failed to fetch or process CSV from {url}: {error}")
elif source_type == "json":
pk = None
response = await pyfetch(url)
Expand Down

0 comments on commit c3be31c

Please sign in to comment.