Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't hide errors in imports from the user #24

Closed
simonw opened this issue Jun 9, 2022 · 3 comments
Closed

Don't hide errors in imports from the user #24

simonw opened this issue Jun 9, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@simonw
Copy link
Owner

simonw commented Jun 9, 2022

Related issue: if this happens an error message is shown in the logs but not to the user.

Originally posted by @simonw in #23 (comment)

@simonw simonw added the enhancement New feature or request label Jun 9, 2022
@simonw
Copy link
Owner Author

simonw commented Jun 9, 2022

image

@simonw
Copy link
Owner Author

simonw commented Jun 9, 2022

The problem is that any exceptions occur inside this block, which is run by db.execute_write_fn(insert_docs, block=False) and hence can't interrupt a current page request.

def insert_docs(conn):
database = sqlite_utils.Database(conn)
# TODO: Support other encodings:
reader = csv_std.reader(codecs.iterdecode(csv.file, "utf-8"))
headers = next(reader)
docs = (dict(zip(headers, row)) for row in reader)
i = 0
def docs_with_progress():
nonlocal i
for doc in docs:
i += 1
yield doc
if i % 10 == 0:
database["_csv_progress_"].update(
task_id,
{
"rows_done": i,
"bytes_done": csv.file.tell(),
},
)
database[filename].insert_all(docs_with_progress(), alter=True, batch_size=100)
database["_csv_progress_"].update(
task_id,
{
"rows_done": i,
"bytes_done": total_size,
"completed": str(datetime.datetime.utcnow()),
},
)
return database[filename].count

Instead, it should write something to the _csv_progress_ table such that the polling JavaScript can detect that an error has occurred.

@simonw
Copy link
Owner Author

simonw commented Jun 9, 2022

Now this happens, and after you click OK the page reloads.

CleanShot 2022-06-09 at 12 19 55@2x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant