commit bdb9b00ff68266b7ed28fa86bc0637c9dbbbcf4f
parent 9e34c4f1c556c3d873b0df6d75c3707ae7fdef99
Author: lash <dev@holbrook.no>
Date: Sun, 23 Apr 2023 10:39:07 +0100
Introduce resource result status code
Signed-off-by: lash <dev@holbrook.no>
Diffstat:
3 files changed, 17 insertions(+), 5 deletions(-)
diff --git a/resource/resource.go b/resource/resource.go
@@ -7,6 +7,7 @@ import (
// Result contains the results of an external code operation.
type Result struct {
Content string // content value for symbol after execution.
+ Status int // application defined status code which can complement error returns
FlagSet []uint32 // request caller to set error flags at given indices.
FlagReset []uint32 // request caller to reset error flags at given indices.
}
diff --git a/vm/runner.go b/vm/runner.go
@@ -13,17 +13,28 @@ import (
// ExternalCodeError indicates an error that occurred when resolving an external code symbol (LOAD, RELOAD).
type ExternalCodeError struct {
sym string
+ code int
err error
}
// NewExternalCodeError creates a new ExternalCodeError.
-func NewExternalCodeError(sym string, err error) error {
- return ExternalCodeError{sym, err}
+func NewExternalCodeError(sym string, err error) *ExternalCodeError {
+ return &ExternalCodeError{
+ sym: sym,
+ err: err,
+ }
+}
+
+func(e *ExternalCodeError) WithCode(code int) *ExternalCodeError {
+ e.code = code
+ return e
}
// Error implements error interface
func(e ExternalCodeError) Error() string {
- return fmt.Sprintf("[%s] %v", e.sym, e.err)
+ //return fmt.Sprintf("[%s] %v", e.sym, e.err)
+ Logg.Errorf("external code error: %v", e.err)
+ return fmt.Sprintf("error %v:%v", e.sym, e.code)
}
// Vm holds sub-components mutated by the vm execution.
@@ -526,7 +537,7 @@ func(vm *Vm) refresh(key string, rs resource.Resource, ctx context.Context) (str
if perr != nil {
panic(err)
}
- return "", NewExternalCodeError(key, err)
+ return "", NewExternalCodeError(key, err).WithCode(r.Status)
}
for _, flag := range r.FlagSet {
if !state.IsWriteableFlag(flag) {
diff --git a/vm/runner_test.go b/vm/runner_test.go
@@ -701,7 +701,7 @@ func TestLoadError(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- expect := `[aiee] uh-oh spaghetti'ohs
+ expect := `error aiee:0
0:repent`
if r != expect {
t.Fatalf("expected: \n\t%s\ngot:\n\t%s", expect, r)