I write simple bash script and run it:
#!/bin/bash
set -e
bq load --replace ...
and I get this error:
ERROR: permission denied for table message
WRITING LINES: 0
As we can see, we got an obvious error related to access. Why did the script end with 0 code?
Really when using gcloud or bq (and other google-family cli utils) need write catch errors in bash?
This method works and successfully “breaks” the execution on error:
#!/bin/bash
set -e
function error() {
exitcode=$1
shift
echo "ERROR: exited with level $exitcode, error was '$@'" >&2
kill -s TERM $TOP_PID
}
bq load --replace ...
responseCode=$?
if [[ $responseCode -eq 1 ]]; then
error 1
fi
This important for me, I run scripts in Kubernetes (cronjob). Thanks