Repository navigation
Commit 8522299
authored
fix(cli): keep db export stdout clean by routing the banner to stderr (#253)
## What
`runDbCommand` now detects the `export` action without `--output` and
sends the intro banner (and its leading blank line) to stderr for that
mode. `runExport` sends its three error messages to stderr as well. The
SQL dump still goes to stdout via `process.stdout.write`. Every other db
subcommand is unchanged.
## Why
`void db export` without `--output` streams raw SQL to stdout so it can
be piped or redirected, for example `void db export > dump.sql` or `void
db export | sqlite3 new.db`. But the command printed the clack intro
banner first, and clack writes to stdout by default, so the dump began
with a blank line and a `void db` banner before the first `CREATE
TABLE`. Feeding that file into sqlite3 fails with a parse error on the
banner line and the restore never runs. Errors raised during a piped
export were also written into the dump and hidden from the user, so
routing them to stderr both keeps the dump clean and makes the error
visible on the terminal.
## Safety
The change is scoped to the export to stdout path. Other db subcommands
keep their banner and status on stdout exactly as before, and `void db
export --output file.sql` is unaffected because that path does not
stream to stdout. The banner still appears on the terminal in every
case, since stderr is not redirected by a stdout pipe.
## Verification
A new regression test at
`packages/void/test/unit/db-export-stdout.test.ts` drives `runDbCommand`
with the real clack library and a mocked SQLite layer, then asserts that
stdout is byte for byte the SQL dump and that the banner lands on
stderr. It fails on the old code, where stdout starts with the banner,
and passes on the fix. The `db-migrate`, `db-seed`, and `db-commands`
suites that assert exact clack arguments stay green (33 tests total),
and the void package typechecks with tsgo and passes oxlint.1 parent ab73bf7 commit 8522299
2 files changed
Lines changed: 95 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
139 | 139 | | |
140 | 140 | | |
141 | 141 | | |
142 | | - | |
143 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
144 | 150 | | |
145 | 151 | | |
146 | 152 | | |
| |||
1374 | 1380 | | |
1375 | 1381 | | |
1376 | 1382 | | |
| 1383 | + | |
1377 | 1384 | | |
1378 | 1385 | | |
1379 | 1386 | | |
| |||
1384 | 1391 | | |
1385 | 1392 | | |
1386 | 1393 | | |
1387 | | - | |
| 1394 | + | |
1388 | 1395 | | |
1389 | 1396 | | |
1390 | 1397 | | |
| |||
1452 | 1459 | | |
1453 | 1460 | | |
1454 | 1461 | | |
1455 | | - | |
| 1462 | + | |
1456 | 1463 | | |
1457 | 1464 | | |
1458 | 1465 | | |
| |||
1464 | 1471 | | |
1465 | 1472 | | |
1466 | 1473 | | |
1467 | | - | |
| 1474 | + | |
1468 | 1475 | | |
1469 | 1476 | | |
1470 | 1477 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
0 commit comments