Skip to content

fix(aitools): non-zero exit when discover-schema has any failed table#5116

Merged
jamesbroadhead merged 2 commits into
mainfrom
jb/aitools-discover-schema-exit-code
May 18, 2026
Merged

fix(aitools): non-zero exit when discover-schema has any failed table#5116
jamesbroadhead merged 2 commits into
mainfrom
jb/aitools-discover-schema-exit-code

Conversation

@jamesbroadhead
Copy link
Copy Markdown
Contributor

Summary

databricks aitools tools discover-schema TABLE... rendered per-table failures into stdout but always returned nil from RunE. Even when every table failed, the process exited 0, so scripts and CI couldn't detect failure without grepping output for "Error discovering " — exactly the kind of err.Error() string-matching the repo's style guide forbids.

Extract the loop into runDiscoverSchemas which returns (output, anyFailed). RunE prints the output and returns root.ErrAlreadyPrinted when anyFailed is true so cobra produces a non-zero exit without re-printing the per-table errors. Behavior preserved: one bad table still doesn't abort the others.

Spotted via multi-model code review on #4917 (GPT 5.4). Pre-existing in #5097, not introduced by #4917 — sending as a separate small fix per the "keep PRs focused" rule.

Test plan

  • go test ./experimental/aitools/cmd/ (new tests: TestRunDiscoverSchemasFlagsTableFailureForExitCode, TestRunDiscoverSchemasAllSucceedReturnsFalse).
  • Manual: databricks aitools tools discover-schema doesnt.exist.foo; echo $? should now print 1.
  • Manual: a successful run still prints 0.

This pull request and its description were written by Isaac.

Per-table failures were rendered into stdout but the command still
returned nil from RunE, so the process exited 0 even when every
table failed. Scripts and CI couldn't detect failure without parsing
output for "Error discovering ...", which is exactly the kind of
err.Error() string-matching the repo's style guide forbids.

Extract the loop into runDiscoverSchemas which returns (output, anyFailed).
RunE prints the output and returns root.ErrAlreadyPrinted when anyFailed
is true so cobra produces a non-zero exit without re-printing the errors.

Behavior preserved: per-table failures still don't abort the others.

Co-authored-by: Isaac
Copy link
Copy Markdown
Member

@simonfaltum simonfaltum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. This matches the nearby aitools pattern of printing the detailed failure once, then returning root.ErrAlreadyPrinted so scripts get a non-zero exit without an extra Cobra error line.

One scope question: should sample-data/null-count probe failures inside a successfully described table also make the command exit non-zero? Today discoverTable renders those as SAMPLE DATA: Error - ... / NULL COUNTS: Error - ... but still returns nil, so this PR only covers full table-discovery failures. That may be intentional, but I wanted to call it out explicitly.

@jamesbroadhead jamesbroadhead added this pull request to the merge queue May 18, 2026
Merged via the queue into main with commit 69f8d88 May 18, 2026
21 checks passed
@jamesbroadhead jamesbroadhead deleted the jb/aitools-discover-schema-exit-code branch May 18, 2026 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants