bash-oo-framework icon indicating copy to clipboard operation
bash-oo-framework copied to clipboard

Try catch causes docker conatiner crash with multiple sub shells.

Open microstacks opened this issue 8 years ago • 5 comments

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"
} 

microstacks avatar Apr 20 '16 20:04 microstacks

Same issue here with multiple sub-shells spawning unto death. GNU bash, version 4.3.46(1)-release (x86_64-pc-linux-gnu)

indietravel avatar Sep 12 '17 10:09 indietravel

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.

niieani avatar Sep 27 '17 18:09 niieani

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=
'

bborysenko avatar Jul 04 '18 06:07 bborysenko

Could you make a minimal reproduction Dockerfile repository?

niieani avatar Jul 07 '18 13:07 niieani

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 !

remipichon avatar Jan 07 '19 11:01 remipichon