Golang/ Javascript plugins: make errors permanent (#17631)

This commit is contained in:
andig 2024-12-07 14:22:06 +01:00 • committed by GitHub
parent b881bfcf5a
commit 0f5ad83750
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 14 additions and 2 deletions

View file

@ -6,6 +6,7 @@ import (
"fmt"
"reflect"
"github.com/cenkalti/backoff/v4"
"github.com/evcc-io/evcc/provider/golang"
"github.com/evcc-io/evcc/util"
"github.com/traefik/yaegi/interp"
@ -167,6 +168,7 @@ func (p *Go) evaluate() (res any, err error) {
if r := recover(); r != nil {
err = fmt.Errorf("panic: %v", r)
}
err = backoff.Permanent(err)
}()
v, err := p.vm.Eval(p.script)

View file

@ -2,7 +2,9 @@ package provider
import (
"context"
"fmt"
"github.com/cenkalti/backoff/v4"
"github.com/evcc-io/evcc/provider/javascript"
"github.com/evcc-io/evcc/util"
"github.com/robertkrimen/otto"
@ -147,7 +149,14 @@ func (p *Javascript) handleSetter(param string, val any) error {
return transformOutputs(p.out, v)
}
func (p *Javascript) evaluate() (any, error) {
func (p *Javascript) evaluate() (res any, err error) {
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("panic: %v", r)
}
err = backoff.Permanent(err)
}()
v, err := p.vm.Eval(p.script)
if err != nil {
return nil, err

View file

@ -9,6 +9,7 @@ import (
"strings"
xj "github.com/basgys/goxml2json"
"github.com/cenkalti/backoff/v4"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/jq"
"github.com/itchyny/gojq"
@ -185,7 +186,7 @@ func (p *Pipeline) Process(in []byte) ([]byte, error) {
if p.jq != nil {
v, err := jq.Query(p.jq, b)
if err != nil {
return b, err
return b, backoff.Permanent(err)
}
b = []byte(fmt.Sprintf("%v", v))
}