Skip to content

Commit

Permalink
#18 add exit 1 to run_xx errors
Browse files Browse the repository at this point in the history
  • Loading branch information
lucamlouzada committed Oct 1, 2024
1 parent 584c3d4 commit 9e7d338
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/shell/run_R.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ run_R () {
error_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "\033[0;31mProgram error\033[0m at ${error_time}: ${rCmd} not found. Make sure command line usage is properly set up."
echo "Program Error at ${error_time}: ${rCmd} not found." >> "${logfile}"
return 1 # exit early with an error code
exit 1 # exit early with an error code
fi

# check if the target script exists
if [ ! -f "${program}" ]; then
error_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "\033[0;31mProgram error\033[0m at ${error_time}: script ${program} not found."
echo "Program Error at ${error_time}: script ${program} not found." >> "${logfile}"
return 1
exit 1
fi

# capture the content of output folder before running the script
Expand Down
4 changes: 2 additions & 2 deletions lib/shell/run_latex.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ run_latex() {
error_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "\033[0;31mProgram error\033[0m at ${error_time}: latexmk not found. Ensure LaTeX is installed."
echo "Program Error at ${error_time}: latexmk not found." >> "${logfile}"
return 1
exit 1
fi

# check if the target script exists
if [ ! -f "${programname}.tex" ]; then
error_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "\033[0;31mProgram error\033[0m at ${error_time}: script ${programname}.tex not found."
echo "Program Error at ${error_time}: script ${programname}.tex not found." >> "${logfile}"
return 1
exit 1
fi

# capture the content of output folder before running the script
Expand Down
5 changes: 3 additions & 2 deletions lib/shell/run_python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ run_python () {
error_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "\033[0;31mProgram error\033[0m at ${error_time}: ${pythonCmd} not found. Make sure command line usage is properly set up."
echo "Program Error at ${error_time}: ${pythonCmd} not found." >> "${logfile}"
return 1 # exit early with an error code
exit 1 # exit early with an error code
fi

# check if the target script exists
if [ ! -f "${program}" ]; then
error_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "\033[0;31mProgram error\033[0m at ${error_time}: script ${program} not found."
echo "Program Error at ${error_time}: script ${program} not found." >> "${logfile}"
return 1
exit 1
fi

# capture the content of output folder before running the script
Expand Down Expand Up @@ -56,6 +56,7 @@ run_python () {
echo -e "\033[0;31mWarning\033[0m: there was an error, but files where created. Check log."
echo -e "\nWarning: There was an error, but these files were created: $created_files" >> "${logfile}" # log created files
fi
exit 1
else
echo "Script ${program} finished successfully at $(date '+%Y-%m-%d %H:%M:%S')" | tee -a "${logfile}"
echo "Output: $output" >> "${logfile}" # log output
Expand Down
3 changes: 2 additions & 1 deletion lib/shell/run_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ run_shell () {
error_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "\033[0;31mProgram error\033[0m at ${error_time}: script ${program} not found."
echo "Program Error at ${error_time}: script ${program} not found." >> "${logfile}"
return 1
exit 1
fi

# capture the content of the output folder before running the script
Expand Down Expand Up @@ -45,6 +45,7 @@ run_shell () {
echo -e "\033[0;31mWarning\033[0m: there was an error, but files where created. Check log."
echo -e "\nWarning: There was an error, but these files were created: $created_files" >> "${logfile}" # log created files
fi
exit 1
else
echo "Script ${program} finished successfully at $(date '+%Y-%m-%d %H:%M:%S')" | tee -a "${logfile}"
echo "Output: $output" >> "${logfile}" # log output
Expand Down
2 changes: 1 addition & 1 deletion lib/shell/run_stata.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ run_stata() {
error_time=$(date '+%Y-%m-%d %H:%M:%S')
echo -e "\033[0;31mProgram error\033[0m at ${error_time}: script ${program} not found."
echo "Program Error at ${error_time}: script ${program} not found." >> "${logfile}"
return 1
exit 1
fi

# capture the content of output folder before running the script
Expand Down

0 comments on commit 9e7d338

Please sign in to comment.