Skip to content

Commit

Permalink
v9.6
Browse files Browse the repository at this point in the history
- DietPi-Globals | G_BUG_REPORT: Print compelete bug report template
- DietPi-Globals | G_EXEC: Do not always print bug report template on error. Instead add error handler option to do so.
  • Loading branch information
MichaIng committed Jul 7, 2024
1 parent 5946838 commit 44f500d
Showing 1 changed file with 88 additions and 73 deletions.
161 changes: 88 additions & 73 deletions dietpi/func/dietpi-globals
Original file line number Diff line number Diff line change
Expand Up @@ -803,27 +803,60 @@ $grey─────────────────────────
return "${result:-1}"
}

G_BUG_REPORT() {
local dietpi_version="v$G_DIETPI_VERSION_CORE.$G_DIETPI_VERSION_SUB.$G_DIETPI_VERSION_RC ($G_GITOWNER/$G_GITBRANCH)"
local image_creator preimage_name

if [[ -f '/boot/dietpi/.prep_info' ]]; then
image_creator=$(mawk 'NR==1' /boot/dietpi/.prep_info)
[[ $image_creator == 0 ]] && image_creator='DietPi Core Team'
preimage_name=$(mawk 'NR==2' /boot/dietpi/.prep_info)
fi

cat <<EOF
#### Required Information
- DietPi version | $dietpi_version
# G_BUG_REPORT [-c COMMAND] [-? EXIT_CODE]
# - Print pre-filled bug report template
G_BUG_REPORT()
{
local command exit_code
while (( $# ))
do
case $1 in
'-c') shift; command=$1;;
'-?') shift; exit_code=$1;;
*) G_DIETPI-NOTIFY 1 "Invalid argument \"$1\""; return 1;;
esac
shift
done

# Print bug report template
echo "#### Details:
- Date | $(date '+%F %T')"
# - Add program/script name, failed command and exit code if given
[[ $G_PROGRAM_NAME ]] && echo "- Program name | $G_PROGRAM_NAME"
[[ $command ]] && echo "- Command | \`$command\`"
[[ $exit_code ]] && echo "- Exit code | $exit_code"
echo "- DietPi version | v$G_DIETPI_VERSION_CORE.$G_DIETPI_VERSION_SUB.$G_DIETPI_VERSION_RC ($G_GITOWNER/$G_GITBRANCH)
- Distro version | $G_DISTRO_NAME (ID=$G_DISTRO${G_RASPBIAN:+,RASPBIAN=$G_RASPBIAN})
- Kernel version | \`$(uname -a)\`
- Architecture | \`$(dpkg --print-architecture)\`
- SBC model | $G_HW_MODEL_NAME (ID=$G_HW_MODEL)
- Image creator | $image_creator
- Pre-image | $preimage_name
EOF
}
- Hardware model | $G_HW_MODEL_NAME (ID=$G_HW_MODEL)"
# - Add image creator and pre-image info if given
if [[ -f '/boot/dietpi/.prep_info' ]]
then
image_creator=$(mawk 'NR==1' /boot/dietpi/.prep_info)
[[ ${image_creator:-0} == 0 ]] || echo "- Image creator | $image_creator"
preimage_name=$(mawk 'NR==2' /boot/dietpi/.prep_info)
[[ $preimage_name ]] && echo "- Pre-image | $preimage_name"
fi
echo '#### Steps to reproduce:
<!-- Explain how to reproduce the issue -->
1. ...
2. ...
#### Expected behaviour:
<!-- What SHOULD happen? -->
- ...
#### Actual behaviour:
<!-- What IS happening? -->
- ...
#### Extra details:
<!-- Please post any extra details that might help solve the issue -->
- ...
#### Additional logs:
```'
# - Add log if given
[[ -f '/tmp/G_EXEC_LOG' ]] && cat '/tmp/G_EXEC_LOG' || echo '<!-- Please paste logs or related console output here -->'
echo '```'
}

#-----------------------------------------------------------------------------------
# Error handled command execution wrapper
Expand Down Expand Up @@ -889,56 +922,17 @@ EOF
# Retry non-interactively if current $attempt is <= $G_EXEC_RETRIES
[[ $attempt -le $G_EXEC_RETRIES ]] && { ((attempt++)) && continue; }

# Print command output if not done already
[[ $G_EXEC_OUTPUT != 1 ]] && cat "$fp_log"

# Print FAILED, append raw command string if $G_EXEC_DESC is given
G_DIETPI-NOTIFY 1 "${G_EXEC_DESC:+$G_EXEC_DESC\n - Command: }$ecommand"

# Exit retry loop if $G_EXEC_NOHALT=1 is given
[[ $G_EXEC_NOHALT == 1 ]] && break

# Prepare error handler menu and GitHub issue template
local fp_error_report='/tmp/G_EXEC_ERROR_REPORT' log_content=$(<"$fp_log") last_whip_menu_item sent_bug_report
if [[ -f '/boot/dietpi/.prep_info' ]]; then
image_creator=$(mawk 'NR==1' /boot/dietpi/.prep_info)
[[ $image_creator == 0 ]] && image_creator='DietPi Core Team'
preimage_name=$(mawk 'NR==2' /boot/dietpi/.prep_info)
fi

local dietpi_version="v$G_DIETPI_VERSION_CORE.$G_DIETPI_VERSION_SUB.$G_DIETPI_VERSION_RC ($G_GITOWNER/$G_GITBRANCH)"
local error_details=$(G_BUG_REPORT)

[[ ${G_PROGRAM_NAME,,} == 'dietpi-'* ]] && echo -e "\e[41m
\e[41m
---------------------------------------------------------------------
- DietPi has encountered an error -
- Please create a ticket: https://github.com/MichaIng/DietPi/issues -
- Copy and paste only the BLUE lines below into the ticket -
---------------------------------------------------------------------\e[44m
#### Details:
- Date | $(date)
- Command | \`$ecommand\`
- Exit code | $exit_code
- Software title | $G_PROGRAM_NAME
$error_details
#### Steps to reproduce:
<!-- Explain how to reproduce the issue -->
1. ...
2. ...
#### Expected behaviour:
<!-- What SHOULD happen? -->
- ...
#### Actual behaviour:
<!-- What IS happening? -->
- ...
#### Extra details:
<!-- Please post any extra details that might help solve the issue -->
- ...
#### Additional logs:
\`\`\`
$log_content
\`\`\`\e[41m
---------------------------------------------------------------------\e[0m" > "$fp_error_report"

# Enter error handler menu loop in interactive mode
local last_whip_menu_item sent_bug_report fp_error_report='/tmp/G_EXEC_ERROR_REPORT' dietpi_version="v$G_DIETPI_VERSION_CORE.$G_DIETPI_VERSION_SUB.$G_DIETPI_VERSION_RC ($G_GITOWNER/$G_GITBRANCH)"
[[ $G_INTERACTIVE == 1 ]] && while :
do
G_WHIP_MENU_ARRAY=('Retry' ': Re-run the last command that failed')
Expand All @@ -948,8 +942,12 @@ $log_content
pgrep -cf 'dietpi-config' &> /dev/null || G_WHIP_MENU_ARRAY+=('DietPi-Config' ': Edit network, APT/NTP mirror settings etc')
G_WHIP_MENU_ARRAY+=('Open subshell' ': Open a subshell to investigate or solve the issue')

# Allow to send bug report, if it was produced by one of our scripts
[[ ${G_PROGRAM_NAME,,} == 'dietpi-'* && $G_PROGRAM_NAME != 'DietPi-Installer' ]] && G_WHIP_MENU_ARRAY+=('Send report' ': Uploads bugreport containing system info to DietPi')
# Allow to send bug report if it was produced by one of our scripts, excluding DietPi-Installer
[[ ${G_PROGRAM_NAME,,} == 'dietpi-'* && $G_PROGRAM_NAME != 'DietPi-Installer' ]] && G_WHIP_MENU_ARRAY+=('Send report' ': Upload bug report including system info to DietPi')

# Allow to print bug report template if it was produced by one of our scripts
[[ ${G_PROGRAM_NAME,,} == 'dietpi-'* ]] && G_WHIP_MENU_ARRAY+=('Print report' ': Print bug report template for GitHub or forum')

G_WHIP_MENU_ARRAY+=('' '●─ Devs only ')
G_WHIP_MENU_ARRAY+=('Change command' ': Adjust and rerun the command')

Expand All @@ -959,8 +957,8 @@ $log_content
G_WHIP_MENU "${G_EXEC_DESC:+$(mawk '{gsub("\\\e[[0-9][;0-9]*m","");print}' <<< "$G_EXEC_DESC")\n} - Command: ${acommand[*]}
- Exit code: $exit_code
- DietPi version: $dietpi_version | HW_MODEL: $G_HW_MODEL | HW_ARCH: $G_HW_ARCH | DISTRO: $G_DISTRO
${image_creator:+ - Image creator: $image_creator\n}${preimage_name:+ - Pre-image: $preimage_name\n} - Error log:
$log_content" || break # Exit error handler menu loop on cancel
- Error log:
$(<"$fp_log")" || break # Exit error handler menu loop on cancel

last_whip_menu_item=$G_WHIP_RETURNED_VALUE

Expand All @@ -987,10 +985,34 @@ $log_content" || break # Exit error handler menu loop on cancel

elif [[ $G_WHIP_RETURNED_VALUE == 'Send report' ]]; then

# Store error details to append to bug report upload
G_BUG_REPORT -c "${acommand[*]}" -? "$exit_code" > "$fp_error_report"

# Send report
/boot/dietpi/dietpi-bugreport 1 && sent_bug_report=1
read -rp '
Press any key to continue...'

elif [[ $G_WHIP_RETURNED_VALUE == 'Print report' ]]; then

echo -e '\e[41m---------------------------------------------------------------------
- DietPi bug report template for GitHub or forum -
- Please report at: https://github.com/MichaIng/DietPi/issues -
or: https://dietpi.com/forum/c/troubleshooting/10 -
- Copy and paste ONLY the BLUE lines below, replacing the template! -
---------------------------------------------------------------------\e[44m'
# Add bug report ID if sent already
if [[ $sent_bug_report == 1 ]]
then
sed --follow-symlinks -i "/^- Date | /a\- Bug report | $G_HW_UUID" "$fp_error_report"
cat "$fp_error_report"
else
G_BUG_REPORT -c "${acommand[*]}" -? "$exit_code"
fi
echo -e '\e[41m---------------------------------------------------------------------\e[0m'
read -rp '
Press any key to continue...'

elif [[ $G_WHIP_RETURNED_VALUE == 'Change command' ]]; then

G_WHIP_DEFAULT_ITEM=${acommand[*]}
Expand All @@ -1016,14 +1038,7 @@ Press any key to continue...'
fi
done

# Error has not been solved, print GitHub issue template if it was produced and exit error handler menu loop
if [[ -f $fp_error_report ]]; then

# Add bug report ID if it was sent
[[ $sent_bug_report == 1 ]] && sed --follow-symlinks -i "/^- Date | /a\- Bug report | $G_HW_UUID" "$fp_error_report"
cat "$fp_error_report"

fi
# Error has not been solved, exit error handler menu loop
break
done

Expand Down

0 comments on commit 44f500d

Please sign in to comment.