diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-12 08:42:36 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-12 08:42:36 +0300 |
| commit | 675d450919c63ec9d9955e8ae6a734d8086d96fd (patch) | |
| tree | 0579a8185ed473ce06ec33788e4bdf35a43f22de | |
| parent | ac6d1ad45c6a286a7b31090649d232bb5ee7d8bc (diff) | |
Propagate dispatcher validation failures for bm0
| -rwxr-xr-x | bin/shuriken | 93 | ||||
| -rw-r--r-- | src/lib/action.source.sh | 82 | ||||
| -rwxr-xr-x | src/shuriken.sh | 11 | ||||
| -rwxr-xr-x | tests/cli.sh | 68 |
4 files changed, 254 insertions, 0 deletions
diff --git a/bin/shuriken b/bin/shuriken index d9fd925..7ed6069 100755 --- a/bin/shuriken +++ b/bin/shuriken @@ -3079,6 +3079,7 @@ run_simple_action() { load_configured_action() { local -r rc_file="$1"; shift + local -i status=0 if [ ! -f "$rc_file" ]; then missing_config "$rc_file" @@ -3086,9 +3087,29 @@ load_configured_action() { # shellcheck source=/dev/null source "$rc_file" + status=$? + if (( status != 0 )); then + return "$status" + fi + apply_config_defaults + status=$? + if (( status != 0 )); then + return "$status" + fi + apply_template_dir_default + status=$? + if (( status != 0 )); then + return "$status" + fi + apply_cli_overrides + status=$? + if (( status != 0 )); then + return "$status" + fi + SHURIKEN_CONFIG_SOURCE="$rc_file" export SHURIKEN_CONFIG_SOURCE } @@ -3115,6 +3136,7 @@ log_configured_action() { run_configured_action() { local rc_file + local -i status=0 if [[ "$SHURIKEN_FORCE_GENERATE" = yes \ && "$SHURIKEN_CLI_ACTION" != --generate ]]; then @@ -3124,6 +3146,11 @@ run_configured_action() { rc_file="$(resolve_config_file "$SHURIKEN_CLI_CONFIG_FILE")" load_configured_action "$rc_file" + status=$? + if (( status != 0 )); then + return "$status" + fi + log_configured_action "$rc_file" case "$SHURIKEN_CLI_ACTION" in @@ -3137,34 +3164,89 @@ run_configured_action() { ;; --generate) validate_generation_config + status=$? + if (( status != 0 )); then + return "$status" + fi + generate_staged + status=$? + if (( status != 0 )); then + return "$status" + fi ;; --refresh-splash) validate_refresh_splash_config + status=$? + if (( status != 0 )); then + return "$status" + fi + refresh_splash + status=$? + if (( status != 0 )); then + return "$status" + fi ;; --sync) validate_sync_config + status=$? + if (( status != 0 )); then + return "$status" + fi + sync_dist + status=$? + if (( status != 0 )); then + return "$status" + fi ;; --dry-run) validate_generation_config no + status=$? + if (( status != 0 )); then + return "$status" + fi + dry_run + status=$? + if (( status != 0 )); then + return "$status" + fi ;; --print-config) validate_print_config + status=$? + if (( status != 0 )); then + return "$status" + fi + print_config + status=$? + if (( status != 0 )); then + return "$status" + fi ;; esac } run_action() { + local -i status=0 + case "$SHURIKEN_CLI_ACTION" in --version|--init) run_simple_action + status=$? + if (( status != 0 )); then + return "$status" + fi ;; --clean|--generate|--refresh-splash|--sync|--dry-run|--print-config) run_configured_action + status=$? + if (( status != 0 )); then + return "$status" + fi ;; *) usage @@ -3176,6 +3258,8 @@ run_action() { # SHURIKEN_LIB_SOURCES_END main() { + local -i status=0 + SHURIKEN_CLI_ACTION='' SHURIKEN_CLI_CONFIG_FILE='' SHURIKEN_CLI_HAS_CONFIG_OVERRIDES='no' @@ -3188,7 +3272,16 @@ main() { fi parse_cli_arguments "$@" + status=$? + if (( status != 0 )); then + return "$status" + fi + run_action + status=$? + if (( status != 0 )); then + return "$status" + fi } main "$@" diff --git a/src/lib/action.source.sh b/src/lib/action.source.sh index f1103a6..165cb2b 100644 --- a/src/lib/action.source.sh +++ b/src/lib/action.source.sh @@ -25,6 +25,7 @@ run_simple_action() { load_configured_action() { local -r rc_file="$1"; shift + local -i status=0 if [ ! -f "$rc_file" ]; then missing_config "$rc_file" @@ -32,9 +33,29 @@ load_configured_action() { # shellcheck source=/dev/null source "$rc_file" + status=$? + if (( status != 0 )); then + return "$status" + fi + apply_config_defaults + status=$? + if (( status != 0 )); then + return "$status" + fi + apply_template_dir_default + status=$? + if (( status != 0 )); then + return "$status" + fi + apply_cli_overrides + status=$? + if (( status != 0 )); then + return "$status" + fi + SHURIKEN_CONFIG_SOURCE="$rc_file" export SHURIKEN_CONFIG_SOURCE } @@ -61,6 +82,7 @@ log_configured_action() { run_configured_action() { local rc_file + local -i status=0 if [[ "$SHURIKEN_FORCE_GENERATE" = yes \ && "$SHURIKEN_CLI_ACTION" != --generate ]]; then @@ -70,6 +92,11 @@ run_configured_action() { rc_file="$(resolve_config_file "$SHURIKEN_CLI_CONFIG_FILE")" load_configured_action "$rc_file" + status=$? + if (( status != 0 )); then + return "$status" + fi + log_configured_action "$rc_file" case "$SHURIKEN_CLI_ACTION" in @@ -83,34 +110,89 @@ run_configured_action() { ;; --generate) validate_generation_config + status=$? + if (( status != 0 )); then + return "$status" + fi + generate_staged + status=$? + if (( status != 0 )); then + return "$status" + fi ;; --refresh-splash) validate_refresh_splash_config + status=$? + if (( status != 0 )); then + return "$status" + fi + refresh_splash + status=$? + if (( status != 0 )); then + return "$status" + fi ;; --sync) validate_sync_config + status=$? + if (( status != 0 )); then + return "$status" + fi + sync_dist + status=$? + if (( status != 0 )); then + return "$status" + fi ;; --dry-run) validate_generation_config no + status=$? + if (( status != 0 )); then + return "$status" + fi + dry_run + status=$? + if (( status != 0 )); then + return "$status" + fi ;; --print-config) validate_print_config + status=$? + if (( status != 0 )); then + return "$status" + fi + print_config + status=$? + if (( status != 0 )); then + return "$status" + fi ;; esac } run_action() { + local -i status=0 + case "$SHURIKEN_CLI_ACTION" in --version|--init) run_simple_action + status=$? + if (( status != 0 )); then + return "$status" + fi ;; --clean|--generate|--refresh-splash|--sync|--dry-run|--print-config) run_configured_action + status=$? + if (( status != 0 )); then + return "$status" + fi ;; *) usage diff --git a/src/shuriken.sh b/src/shuriken.sh index a3d6f1f..901b558 100755 --- a/src/shuriken.sh +++ b/src/shuriken.sh @@ -101,6 +101,8 @@ source "$SHURIKEN_SOURCE_DIR/lib/action.source.sh" # SHURIKEN_LIB_SOURCES_END main() { + local -i status=0 + SHURIKEN_CLI_ACTION='' SHURIKEN_CLI_CONFIG_FILE='' SHURIKEN_CLI_HAS_CONFIG_OVERRIDES='no' @@ -113,7 +115,16 @@ main() { fi parse_cli_arguments "$@" + status=$? + if (( status != 0 )); then + return "$status" + fi + run_action + status=$? + if (( status != 0 )); then + return "$status" + fi } main "$@" diff --git a/tests/cli.sh b/tests/cli.sh index 7f70a6d..89947e0 100755 --- a/tests/cli.sh +++ b/tests/cli.sh @@ -2010,6 +2010,71 @@ test_config_validators_fail_fast_without_errexit() { "$output" } +test_generate_validation_failure_skips_action_without_errexit() { + local config_file + local output + local ran_file + local -i status=0 + + test::setup + config_file="$TEST_TMPDIR/shuriken.conf" + ran_file="$TEST_TMPDIR/generate-ran" + mkdir -p "$TEST_TMPDIR/incoming" + test::write_preflight_config \ + "$config_file" "$TEST_TMPDIR/incoming" "$TEST_TMPDIR/dist" \ + "$TEST_REPO_ROOT/share/templates/default" + printf 'THUMBHEIGHT=bad\n' >> "$config_file" + + set +e + output=$( + bash -euo pipefail -s "$TEST_SHURIKEN" "$config_file" "$ran_file" \ + 2>&1 \ + <<'BASH' +shuriken="$1"; shift +config_file="$1"; shift +ran_file="$1"; shift + +# shellcheck source=/dev/null +source <(sed '$d' "$shuriken") + +generate_staged() { + printf 'generate_staged ran\n' > "$ran_file" +} + +SHURIKEN_CLI_ACTION=--generate +SHURIKEN_CLI_CONFIG_FILE="$config_file" +SHURIKEN_CLI_HAS_CONFIG_OVERRIDES=no +SHURIKEN_CLI_OVERRIDES=() +SHURIKEN_CLI_SYNC_DESTINATIONS=() +SHURIKEN_FORCE_GENERATE=no + +set +e +run_configured_action +run_configured_status=$? + +if [ -e "$ran_file" ]; then + printf 'FAIL: generate_staged ran after validation failure\n' >&2 + exit 1 +fi + +exit "$run_configured_status" +BASH + ) + status=$? + set -e + + if (( status == 0 )); then + printf 'FAIL: expected run_configured_action to fail\n' >&2 + exit 1 + fi + + test::assert_contains \ + 'ERROR: THUMBHEIGHT must be a positive integer' \ + "$output" + test::assert_path_absent "$ran_file" + test::teardown +} + test_generate_preflight_accepts_empty_height() { local config_file local fake_bin @@ -4023,6 +4088,9 @@ main() { 'config validators fail fast without errexit' \ test_config_validators_fail_fast_without_errexit test::run_case \ + '--generate validation failure skips action without errexit' \ + test_generate_validation_failure_skips_action_without_errexit + test::run_case \ '--generate preflight accepts empty HEIGHT' \ test_generate_preflight_accepts_empty_height test::run_case \ |
