niieani / bash-oo-framework Goto Github PK
View Code? Open in Web Editor NEWBash Infinity is a modern standard library / framework / boilerplate for Bash
Home Page: https://github.com/niieani/bash-oo-framework/discussions
License: MIT License
Bash Infinity is a modern standard library / framework / boilerplate for Bash
Home Page: https://github.com/niieani/bash-oo-framework/discussions
License: MIT License
the framework works out of the box in my current ubuntu.
I have a docker container using debian9 and bash 4.4.12
. I am getting output like this
igor@04e68d65320c:~/containerroot$ ./igorpro --registerfile serial.txt
activating bash-oo-framework
! Press [CTRL+C] to exit or [Return] to continue execution.
{*} Continuing...
! Press [CTRL+C] to exit or [Return] to continue execution.
where the error description and backtrace is missing. Do I need to install any required packages or fonts - I could not find anything.
Hi,
i'm trying to implement try/catch util but no success so far.
Following code
try {
# many lines of code
} catch {
# Handling error
}
Gives me an error:
script.sh: syntax error near unexpected token }' script.sh: line 159:
} catch {'
Any clue what's wrong with try catch syntax and/or implementation?
I need imagemagick for taking screenshots in my current bash project.
I tried to add this framework to it, but import
does not work for import util/exception
:
import-im6.q16: unable to open image `util/exception': No such file or directory @ error/blob.c/OpenBlob/201.
import is a native imagemagick function. Is there a way to work around this, i.e. unbind import before sourcing the framework and afterwards binding import again?
$ which import
/usr/bin/import
I'm using Bash 4.3.42(1)-release and just checked out the project.
Trying to call ./oo.sh
results in:
✘ UNCAUGHT EXCEPTION: Manually invoked
## 58
➦ Cannot import /src/bash-oo-framework/lib/types/base/Var.sh [06_system.sh:53]
✘ [ ! -e "$libPath" ] && throw "Cannot import $libPath" && return 1 [06_system.sh:53]
## 1
import Var [Array.sh:1]
## 19
➦ source "$libPath" || throw "Unable to load $libPath" [06_system.sh:19]
## 66
➦ System.LoadFile "$file" [06_system.sh:66]
## 9
➦ System.Import [oo.sh:4]
✘ import lib/types/base [oo.sh:4]
⚡ Press [CTRL+C] to exit or [Return] to continue execution.
I have a function that accepts a "boolean" as an argument. I want to make this argument named. I have:
import util/namedParameters
set -u
function q {
[boolean] debug
if [ "$debug" = "true" ]; then
set -x
else
set +x
fi
}
q true
Now, due to set -u
the script fails as there is an unbound varible __primitive_extension_fingerprint__boolean
. This variable is defined in util/types
.
set -u
the $debug
variable has a value of :false
.__primitive_extension_fingerprint__boolean
from utils/types
into utils/namedParameters
, the script succeeds. But the variable's value has a long alphanumeric prefix.In both cases, my check `[ "$debug" = "true"] fails. How should I check for the value of the boolean?
I'm making 'float' primitive extension.
The problem is that:
I want to implement it by using integerArray so that we can calculate easily.
But I can't use integerArray as 'fingerprint' uses some alphabets.
I want to change the base __primitive_extension_declaration
using only numbers.
If it is a problem, I'll use 'array' instead of 'integerarray'.
When I do:
!/usr/bin/env bash
# Save current path
currentPath=$(pwd)
scriptDirectoryPath="$(cd "${BASH_SOURCE[0]%/*}" && pwd )"
# Load Bash Infinity Framework, import libraries and turn logging on
source "${scriptDirectoryPath}/vendor/bash-oo-framework/lib/oo-bootstrap.sh"
import util/exception util/tryCatch util/log util/variable util/type util/namedParameters UI/Color
e="test" throw
I will get following:
✘ UNCAUGHT EXCEPTION: shift (1)
➦ shift [exception.sh:41]
➦ command_not_found_handle [test.sh:7]
✘ e="test" throw [test.sh:7]
⚡ Press [CTRL+C] to exit or [Return] to continue execution.
When I comment out line 41 in lib/util/exception.sh
of this framework I get
✘ UNCAUGHT EXCEPTION: test ()
e="➦ test" throw [test.sh:12]
⚡ Press [CTRL+C] to exit or [Return] to continue execution.
Human.Eat() {
[string] food
this eaten push "$food"
# will return a string with the value:
@return:value "$this just ate $food, which is the same as $1"
}
This function prints out just ate corn, which is the same as corn
It should be like this:
Human.Eat() {
[string] food
this eaten push "$food"
# will return a string with the value:
@return:value "$(this name) just ate $food, which is the same as $1"
}
This function prints out Mark just ate corn, which is the same as corn
Hi,
I have some function that change some variable inside the try/catch and return 0 or 1.
My first problem is when I return 0 or 1 it throws an error.
My second problem is: I placed the return 0 or 1 outside of the try/catch, but I change some variable inside the try/catch. And then I cannot see the new value of this variable.
Kind Regards,
Felipe
tested in bash 4.3+
when setting 'set -u' in example/array.sh, I receive:
bash-oo-framework/lib/util/command.sh: line 34: $3: unbound variable
there are more errors elsewhere, after performing "${unboundvar:-}"
Is this conscious design decision related to bash version?
Sometimes I want my script to fail, not to cause more mayhem in unpredictable way. How to overcome this?
hello, I'm really interested in this project, and respect it.
I'm trying translating the README.md into Japanese.
While this, I got some questions( might be a fool one) so can I ask some?
(I'm not a native English speaker, I'm still learning English at school. So, I apologize that there might be some rude words/sentences)
lossless dumping
In Passing arrays, maps and objects as parameters
section:
The Variable utility offers lossless dumping of arrays and associative array (referred here to as `maps`) declarations by the use of the `@get` command.
I couldn't get the meaning of lossless dumping
.
I googled a lot, but there's no info...
Is it almost the same meaning of 'dumps perfect copy of arrays' ?
In the README.md, Standard Library
section, there's such comments
# lists all matches in group 1:
$var:matchGroups every 2 1
but based on my codereading, I couldn't understand what the 'group 1' is.
what I got is "every
method choose every $every
th value starting from $startingIndex
. and return it as an array"
## group 0, match 1
$var:someString match '([0-9]+) [a-zA-Z]+' 0 1
this also confuse me...
is it a word of functional languages?
I'm not sure those are because I don't know other meaning of 'group', or I don't know C#/Java/javaScript languages...
I'm glad if you answer me, thanks.
Hi niieani,
I forked your bash-oo-framework to extend the System.Import function for loading modules directly from github repos. Thus I'd like to print out the subject=level{2,3,4} .... lines Unfortunately I don' really understand how to set-up the logger.
I tried this:
#!/usr/bin/env bash
## BOOTSTRAP ##
source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-framework.sh"
level_debug(){
echo "level: $*"
}
Log.RegisterLogger level4 level_debug
Log.RegisterLogger level3 level_debug
Log.RegisterLogger level2 level_debug
## MAIN ##
import lib/steffenhoenig/crash/modules/example
import lib/type-core
The test is the sample test on README.md:
#!/bin/bash
source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"
import util/test UI/Color
it 'should make a number and change its value'
try
integer aNumber=10
aNumber=12
test $aNumber == 12
expectPass
When the test is runned the next error is shown:
UI.Color.Red: order not found
UI.Color.Default: order not found
The problem happens on line 70 of test.sh:
alias caught="echo "CAUGHT:
Why it did as a workaround was to put the aliases on the same file just above the conflicting line:
alias UI.Color.Default="echo"
alias UI.Color.Red="echo"
alias describe='Test NewGroup'
alias summary='Test DisplaySummary'
alias caught="echo "CAUGHT:
And all work.
The lxterminal I'm using uses 8 colors:.
I have the following stack trace:
This is how I interpret the output. Could you correct me if I am wrong?
The "important" lines are the ones starting with the arrow (the underlined, red ones). I call them main lines. The first of these, the top-most, contains a friendly error message. The others show at most 3 things:
Then, some times there might be a second accompanying line for these main lines. These accompanying lines are present when the main line does not provide the full picture, ie the actual function/builtin call with the arguments passed.
Is the above correct?
Some more questions:
Variable::TrapAssignNumberedParameter
function. But the accompanying line seems out of place. Is this due to the magic with the named parameters aliases and traps?I tried executing a couple of test scripts (try-catch.sh and oo.sh). The shell window was immediately closed when executed.
My bash version is as follows.
GNU bash, version 3.2.25(1)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.
Please give me some guide lines on solving this.
Thanks.
[This is just a mention for people who is trying to translate/ translating into Japanese]
[日本語訳作業をしている人/しようと思っている人へのメモです]
This is not a issue about bug-report, feature, and something like that.
バグレポートや新しい機能に関するissueではありません。
--- Japanese
oo-frameworkのREADMEを日本語訳しています。
他の人がやってなければ日本語訳やろうかな...?と思っている方いましたら一緒にやりましょう!
大体の部分は翻訳が終わり、細かい訳と手直し作業が残っています。
自分はまだ英語勉強中な身なのでおそらくより良い訳があると思うのです...
協力してくださる方、待っています!(実は少し詰まってたりするので)
--- English
Hi, I'm translating README into Japanese these days.
If you're thinking of translation for Japanese, why not doing together!
It's almost close to end, but I have to check the details and fix mistakes.
As I'm just a student learning English at school, I think there should be better translations.
I'm glad if someone join me and could do great job together! ( actually, I have some problem so that my work is stopped now)
Such a good programming font!
https://raw.githubusercontent.com/niieani/bash-oo-framework/master/docs/exception.png
Have this error when running your-script.sh on Solaris.
$ uname -a
SunOS localhost 5.11 11.2 sun4v sparc sun4v
$ bash --version
GNU bash, version 4.1.17(1)-release (sparc-sun-solaris2.11)
$ ./your-script.sh
/pkg/my/tools/bash-oo/lib/oo-bootstrap.sh: line 44: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/my/tools/bash-oo/lib/oo-bootstrap.sh: line 45: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/my/tools/bash-oo/lib/oo-bootstrap.sh: line 176: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/my/tools/bash-oo/lib/oo-bootstrap.sh: line 177: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/my/tools/bash-oo/lib/oo-bootstrap.sh: line 178: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
/pkg/my/tools/bash-oo/lib/oo-bootstrap.sh: line 190: declare: -g: invalid option
declare: usage: declare [-aAfFilrtux] [-p] [name[=value] ...]
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!
The error handling framework shows the error on Cygwin (some characters look odd, though) and then offers to exit or continue.
When I press Ctrl+C to exit, I get a new prompt but the terminal is in a bad state - I can't see what I type anymore. I have to blindly type "stty sane" to reset the terminal.
I'm not sure why that happens. I tried read -s
in the terminal and aborted it with Ctrl+C. The editing was restored in this case, so it must be something else. The escape codes in line 232 of https://github.com/niieani/bash-oo-framework/blob/master/lib/system/03_exception.sh (c282937) also doesn't look like it's leaking something.
Maybe a trap handler?
I'm using a recent version of Cygwin with BASH 4.3.42.
There is a problem when trying to assign array by value to any variable after initialization. I prepared code sample to demonstrate my issue. To my knowledge every case should work exactly the same. What am I missing here?
#!/usr/bin/env bash
source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"
import util/log
import util/class
class:MyIssue() {
public string someMessage
public array someMessageLines
MyIssue.someStuff() {
array someMessageLines="$(this someMessage toArray)"
$var:someMessageLines
if [[ $($var:someMessageLines length) != 0 ]]; then echo 'This stuff worked '; fi
}
MyIssue.someStufff() {
array someMessageLines
$var:someMessageLines="$(this someMessage toArray)"
$var:someMessageLines
if [[ $($var:someMessageLines length) != 0 ]]; then echo 'This stufff worked '; fi
}
MyIssue.someStuffff() {
this someMessageLines="$(this someMessage toArray)"
this someMessageLines
if [[ $(this someMessageLines length) != 0 ]]; then echo 'This stuffff worked '; fi
}
}
Type::Initialize MyIssue
MyIssue my
$var:my someMessage = 'automatic
error
handling
with
exceptions
'
$var:my someStuff
echo '----------------'
$var:my someStufff
echo '----------------'
$var:my someStuffff
I thought this should work:
namespace app
Log.AddOutput app DEBUG
subject=info Log "Done"
but it logs at the defaut level (DEBUG) instead of INFO.
There are calls to Log
inside it.
Here is an example script:
#!/bin/bash
source "lib/oo-bootstrap.sh"
import "../Ethical Hacking/EN2720/scripts/vendor/bash-oo-framework/lib/util/namedParameters.sh"
function q {
@required [string] command
echo "${command-UNDEFINED}"
}
q 'some value'
Running this prints 'UNDEFINED'.
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"
}
Consider this example bash file:
function q() {
[string] var
}
In the above example, there is no command for the DEBUG trap to hook into. This is expected.
Now consider this:
function q(){
@required [array] var
for i in "${var[@]}"; do
echo $i
done
}
q "$(@get array_var)"
echo 'Done'
In the above, (it seems that) the var
array will be set when the for i in "${var[@]}"; do
line gets run. But bash will not even run this line as there is no array to expand. So, it will simply skip the loop and return from the function as there is no other command to run. As a result, the context will change and __assign_paramNo
and the other variables will be unset. The @required
is there just for the example, it is not crucial to repeating the behavior. If there were more lines after the loop in the function, bash would still skip the loop, but the array would eventually be evaluated when the line after the loop was run.
I haven't found a way to solve this.
Hi, I just love your framework (finally I don't see myself lost coming from C# and Swift worlds), but is there any complex example? I'm currently looking for these:
1] How do you create collections of class objects?
2] How to have class properties which are based on other classes? I mean:
class:Location() {
public string x
public string y
}
class:Vehicle() {
public Location location
public string name
}
Is it possible at all?
Thank you.
(This issue is writn for infomation sharing.)
It doesn't work at this time because of bpkg's bug.
I find this issue in bokg which referred to this problem.
And there's also PR to fix this but not mergerd yet.
For now, if you try to install using bpkg, you'll get results like this:
https://asciinema.org/a/208863
What we can do is just to wait for the time PR is merged...
For now, README.md
is the only reference of this framework(except source codes themselve.)
I wonder if we gather all knowledges and make a wiki for tutorial, reference, etc.
I've spent so much time to read code in order to understand the framework.
It's really good experience for me and I enjoy reading, but some people doesn't like it.
(and also, I want reference while making my project)
I'm sure it's not a good time to start because #45 (the RFC for 3.0) is on the way.
But I think it'll take long time to release 3.0 so that it's better to have wiki of version 2.0
(I can add Japanese references)
Continuing from #44 (comment).
@tterranigma Let's discuss the scope of 3.0.
I've added you as a collaborator so you have push rights to the repo.
We should decide on the features to focus on implementing and problems needing tackling first. I've opened a clean branch (3.0) so we can work with a clean slate.
We can keep the outcome of the discussion as documentation inside of the repo itself, e.g. in a docs
folder.
Some things that come to mind while designing the future:
Any respecting language ecosystem has a module system for managing and sharing dependencies/libraries (JS has npm
, Python has PyPi
, Ruby has RubyGem
, C# has NuGet, and so on). I think we should think about both a method of sharing internal and external "modules", which is especially difficult, since functions are global in bash
.
For a non-polluting way of loading, I propose something in the lines of my experiment here.
For a shared repository of public (and private) libraries we could use GitHub, just as Go
does it.
Another useful feature that I thought about is would be "bundling", i.e. replacing and inlining all imports, in order, with actual code. This would be great for distributing, since you could use all the features you want and just move/upload a single script file that has all of the functionality embedded.
Which are the most important to port first?
bashdb
for debugging would be really useful.Thoughts?
Aliases are simply not supported by the legacy Bourne shell which predates functions. There is no point trying to define and execute an alias under /sbin/sh or /bin/sh when running Solaris 10 and older. The Solution again is to determine the current OS and decide whether to use the Alias or Function.
Possible incomplete solution, declare if older bash detected.
if [[ "${BASH_VERSION:0:1}" -lt 4 ]] ; then
P="x"
declare -${P} import="System::Import"
declare -${P} source="__oo__allowFileReloading=true System::ImportOne"
declare -${P} .="__oo__allowFileReloading=true System::ImportOne"
else
P="g"
alias import="System::Import"
alias source="__oo__allowFileReloading=true System::ImportOne"
alias .="__oo__allowFileReloading=true System::ImportOne"
fi
Replace import with ${import:-import}
Should use import if value not null or literal "import" if null and alias is available.
Side issue:
declare -${P} .="__oo__allowFileReloading=true System::ImportOne" causes error: .../lib/oo-bootstrap.sh: line 11: declare: `.=__oo__allowFileReloading=true System::ImportOne': not a valid identifier
I'm sure I could hack away at this but it seems that there's a hold up here that's preventing this from running just out of the box (directly cloned, run oo.sh) as a simple smoke test.
[themarmot@bq bash-oo-framework] :) ./oo.sh
/Users/themarmot/Projects/buyerquest/itops/nextgen/terraform-dev/bash-oo-framework/lib/oo-framework.sh: line 47: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
/Users/themarmot/Projects/buyerquest/itops/nextgen/terraform-dev/bash-oo-framework/lib/oo-framework.sh: line 48: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
/Users/themarmot/Projects/buyerquest/itops/nextgen/terraform-dev/bash-oo-framework/lib/oo- framework.sh: line 49: declare: -g: invalid option
declare: usage: declare [-afFirtx] [-p] [name[=value] ...]
/Users/themarmot/Projects/buyerquest/itops/nextgen/terraform-dev/bash-oo-framework/lib/oo-framework.sh: line 16: /system/*.sh: No such file or directory
Hi all!
As the title says, util/exception.sh shows stack trace as expected but don't exit on Ctrl+C
.
The script just keeps running, just as if I have pressed Enter
.
Is this a bug? A incorrect implementation of my part?
when I execute this code, most of part goes good, but this should not be displayed
were
also printed out.
I have no idea for this, so note here.
Hi Bazyli,
after you resolved #7, I'm running into another problem:
✘ UNCAUGHT EXCEPTION: Manually invoked
➦ Unable to load /src/bash-oo-framework/lib/types/ui/color.sh [06_system.sh:14]
✘ source "$libPath" || throw "Unable to load $libPath" [06_system.sh:14]
➦ System.LoadFile "$file" [06_system.sh:66]
➦ System.Import [oo.sh:5]
✘ import lib/types/ui [oo.sh:5]
Thanks.
Is there are way to use custom exit code?
#!/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
exit 1
$ ./your-script.sh; echo $?
0
Exception::CleanUp()
#!/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
Exception::CleanUp() {
local exitVal=$?
rm -f $__oo__storedExceptionLineFile $__oo__storedExceptionSourceFile $__oo__storedExceptionBacktraceFile $__oo__storedExceptionFile || exit 100
exit $exitVal
}
exit 1
$ ./your-script.sh; echo $?
1
#!/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
Exception::CleanUp() {
local exitVal=$?
rm -f $__oo__storedExceptionLineFile $__oo__storedExceptionSourceFile $__oo__storedExceptionBacktraceFile $__oo__storedExceptionFile || exit 10
exit $exitVal
}
class:Webhook() {
Webhook.gitlab() {
echo "GITLAB"
}
Webhook.handle() {
[string] id
case "$id" in
gitlab)
this $id
;;
*)
echo "Error"
exit 1
;;
esac
}
}
Type::Initialize Webhook
Webhook webhook
$var:webhook handle $1
$ ./your-script.sh gitlab; echo $?
GITLAB
0
$ ./your-script.sh slack; echo $?
Error
0
Use of hardcoded names referring to world-writable locations, ie. /tmp/stored_exception
, mean that an attacker can create symlinks to a file they don't themselves have write privileges to in such a location, and rely on separate program using the infinity framework to overwrite that symlink's target.
(See also concurrency issues).
The following error occurred
boolean trueVar=true
$var:trueVar toString #true
boolean falseVar=false
$var:falseVar toString #UNCAUGHT EXCEPTION: toString
Is it a bug? Or is my implementation incorrect?
Hi,
I would like to start using this framework instead of log4sh and I want to kindly ask you if there is any example or if somebody can guide me on how to log to a file, syslog or send the logs thru email?
Thank you.
I wrote a file main_menu.sh which used: import lib/* human.sh
and then I added the example usage of human as in the README but it didn't work:
✘ UNCAUGHT EXCEPTION: Method Human.name is not defined.
➦ Method Human.name is not defined. [type.sh:161]
✘ e="Method $methodName is not defined." throw [type.sh:161]
➦ Type::InjectThisResolutionIfNeeded "$type.$method" [type.sh:417]
local resultString=$(__return_self_and_result=true ➦ Type::ExecuteMethod "$type" "$variableName" "$method" "${params[@]}" || { local falseBool="${__primitive_extension_fingerprint__boolean}:false"; __return_self_and_result=true @return falseBool $variableName; }) [type.sh:435]
➦ Type::RunCurrentStack [type.sh:676]
eval "${__oo__variableMethodPrefix}${variableName}() { ➦ Type::Handle
➦ A04FB7D7594E479B8CD8D90C5014E37A:Mark [main_menu.sh:51]
✘ $var:Mark name = 'Mark' [main_menu.sh:51]
Is this a bug or am I misunderstanding how to use this?
GNU bash, version 4.4.12(1)-release (x86_64-unknown-linux-gnu)
Commit hash: 903fd74
While I tried importing my script, this error has been occurred:
✘ UNCAUGHT EXCEPTION: Undefined command (throw)
➦ Undefined command [oo-bootstrap.sh:84]
✘ System::SourcePath "${__oo__path}/${libPath}" "$@" || e="Cannot import $libPath" throw [oo-bootstrap.sh:84]
➦ System::ImportOne "$libPath" [oo-bootstrap.sh:96]
➦ System::Import [laun.sh:9]
✘ import launsh_lib/keys [laun.sh:9]
( launsh.sh
and launsh_lib/*
is mine)
From my research, I figured out that throw
was treated as exit_code
in command_not_found_handle
:
# piece of result of 'bash -x laun.sh`
+(oo-bootstrap.sh:89): System::ImportOne(): throw
+(exception.sh:30): command_not_found_handle(): local 'IFS=
'
+(exception.sh:33): command_not_found_handle(): [[ throw = \(\ \s\e\t\ \-*\;\ \t\r\u\e* ]]
+(exception.sh:38): command_not_found_handle(): Exception::CustomCommandHandler throw
+(exception.sh:17): Exception::CustomCommandHandler(): return 1
+(exception.sh:38): command_not_found_handle(): true
+(exception.sh:40): command_not_found_handle(): local exit_code=throw
It's strange because exit_code
should be $1
, not ${FUNCNAME[0]}
.
In this time, exit_code
should be empty.
Source:
bash-oo-framework/lib/util/exception.sh
Line 40 in 903fd74
Actually, this is strange too:
bash-oo-framework/lib/util/exception.sh
Line 33 in 903fd74
$*
is expanded to throw
)
Unfortunately, I have no idea to solve this, so I post it.
the minimum example code:
#!/usr/bin/env bash
source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"
import util/log util/exception
import file_not_exist # try to import non-exist file
echo 'hello!'
My first attempt to use this project failed.
#!/bin/bash
source "$( cd "${BASH_SOURCE[0]%/*}" && pwd )/lib/oo-bootstrap.sh"
import util/exception
ta() {
touch /untouchable
}
ta
running it:
$ /t/bash-oo-framework/x.sh
touch: cannot touch '/untouchable': Permission denied
! Press [CTRL+C] to exit or [Return] to continue execution.
I'm on bash 4.3.48(1)-release, and for this project, 903fd74
I am in.the process of incorporating this framework to a project of mine. I used to have a file full of color definitions in the form of variables. I saw that you provide colors as aliases that use echo. Is there a benefit in doing that? My (naive) intuition that variable should be even a little faster.
ubuntu 14.04 with GNOME Terminal 3.6.2.
possible cause:
tput colors
at Colors.sh line 1 returns '8' even if gnome-ternimal is capable of 256 colors.
This stackoverflow post outlines a different method of using namedParameters than the readme and seems to be correct. Readme could be updated to match.
https://stackoverflow.com/questions/6212219/passing-parameters-to-a-bash-function
...but rather forces -e
to be unset when leaving a try block, regardless of its prior value.
I’m curious because I’d love to try this out as a heavy oh my zsh user.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.