-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy patherror-handler.sh
More file actions
75 lines (65 loc) · 2.72 KB
/
error-handler.sh
File metadata and controls
75 lines (65 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
# Centralized error handler and exit-trap for graceful pod termination.
#
# fail() — logs the error, stores its message, and exits 1.
# finalize_once() — the single EXIT trap: writes error-state JSON when rc≠0,
# runs all cleanup, then always exits 0 so Argo does not hang.
#
# Register the trap in entrypoint.sh AFTER all scripts are sourced:
# trap 'finalize_once' EXIT
# Stores the fatal error message so finalize_once can embed it in the error JSON.
FAIL_MESSAGE=""
FINALIZE_DONE=false
fail() {
local error_message="${1:-Unknown error}"
echo "❌ FATAL: $error_message"
echo "⚠️ Delegating cleanup to EXIT trap (finalize_once)."
FAIL_MESSAGE="$error_message"
# Catched by EXIT trap and goes to finalize_once()
exit 1
}
#shellcheck disable=SC2329
finalize_once() {
local rc=$?
if [ "$FINALIZE_DONE" != "true" ]; then
FINALIZE_DONE=true
echo "🔄 EXIT trap triggered with rc=$rc"
set +e
# When fail() triggered the exit, write a minimal error-state JSON so
# downstream pipeline stages (e.g. "get ATP report file") receive a valid
# FAILED payload instead of finding no file at all.
if [ "$rc" -ne 0 ]; then
echo "⚠️ Non-zero exit detected — pre-seeding error-state variables for generate_email_notification_json."
# Pre-export the variables that generate_email_notification_json reads.
# calculate-email-notification-variables.sh will bail early (no allure results),
# leaving these values intact so the downstream JSON reflects the fatal error.
export TEST_OVERALL_STATUS="FAILED"
export TEST_PASS_RATE=0
export TEST_PASS_RATE_ROUNDED=0
export TEST_TOTAL_COUNT=0
export TEST_PASSED_COUNT=0
export TEST_FAILED_COUNT=0
export TEST_SKIPPED_COUNT=0
export TEST_COVERAGE=0
export TEST_DETAILS_STRING=""
export EXECUTION_DATE
EXECUTION_DATE="$(date '+%Y-%m-%d %H:%M:%S')"
export TIMESTAMP
TIMESTAMP="$(date '+%Y-%m-%d %H:%M:%S UTC')"
if compgen -G "$TMP_DIR/allure-results/*-result.json" > /dev/null 2>&1; then
echo "ℹ️ Allure results detected — skipping 'Test not started' URL override."
else
export ALLURE_REPORT_URL="Test not started. Please check the logs for more details. $FAIL_MESSAGE. "
export ATP_REPORT_VIEW_UI_URL="Test not started. Please check the logs for more details. $FAIL_MESSAGE. "
fi
fi
generate_email_notification_json || true
push_metrics || true
save_native_report "$TMP_DIR/${NATIVE_REPORT_DIR:-playwright-report}" || true
finalize_upload || true
sleep 15
set -e
fi
# Always exit 0 so Argo/Kubernetes does not treat this pod as failed and hang.
exit 0
}