Skip to content

Commit

Permalink
redirect error messages to STDERR
Browse files Browse the repository at this point in the history
According to Shell Style Guide,
all error messages should go to stderr (see [here](https://google.github.io/styleguide/shellguide.html#stdout-vs-stderr))
  • Loading branch information
giovanni-guidini committed Dec 18, 2023
1 parent 8828a9b commit d4899ff
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/codecov_ats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ say() {
echo -e "$1"
}

error() {
echo -e "${r}$*${e}" >&2

Check warning on line 17 in src/codecov_ats.sh

View check run for this annotation

Codecov / codecov/patch

src/codecov_ats.sh#L17

Added line #L17 was not covered by tests
}

# Set up token variables
if [[ -n $INPUTS_CODECOV_TOKEN ]]; then
CODECOV_TOKEN=$INPUTS_CODECOV_TOKEN
fi
if [[ -z $CODECOV_TOKEN ]]; then
say "${r}Token not provided or could not be found in environment. Exiting${x}"
error "Token not provided or could not be found in environment. Exiting"

Check warning on line 25 in src/codecov_ats.sh

View check run for this annotation

Codecov / codecov/patch

src/codecov_ats.sh#L25

Added line #L25 was not covered by tests
exit 1
else
say "$b==>$x Token of length ${#CODECOV_TOKEN} detected"
Expand All @@ -29,7 +32,7 @@ if [[ -n $INPUTS_CODECOV_STATIC_TOKEN ]]; then
CODECOV_STATIC_TOKEN=$INPUTS_CODECOV_STATIC_TOKEN
fi
if [[ -z $CODECOV_STATIC_TOKEN ]]; then
say "${r}Static token not provided or could not be found in environment. Exiting${x}"
error "Static token not provided or could not be found in environment. Exiting"

Check warning on line 35 in src/codecov_ats.sh

View check run for this annotation

Codecov / codecov/patch

src/codecov_ats.sh#L35

Added line #L35 was not covered by tests
exit 1
else
say "$b==>$x Static token of length ${#CODECOV_STATIC_TOKEN} detected"
Expand Down Expand Up @@ -73,22 +76,22 @@ label_analysis_args=""
if $(codecovcli ${codecovcli_args}create-commit ${create_commit_args}-t ${CODECOV_TOKEN}); then
say "${g}Codecov: Successfully created commit record$x"
else
say "${r}Codecov: Failed to properly create commit$x"
error "Codecov: Failed to properly create commit"

Check warning on line 79 in src/codecov_ats.sh

View check run for this annotation

Codecov / codecov/patch

src/codecov_ats.sh#L79

Added line #L79 was not covered by tests
exit 1
fi

if $(codecovcli ${codecovcli_args}create-report ${create_report_args}-t ${CODECOV_TOKEN}); then
say "${g}Codecov: Successfully created report record$x"
else
say "${r}Codecov: Failed to properly create report$x"
error "Codecov: Failed to properly create report"

Check warning on line 86 in src/codecov_ats.sh

View check run for this annotation

Codecov / codecov/patch

src/codecov_ats.sh#L86

Added line #L86 was not covered by tests
exit 1
fi

codecovcli ${codecovcli_args}static-analysis ${static_analysis_args}--token ${CODECOV_STATIC_TOKEN}
if [[ $? == 0 ]]; then
say "${g}Codecov: Successfully ran static analysis$x"
else
say "${r}Codecov: Failed to run static analysis$x"
error "Codecov: Failed to run static analysis"

Check warning on line 94 in src/codecov_ats.sh

View check run for this annotation

Codecov / codecov/patch

src/codecov_ats.sh#L94

Added line #L94 was not covered by tests
exit 1
fi

Expand All @@ -110,7 +113,7 @@ do
done

if [[ -z $response && -n $INPUTS_OVERRIDE_BASE_COMMIT ]]; then
say "${r}Codecov: Failed to run label analysis. Please select a different base commit.$x"
error "Codecov: Failed to run label analysis. Please select a different base commit."

Check warning on line 116 in src/codecov_ats.sh

View check run for this annotation

Codecov / codecov/patch

src/codecov_ats.sh#L116

Added line #L116 was not covered by tests
exit 1
fi

Expand Down

0 comments on commit d4899ff

Please sign in to comment.