Skip to content

Commit 5de3e87

Browse files
authored
Merge pull request #22 from codeasier/fix/narrow-exceptions
fix: narrow broad exception handling and enforce zip strictness
2 parents 4d148fe + 83c2b67 commit 5de3e87

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

‎src/pt_snap_cli/cli.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from pt_snap_cli import __version__
99
from pt_snap_cli.config import ENV_DB_PATH, Config, ContextResolutionError
10-
from pt_snap_cli.context import Context
10+
from pt_snap_cli.context import Context, DatabaseNotFoundError, SchemaVersionError
1111

1212
app = typer.Typer(
1313
name="pt-snap",
@@ -101,9 +101,12 @@ def use_database(
101101
typer.echo(f"Available devices: {', '.join(map(str, devices))}")
102102
else:
103103
typer.echo("No devices found in database.")
104-
except Exception as e:
104+
except (DatabaseNotFoundError, SchemaVersionError) as e:
105105
typer.secho(f"Error: {e}", fg=typer.colors.RED)
106106
raise typer.Exit(1) from None
107+
except Exception as e:
108+
typer.secho(f"Error: unexpected failure opening database: {e}", fg=typer.colors.RED)
109+
raise typer.Exit(1) from None
107110

108111

109112
@app.command("query")

‎src/pt_snap_cli/query/executor.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def execute(
120120
else:
121121
cursor.execute(sql)
122122
columns = [desc[0] for desc in cursor.description]
123-
return [dict(zip(columns, row, strict=False)) for row in cursor.fetchall()]
123+
return [dict(zip(columns, row, strict=True)) for row in cursor.fetchall()]
124124
except Exception as e:
125125
raise QueryExecutionError(f"Query execution failed: {e}") from e
126126

0 commit comments

Comments
 (0)