@@ -574,7 +574,10 @@ function Error () {
574574 # Because of the newlines in the error message subsequent lines appear without a leading '+' character
575575 # so that those debug output lines are indistinguishable from normal stdout/stderr output of programs,
576576 # cf. https://github.com/rear/rear/pull/1877
577- # Thereafter ('+ [Bug]*Error ' lines were needed before) skip 'set -x' lines (lines that start with a '+' character).
577+ # Thereafter ('+ [Bug]*Error ' lines were needed before) skip 'set -x' lines (lines that start with a '+' character)
578+ # and skip the initial 'Including sub-path/to/script.sh' line that is always found
579+ # to keep only the actual stdout and stderr messages of the last called programs
580+ # so we can test if messages were actually found via 'test "string of messages"' for emptiness.
578581 # Show at most the last 8 lines because too much before the actual error may cause more confusion than help.
579582 # Add two spaces indentation for better readability what those extracted log file lines are.
580583 # Some messages could be too long to be usefully shown on the user's terminal so that they are truncated after 200 bytes:
@@ -583,13 +586,32 @@ function Error () {
583586 PrintError " Some latest log messages since the last called script $last_sourced_script_filename :"
584587 PrintError " $last_sourced_script_log_messages "
585588 fi
589+ # In non-debug modes stdout and stderr are redirected to STDOUT_STDERR_FILE="$TMP_DIR/rear.$WORKFLOW.stdout_stderr" if possible
590+ # but in certain cases (e.g. for the 'help' workflow where no $TMP_DIR exists) STDOUT_STDERR_FILE=/dev/null
591+ # so we extract some latest messages only if STDOUT_STDERR_FILE is a regular file:
586592 if test -f $STDOUT_STDERR_FILE ; then
593+ # We use the same extraction pipe as above because STDOUT_STDERR_FILE may also contain 'set -x' and things like that
594+ # because scripts could use 'set -x' and things like that as needed (e.g. diskrestore.sh runs with 'set -x'):
587595 { local last_sourced_script_stdout_stderr_messages=" $( sed -n -e " /Including .*$last_sourced_script_filename /,/+ [Bug]*Error /p" $STDOUT_STDERR_FILE | egrep -v " ^\+|Including .*$last_sourced_script_filename " | tail -n 8 | sed -e ' s/^/ /' | cut -b-200 ) " ; } 2>> /dev/$DISPENSABLE_OUTPUT_DEV
588596 if test " $last_sourced_script_stdout_stderr_messages " ; then
589- PrintError " Some messages from $STDOUT_STDERR_FILE since the last called script $last_sourced_script_filename :"
597+ # When stdout and stderr are redirected to STDOUT_STDERR_FILE messages of the last called programs cannot be in the log
598+ # so we use LogPrintError and 'echo "string of messages" >>$RUNTIME_LOGFILE' (the latter avoids the timestamp prefix)
599+ # to have the extracted messages stored in the log so that they are later available (in contrast to terminal output).
600+ # The full stdout and stderr messages are available in STDOUT_STDERR_FILE:
601+ LogPrintError " Some messages from $STDOUT_STDERR_FILE since the last called script $last_sourced_script_filename :"
590602 PrintError " $last_sourced_script_stdout_stderr_messages "
603+ echo " $last_sourced_script_stdout_stderr_messages " >> " $RUNTIME_LOGFILE "
591604 fi
592605 fi
606+ # Show some generic info about debugging:
607+ if test " $DEBUG " ; then
608+ # We are in debug mode but not in debugscript mode:
609+ test " $DEBUGSCRIPTS " || PrintError " You may use debugscript mode '-D' for full debug messages with 'set -x' output"
610+ else
611+ # We are not in debug mode:
612+ PrintError " Use debug mode '-d' for some debug messages or debugscript mode '-D' for full debug messages with 'set -x' output"
613+ fi
614+ # Log the error message:
593615 Log " ERROR: $* "
594616 LogToSyslog " ERROR: $* "
595617 # Print stack strace in reverse order to the current STDERR which is (usually) the log file:
0 commit comments