diff --git a/bin/miaou-bash b/bin/miaou-bash index b6ae4d3..cc574e3 100755 --- a/bin/miaou-bash +++ b/bin/miaou-bash @@ -571,9 +571,13 @@ function on_exit { if ! is_true $CHILD_PROCESS; then 2>&3 >&3 dump_stderr if [[ -v failure_type && $failure_code -gt 0 ]]; then - 2>&3 >&4 dump_failure - if [[ -v error_source ]]; then - 2>&3 >&4 dump_stacktrace + if [[ $failure_type == 'UNKNOWN ERROR' && $failure_payload == "source \"\$SCRIPT\"" ]]; then + miaou_debug "" + else + 2>&3 >&4 dump_failure + if [[ -v error_source ]]; then + 2>&3 >&4 dump_stacktrace + fi fi fi elif [[ -v failure_type ]]; then diff --git a/doc/bash_tips.md b/doc/bash_tips.md index 9aae9ea..6a1f84f 100644 --- a/doc/bash_tips.md +++ b/doc/bash_tips.md @@ -35,4 +35,29 @@ count=0 ```bash count=0 count=$((count+1)) -` +``` + +## properly grab $? + +> prefer plain `command` rather than `! command` +> otherwise you will miss out the exit code + +### wrong if + +```bash + if ! command; then + local code=$? + >&2 echo $code # => 0 + fi +``` + +### right if + +```bash + if command; then + : # useful for preserving $? + else + local code=$? + >&2 echo $code + fi +``` diff --git a/doc/index.md b/doc/index.md index 5d0ab1b..d4ac7cd 100644 --- a/doc/index.md +++ b/doc/index.md @@ -32,6 +32,9 @@ echo 'echo PIPE2' | miaou-bash ## TODO -* [ ] prompt git shows version with `+` when there is more than one commit over current version. ie: v0.0.0 + 2 commits more should display v-1.0.0+ -* [ ] semver_git_tag should append `RELEASE_NOTES.md` from this TODO markdown file, providing that NEW NOTE section below contains appropriate items to fulfill the current release note - * [ ] git log ..HEAD --oneline +* [ ] prompt should show up version with `+` when there is more than one commit, + not yet versioned. ie: v0.0.0 + 2 commits more should display v0.0.0+ +* [ ] semver_git_tag should append `RELEASE_NOTES.md` from this TODO markdown file, + providing that NEW NOTE section below contains appropriate items + to fulfill the current release note +* [ ] git log ..HEAD --oneline diff --git a/test/miaou-bash.test.bash b/test/miaou-bash.test.bash index 23ac96b..98fc732 100755 --- a/test/miaou-bash.test.bash +++ b/test/miaou-bash.test.bash @@ -172,7 +172,9 @@ time { fail_stderr_count unbound_variable 1 fail_stderr_count child_error 4 + fail_miaou_count command_error_multiline 7 + fail_miaou_count unknown 1 fail_stderr_grep two_options 'ERROR: too many args 2, either single option or SCRIPT + args accepted!' fail_stderr_grep script_not_found "ERROR: script 'doesnt_exist' not found!" diff --git a/test/stub/scenario.bash b/test/stub/scenario.bash index 7227c24..1d9ded3 100755 --- a/test/stub/scenario.bash +++ b/test/stub/scenario.bash @@ -12,6 +12,15 @@ function do_subshell_false { result=$(false) } +function do_unknown { + source /dev/stdin <&2 echo weird +builtin exit 2 +echo END +EOF +} + function do_heredoc { # miaou-bash <