diff --git a/cli_test.go b/cli_test.go index 3b5c197..2e2b8cd 100644 --- a/cli_test.go +++ b/cli_test.go @@ -12,7 +12,7 @@ import ( "net/http" "net/http/httptest" "fmt" - "decl/tests/tempdir" + "decl/internal/tempdir" "archive/tar" "io" "log" diff --git a/internal/builtin/builtin_test.go b/internal/builtin/builtin_test.go index 241ce38..a06e725 100644 --- a/internal/builtin/builtin_test.go +++ b/internal/builtin/builtin_test.go @@ -7,7 +7,7 @@ import ( "log/slog" "os" "testing" - "decl/tests/tempdir" + "decl/internal/tempdir" "decl/internal/folio" "errors" ) diff --git a/internal/folio/declaration.go b/internal/folio/declaration.go index 136170a..2882c63 100644 --- a/internal/folio/declaration.go +++ b/internal/folio/declaration.go @@ -153,8 +153,13 @@ func (d *Declaration) Resource() data.Resource { func (d *Declaration) Apply(stateTransition string) (result error) { defer func() { if r := recover(); r != nil { - slog.Info("Declaration.Apply()", "error", r, "stacktrace", string(debug.Stack())) - result = fmt.Errorf("%s", r) + slog.Debug("Declaration.Apply()", "stacktrace", string(debug.Stack())) + slog.Info("Declaration.Apply()", "error", r, "resourceerror", d.Error) + if d.Error != "" { + result = fmt.Errorf("%s - %s", r, d.Error) + } else { + result = fmt.Errorf("%s", r) + } } if result != nil { d.Error = result.Error() @@ -192,12 +197,13 @@ func (d *Declaration) Apply(stateTransition string) (result error) { return result } } + result = stater.Trigger("read") currentState := stater.CurrentState() switch currentState { case "create", "present": default: - return fmt.Errorf("Failed to create resource: %s - state: %s, err: %s", d.URI(), currentState, result) + return fmt.Errorf("Failed to create resource: %s - state: %s, err: %s", d.URI(), currentState, d.Error) } } return result diff --git a/internal/folio/document.go b/internal/folio/document.go index 1f6bbaf..88d0579 100644 --- a/internal/folio/document.go +++ b/internal/folio/document.go @@ -8,6 +8,7 @@ import ( "gopkg.in/yaml.v3" "io" "io/fs" +_ "os" "log/slog" "net/url" "github.com/sters/yaml-diff/yamldiff" @@ -275,9 +276,11 @@ func (d *Document) Apply(state string) error { if d.ResourceDeclarations[idx].Requires.Check() { - if e := d.ResourceDeclarations[idx].Apply(state); e != nil { - slog.Error("Document.Apply() error applying resource", "index", idx, "uri", d.ResourceDeclarations[idx].Resource().URI()) +// fmt.Fprintf(os.Stderr, "%s: ", d.ResourceDeclarations[idx].Resource().URI()) + if e := d.ResourceDeclarations[idx].Apply(state); e != nil { +// slog.Error("Document.Apply() error applying resource", "index", idx, "uri", d.ResourceDeclarations[idx].Resource().URI(), "error", e) +// fmt.Fprintf(os.Stderr, "%s\n", "error") d.ResourceDeclarations[idx].Error = e.Error() switch d.ResourceDeclarations[idx].OnError.GetStrategy() { case OnErrorStop: @@ -285,6 +288,8 @@ func (d *Document) Apply(state string) error { case OnErrorFail: d.failedResources++ } + } else { +// fmt.Fprintf(os.Stderr, "%s\n", state) } } else { d.ResourceDeclarations[idx].Error = fmt.Sprintf("Constraint failure: %s", d.ResourceDeclarations[idx].Requires) diff --git a/internal/fs/fs_test.go b/internal/fs/fs_test.go index 9876232..5f26daf 100644 --- a/internal/fs/fs_test.go +++ b/internal/fs/fs_test.go @@ -7,7 +7,7 @@ import ( "testing" "os" "log/slog" - "decl/tests/tempdir" + "decl/internal/tempdir" _ "path/filepath" )