-
Notifications
You must be signed in to change notification settings - Fork 245
Open
Description
Hi,
I have this test script with 4 ways to execute mkdir command (for example):
#!/usr/bin/env bash
source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"
import util/log util/exception util/tryCatch util/namedParameters util/class
# Creating a Test class
class:Test() {
Test.Mkdir() {
[string] path
if [ ! -d "${path}" ]; then
mkdir "${path}"
fi
}
Test.MkdirTryCatch() {
[string] path
if [ ! -d "${path}" ]; then
try {
mkdir "${path}"
} catch {
echo "There was an error on folder creation!"
echo "Caught Exception:$(UI.Color.Red) $__BACKTRACE_COMMAND__ $(UI.Color.Default)"
echo "File: $__BACKTRACE_SOURCE__, Line: $__BACKTRACE_LINE__"
Exception::PrintException "${__EXCEPTION__[@]}"
}
fi
}
}
Type::Initialize Test
Test Command
# Run mkdir command without class
#mkdir /tmp/a/b
# Run mkdir command without class with try and catch
#try {
# mkdir "${path}"
#} catch {
# echo "There was an error on folder creation!"
# echo "Caught Exception:$(UI.Color.Red) $__BACKTRACE_COMMAND__ $(UI.Color.Default)"
# echo "File: $__BACKTRACE_SOURCE__, Line: $__BACKTRACE_LINE__"
# Exception::PrintException "${__EXCEPTION__[@]}"
#}
# Run mkdir command using the Test class
#$var:Command Mkdir "/tmp/a/b"
# Run mkdir command using the Test class with try and catch
#$var:Command MkdirTryCatch "/tmp/a/b"
1. Run mkdir command without class
mkdir /tmp/a/b
Output:
# ./test.sh
mkdir: cannot create directory â/tmp/a/bâ: No such file or directory
â UNCAUGHT EXCEPTION: __typeCreate_paramNo (1)
î ⦠mkdir /tmp/a/b [test.sh:33]
â¡ Press [CTRL+C] to exit or [Return] to continue execution.
2. Run mkdir command without class with try and catch
try {
mkdir "${path}"
} catch {
echo "There was an error on folder creation!"
echo "Caught Exception:$(UI.Color.Red) $__BACKTRACE_COMMAND__ $(UI.Color.Default)"
echo "File: $__BACKTRACE_SOURCE__, Line: $__BACKTRACE_LINE__"
Exception::PrintException "${__EXCEPTION__[@]}"
}
Output:
# ./test.sh
mkdir: cannot create directory ââ: No such file or directory
There was an error on folder creation!
Caught Exception: mkdir "${path}"
File: test.sh, Line: 37
î ⦠mkdir "${path}" [test.sh:37]
3. Run mkdir command using the Test class
$var:Command Mkdir "/tmp/a/b"
Output:
# ./test.sh
mkdir: cannot create directory â/tmp/a/bâ: No such file or directory
4. Run mkdir command using the Test class with try and catch
$var:Command MkdirTryCatch "/tmp/a/b"
Output:
# ./test.sh
mkdir: cannot create directory â/tmp/a/bâ: No such file or directory
There was an error on folder creation!
Caught Exception:
File: /usr/local/share/bash-oo-framework/lib/util/command.sh, Line: 58
The problem is that, the exception/error is not cought when I am using the Test Class.
Is there something I need to set/import/etc. ? I am missing something?
Please guide me in the right direction.
Thank you!
Metadata
Metadata
Assignees
Labels
No labels