Skip to content

Commit b40d888

Browse files
authored
chore: enhance error prompt (#329)
Assisted-by: Cursor Signed-off-by: Ruben Romero Montes <[email protected]>
1 parent fbdacbb commit b40d888

File tree

1 file changed

+30
-5
lines changed

1 file changed

+30
-5
lines changed

docker-image/scripts/trustify-da.sh

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,39 @@ exit_code=$?
1212

1313
if [ $exit_code != 0 ]
1414
then
15-
# In case of failure save only exit code into output file.
15+
# Read the full error log
16+
error_log=$(cat error.log 2>/dev/null || echo "")
17+
18+
# Extract the main error message (first Error: line)
19+
main_error=$(echo "$error_log" | grep -m1 "^Error:" || echo "Unknown error")
20+
21+
# Extract cause chain (lines with "cause:" or indented error details)
22+
cause_chain=$(echo "$error_log" | grep -E "(cause:|Caused by| at )" | head -20 || echo "")
23+
24+
# In case of failure save error details into output file.
1625
jq -n {} | \
17-
jq --arg exit_code "$exit_code" '. + {exit_code: $exit_code}' > \
26+
jq --arg exit_code "$exit_code" \
27+
--arg error "$main_error" \
28+
--arg stderr "$error_log" \
29+
'. + {exit_code: $exit_code, error: $error, stderr: $stderr}' > \
1830
$output_file_path
1931

20-
# Print stderr message to console
21-
error_message=$(sed -n '/^Error:/p' error.log)
22-
printf "\n[ERROR] Trustify Dependency Analytics failed with exit code $exit_code.\n$error_message"
32+
# Print detailed error message to console
33+
printf "\n[ERROR] Trustify Dependency Analytics failed with exit code $exit_code.\n"
34+
printf "\n%s\n" "$main_error"
35+
36+
if [ -n "$cause_chain" ]; then
37+
printf "\nCause chain:\n%s\n" "$cause_chain"
38+
fi
39+
40+
# Show full stderr if it contains additional information
41+
if [ -n "$error_log" ] && [ "$error_log" != "$main_error" ]; then
42+
printf "\nFull error output:\n"
43+
printf "=%.0s" {1..50}
44+
printf "\n%s\n" "$error_log"
45+
printf "=%.0s" {1..50}
46+
fi
47+
2348
exit 1
2449
else
2550
# In case of success print report summary into console

0 commit comments

Comments
 (0)