bash-oo-framework
bash-oo-framework copied to clipboard
Try catch causes docker conatiner crash with multiple sub shells.
I am trying try catch & exception for first time. My Docker container is crashing with basic test script (see below). Tried with Bash 4.3.11 & 4.2. On further analysis I see multiple sub shell's are created and my docker container dies because of resource exhaustion. I might be missing something here though, please let me know if thats the case.
#!/bash-4.2/bash
# BASH INFINITY
#
# Bash infinity OO framework for try/catch/exception handling
# Github - https://github.com/niieani/bash-oo-framework.git
source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"
## ERROR HANDLING MODULES
#
# try/catch/excpetion
import util/tryCatch
import util/exception
try {
ls /root2
} catch {
printf "directory /root2 not found"
}
Same issue here with multiple sub-shells spawning unto death. GNU bash, version 4.3.46(1)-release (x86_64-pc-linux-gnu)
Thanks for the report (and sorry for the late answer), unfortunately I don't have resources (time) right now to tackle this. If any of you figure this out, please file a PR with the fix or recommendation.
It looks like that in this case we also have to add import util/log
:
++(exception.sh:33): command_not_found_handle(): [[ ls /root2 = \(\ \s\e\t\ \-*\;\ \t\r\u\e* ]]
++(exception.sh:38): command_not_found_handle(): Exception::CustomCommandHandler ls /root2
++(exception.sh:17): Exception::CustomCommandHandler(): return 1
++(exception.sh:38): command_not_found_handle(): true
++(exception.sh:40): command_not_found_handle(): local script=/opt/workflow/bin/wf
++(exception.sh:41): command_not_found_handle(): local lineNo=13
++(exception.sh:42): command_not_found_handle(): local 'undefinedObject=ls /root2'
++(exception.sh:43): command_not_found_handle(): local type=/root2
++(exception.sh:45): command_not_found_handle(): [[ ls /root2 == \(*\) ]]
++(exception.sh:50): command_not_found_handle(): [[ -z ls /root2 ]]
++(exception.sh:55): command_not_found_handle(): [[ 1 -gt 0 ]]
++(exception.sh:57): command_not_found_handle(): subject=level3
++(exception.sh:57): command_not_found_handle(): Log 'inside Try No.: 1'
++(exception.sh:30): command_not_found_handle(): local 'IFS=
'
++(exception.sh:33): command_not_found_handle(): [[ Log inside Try No.: 1 = \(\ \s\e\t\ \-*\;\ \t\r\u\e* ]]
++(exception.sh:38): command_not_found_handle(): Exception::CustomCommandHandler Log 'inside Try No.: 1'
++(exception.sh:17): Exception::CustomCommandHandler(): return 1
++(exception.sh:38): command_not_found_handle(): true
++(exception.sh:40): command_not_found_handle(): local script=/usr/local/lib/bash-oo-framework/util/exception.sh
++(exception.sh:41): command_not_found_handle(): local lineNo=57
++(exception.sh:42): command_not_found_handle(): local 'undefinedObject=Log inside Try No.: 1'
++(exception.sh:43): command_not_found_handle(): local type=/root2
++(exception.sh:45): command_not_found_handle(): [[ Log inside Try No.: 1 == \(*\) ]]
++(exception.sh:50): command_not_found_handle(): [[ -z Log inside Try No.: 1 ]]
++(exception.sh:55): command_not_found_handle(): [[ 1 -gt 0 ]]
++(exception.sh:57): command_not_found_handle(): subject=level3
++(exception.sh:57): command_not_found_handle(): Log 'inside Try No.: 1'
++(exception.sh:30): command_not_found_handle(): local 'IFS=
'
Could you make a minimal reproduction Dockerfile repository?
Here is a Dockerfile to reproduce the issue
- Dockerfile
FROM ubuntu
RUN apt-get update && apt-get install -y git
WORKDIR /root
RUN git clone https://github.com/niieani/bash-oo-framework.git
COPY script.sh script.sh
RUN chmod +x script.sh
CMD ["./script.sh"]
# build
# docker build -t test_try_catch .
# run
# docker run test_try_catch
- script.sh
#!/usr/bin/env bash
source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/bash-oo-framework/lib/oo-bootstrap.sh"
import util/tryCatch
import util/exception # needed only for Exception::PrintException
# it does work when log are imported
# import util/log
try {
echo "try"
exit 1
} catch {
echo "catch"
echo "Error in $__EXCEPTION_SOURCE__ at line: $__EXCEPTION_LINE__!"
}
- build with
docker build -t test_try_catch .
- test with
docker run test_try_catch
- it will exhaust your cpu so
docker kill
might help - uncomment line 8 of script.sh to have it working
Hope this helps, thanks !