cli: Add program error diagnostics command#6510
Conversation
| output, | ||
| "SQL compiler exit code: 1\n\ | ||
| warning: PRIMARY KEY cannot be nullable: PRIMARY KEY column 'C' has type INTEGER, which is nullable (line 2, column 4)\n\ | ||
| 2| c INT PRIMARY KEY\n\ |
There was a problem hiding this comment.
I wonder whether we need a "verbosity" argument which would enable the snippet being shown
There was a problem hiding this comment.
fixed the ci fmt issue in e0a907d. on the snippet bit, i'd keep snippets in text output for now. personally, i think hiding them would make this cmd less useful, since the whole point is to avoid digging through the full pipeline json just to understand a compiler error. json still gives the raw payload for ppl/scripts that want to handle it differently. if output ends up too noisy, i'd rather add a specific --no-snippets or --summary flag later than introduce a new verbosity arg just for this cmd.
There was a problem hiding this comment.
"Verbosity" would be a new fda flag, which applies to all other fda commands. But that's a separate issue we should file and solve.
|
Our pre-merge checks don't check much, but they didn't like the formatting of your Rust |
gz
left a comment
There was a problem hiding this comment.
it would be good to exercise this as part of test.bash integration test as well
mythical-fred
left a comment
There was a problem hiding this comment.
Approve. Small, focused, well-tested addition that closes a real gap — fda logs only surfaces runtime output, so users currently have to spelunk through the pipeline JSON for SQL/Rust diagnostics. Splitting this into a dedicated program errors subcommand is the right call.
format_program_errors is straightforward and the four unit tests (empty, SQL with snippet, Rust stdout+stderr, system error) cover every branch including the warning vs. error severity flip and the trailing-newline normalisation. Good shape: pure function over &ProgramError, easy to extend if more fields land.
Two non-blocking notes:
-
crates/fda/src/main.rs—Errorsarm: ifprogram_errorisNonethe command exits 1 with "did not include program errors". That's the safe choice for a pre-UPGRADE_NOTICEserver, but for a current server a fully-compiled pipeline can legitimately returnprogram_error: None(no diagnostics to report). Consider treatingNonethe same asformat_program_errorsdoes for an empty struct ("No compilation errors or warnings.\n", exit 0). Otherwise scriptingfda program errors X && deploywill spuriously fail. -
format_program_errors:severityis a&strchosen fromif message.warning { "warning" } else { "error" }. Worth a quick sanity check thatsql.exit_code == 0and all messages flaggedwarning: trueis a valid state — if so, the header "SQL compiler exit code: 0" followed by a "warning:" line reads cleanly, which is what you want.
Nit: the snippet branch prints snippet directly with push_str; if a snippet ever contains a stray { it's still safe because you're not running it through format!. Good.
added this in 31bf0f6. test.bash now creates a bad sql pipeline, waits for sql_error, then exercises both text and json output from fda program errors. |
mythical-fred
left a comment
There was a problem hiding this comment.
Re-APPROVE on f586b88 → 31bf0f6.
Apply formatter to program error snippets collapses the nested if let Some(snippet) = &message.snippet { if !snippet.is_empty() { … } } into a let-chain — pure 2024-edition formatting cleanup, semantics identical.
Test program error diagnostics in fda script adds the integration coverage that was missing from the earlier rounds: creates pbad with an intentionally-invalid SELECT invalid, polls fda program status pbad for up to 60s waiting for the SqlError to surface, then exercises both human and JSON output paths of fda program errors. The 60-second cap is consistent with the rest of the script's pattern, the JSON assertion uses jq -e so a zero-length messages array exits non-zero (test fails loudly), and the cleanup path adds fda delete --force pbad to the top-of-script cleanup block as well — no leak risk on re-run. Nice.
No blockers; APPROVE stands.
mythical-fred
left a comment
There was a problem hiding this comment.
Re-APPROVE on 31bf0f6a4e. Two new commits since prior approval at f586b882e0:
e0a907df9b— formatter pass folding the nestedif let Some(snippet) = ... { if !snippet.is_empty() { ... } }into a let-chain. Matches the rustfmt complaint Mihai flagged.31bf0f6a4e— adds an integration leg totest.bashper Mihai's ask: createspbadwithSELECT invalid, polls up to 60s forSqlError, then exercises both the text formatter (fda program errors pbad | grep -i "error:") and the JSON path (fda --format json program errors pbad | jq -e '.sql_compilation.messages | length > 0'). Cleanup at the top + bottom oftest.bashproperly removespbadandbad-program.sqlso reruns stay idempotent.
Two small nits, non-blocking:
- The poll uses
grep -q "SqlError"againstfda program status, then immediately re-runsfda program status pbad | grep "SqlError"as an assertion. The second invocation is functionally the same as breaking out of the loop having seen it once; you can drop it. As written, if the 60s window expires and status flips to RustError between the two reads, the loop exits via theforend (nobreak) and the assert fails for a different reason. Cleaner: add an explicitelse echo "timeout"; exit 1after the loop body. jq -e '.sql_compilation.messages | length > 0'is a good shape check but doesn't pin thaterror_type/messagestrings are non-empty. A follow-up could assert(.sql_compilation.messages[0].message | length) > 0to catch a regression where the body is dropped but the array remains.
Nice follow-through on the maintainer feedback. Good to merge once CI is green.
fixes #5738
imo this is the smallest useful fix here. fda logs only reads runtime logs, so users had to dig through the full pipeline json to find compilation diagnostics.
adds fda program errors for program_error, with text output for sql messages, rust compiler output, and system errors. --format json returns the raw error payload. lgtm to keep this separate from logs for now since idk if we want to mix runtime logs and compiler output in one command. i also added parser and formatter tests.