Skip to content

[FEATURE] Non-zero exit code from stackql exec when a statement fails, messages on stdout #801

Open

Description

@jeffreyaven

Feature Description

stackql exec exits 0 whether or not the statement worked, and success messages go to stderr, so a script cannot tell success from failure without parsing text. Two changes would make exec usable from scripts, CI and wrappers:

  1. Exit non-zero when a statement fails (unknown provider, service or table, SQL error, HTTP error from the provider, failed REFRESH).
  2. Send informational messages (DDL Execution Completed, insert into table completed, github provider, version '...' successfully installed, refresh materialized view completed) to stdout, keeping stderr for errors.

A smaller related point: with --output json an empty result set prints null. [] would let consumers treat the output as an array without a special case.

Example(s)

All of these exit 0 with stackql v0.12.718:

exit=0  stdout=[]      stderr=[DDL Execution Completed]                <- CREATE TABLE t2 (a text)
exit=0  stdout=[]      stderr=[insert into table completed]            <- INSERT INTO t2 (a) VALUES ('x')
exit=0  stdout=[null]  stderr=[]                                       <- SELECT a FROM t2 WHERE a = 'none'
exit=0  stdout=[]      stderr=[could not locate table 'nope']          <- SELECT a FROM nope
exit=0  stdout=[]      stderr=[cannot resolve service with key = 'nope'] <- SELECT x FROM github.nope.nope
exit=0  stdout=[]      stderr=[http response status code: 401, ...]    <- REFRESH MATERIALIZED VIEW me (bad token)

The rule a wrapper has to use today is "stderr with nothing on stdout means failure", which is wrong for every DDL statement and for REGISTRY PULL, so those need a confirming read afterwards.

Possible Approaches or Libraries to Consider

Return an error from the exec command path when any statement in the input fails, and let cobra map it to exit code 1. Route non error messages through the normal output writer.

Additional context

Per repo HTTP failures inside a fan out (for example a 404 for one repo in a join over many repos) are arguably partial success and could keep exit 0 with the rows that did succeed, but the whole statement failing should not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions