Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Allow custom "Known error" #4

Closed
BadWolf42 opened this issue Jun 28, 2022 · 8 comments · Fixed by #5
Closed

Enhancement: Allow custom "Known error" #4

BadWolf42 opened this issue Jun 28, 2022 · 8 comments · Fixed by #5
Labels
enhancement New feature or request

Comments

@BadWolf42
Copy link

Hello,

It would be nice to have the possibility to handle our own known errors as you do for apt, npm, etc.

For exemple, with a function like:
handle <error to grep> <found message> <command/function>
with in parameter the text error to grep in the log, the message to display when found and the command to fixit
it could be declared between each step (or each try ?) to be specific to a stp (or try) or before pre to be generic.

What do you think about it?

Bad

@NebzHB
Copy link
Owner

NebzHB commented Jun 28, 2022

Nice idea ! i like it !

handlers would need to be defined before "post" i guess, so anywhere between the "include" of the lib and the "post"

i'll think about it...

@NebzHB
Copy link
Owner

NebzHB commented Jun 28, 2022

if you feel comfortable with bash, don't hesitate to PR ;)

@NebzHB
Copy link
Owner

NebzHB commented Jun 28, 2022

here is my poc :

#preparation
touch myfile.txt
echo "hello world">myfile.txt

#in dependencies.sh
declare -A fix_handler
h=0
add_fix_handler () {
    fix_handler[$h,search]=$1
    fix_handler[$h,found]=$2
    fix_handler[$h,fix]=$3
    ((h++))
}
fix () {
    for (( i=0;i<h;i++ )); do
        echo "searching for ${fix_handler[$i,search]} in myfile.txt..."
        grep ${fix_handler[$i,search]} myfile.txt &>/dev/null
        if [ "$?" -eq 0 ];then
            echo ${fix_handler[$i,found]}
            ${fix_handler[$i,fix]}
        else
            echo "not found"
        fi
    done
}
post() {
    # ....
    fix
}


# in your dependencies
myfixWorld () {
    echo "fix my world"
}

myfixUniverse () {
    echo "fix my universe"
}

add_fix_handler "universe" "found my universe" myfixUniverse
add_fix_handler "world" "found my world" myfixWorld

post

@NebzHB
Copy link
Owner

NebzHB commented Jun 28, 2022

result :

searching for universe in myfile.txt...
not found
searching for world in myfile.txt...
found my world
fix my world

@NebzHB NebzHB added the enhancement New feature or request label Jun 28, 2022
@NebzHB
Copy link
Owner

NebzHB commented Jul 6, 2022

Did you had a chance to test it ?

@BadWolf42
Copy link
Author

Sorry not much time this week...

@NebzHB NebzHB linked a pull request Jul 17, 2022 that will close this issue
@NebzHB NebzHB closed this as completed in #5 Jul 17, 2022
@BadWolf42
Copy link
Author

Hello I just did a pre-stable dep-install check and got only errors:

''/..': No such file or directoryjMQTT/resources'$'
: No such file or directory/core/class/../../resources/install_apt.sh: line 8: /var/www/html/plugins/jMQTT/resources
': command not founds/jMQTT/core/class/../../resources/install_apt.sh: line 10: $'
': command not founds/jMQTT/core/class/../../resources/install_apt.sh: line 11: $'pre
': command not founds/jMQTT/core/class/../../resources/install_apt.sh: line 12: $'
/var/www/html/plugins/jMQTT/core/class/../../resources/install_apt.sh: line 64: syntax error: unexpected end of file

Dep file is: https://github.com/Domochip/jMQTT/blob/73cd97088abc02cad65dd6662798c50c42348d0e/resources/install_apt.sh

@BadWolf42
Copy link
Author

Please ignore, file was in WINDOWS vs Linux file format expected by bash...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants