Clean CLI errors for InvalidColumns from insert --pk and extract

sqlite-utils insert db t - --pk badcol and sqlite-utils extract db t
nosuchcol dumped raw InvalidColumns tracebacks - the insert error
handling caught NoTable and OperationalError but not the InvalidColumns
introduced for #732, and the extract command had no handling at all
(including for NoTable when pointed at a view). Both now exit with
click-style Error: messages.

Refs https://github.com/simonw/sqlite-utils/issues/769#issuecomment-4900034150

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Simon Willison 2026-07-06 21:57:14 -07:00
commit 548a886ca1
4 changed files with 41 additions and 2 deletions

View file

@ -13,6 +13,7 @@ from sqlite_utils.db import (
BadMultiValues,
DEFAULT,
DescIndex,
InvalidColumns,
NoTable,
NoView,
quote_identifier,
@ -1172,7 +1173,7 @@ def insert_upsert_implementation(
db.table(table).insert_all(
docs, pk=pk, batch_size=batch_size, alter=alter, **extra_kwargs
)
except NoTable as e:
except (NoTable, InvalidColumns) as e:
raise click.ClickException(str(e))
except Exception as e:
if (
@ -2734,7 +2735,10 @@ def extract(
fk_column=fk_column,
rename=dict(rename),
)
db.table(table).extract(**kwargs)
try:
db.table(table).extract(**kwargs)
except (NoTable, InvalidColumns) as e:
raise click.ClickException(str(e))
@cli.command(name="insert-files")