remove duplicate tempdir pkg
Some checks failed
Lint / golangci-lint (push) Failing after 10m28s
Declarative Tests / test (push) Failing after 12s
Declarative Tests / build-fedora (push) Failing after 1m57s
Declarative Tests / build-ubuntu-focal (push) Successful in 1m50s

This commit is contained in:
Matthew Rich 2024-09-27 03:18:13 +00:00
parent 88fe584fe1
commit d815419c7b
5 changed files with 19 additions and 8 deletions

View File

@ -12,7 +12,7 @@ import (
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"fmt" "fmt"
"decl/tests/tempdir" "decl/internal/tempdir"
"archive/tar" "archive/tar"
"io" "io"
"log" "log"

View File

@ -7,7 +7,7 @@ import (
"log/slog" "log/slog"
"os" "os"
"testing" "testing"
"decl/tests/tempdir" "decl/internal/tempdir"
"decl/internal/folio" "decl/internal/folio"
"errors" "errors"
) )

View File

@ -153,8 +153,13 @@ func (d *Declaration) Resource() data.Resource {
func (d *Declaration) Apply(stateTransition string) (result error) { func (d *Declaration) Apply(stateTransition string) (result error) {
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
slog.Info("Declaration.Apply()", "error", r, "stacktrace", string(debug.Stack())) slog.Debug("Declaration.Apply()", "stacktrace", string(debug.Stack()))
result = fmt.Errorf("%s", r) 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 { if result != nil {
d.Error = result.Error() d.Error = result.Error()
@ -192,12 +197,13 @@ func (d *Declaration) Apply(stateTransition string) (result error) {
return result return result
} }
} }
result = stater.Trigger("read") result = stater.Trigger("read")
currentState := stater.CurrentState() currentState := stater.CurrentState()
switch currentState { switch currentState {
case "create", "present": case "create", "present":
default: 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 return result

View File

@ -8,6 +8,7 @@ import (
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"io" "io"
"io/fs" "io/fs"
_ "os"
"log/slog" "log/slog"
"net/url" "net/url"
"github.com/sters/yaml-diff/yamldiff" "github.com/sters/yaml-diff/yamldiff"
@ -275,9 +276,11 @@ func (d *Document) Apply(state string) error {
if d.ResourceDeclarations[idx].Requires.Check() { if d.ResourceDeclarations[idx].Requires.Check() {
if e := d.ResourceDeclarations[idx].Apply(state); e != nil { // fmt.Fprintf(os.Stderr, "%s: ", d.ResourceDeclarations[idx].Resource().URI())
slog.Error("Document.Apply() error applying resource", "index", idx, "uri", 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() d.ResourceDeclarations[idx].Error = e.Error()
switch d.ResourceDeclarations[idx].OnError.GetStrategy() { switch d.ResourceDeclarations[idx].OnError.GetStrategy() {
case OnErrorStop: case OnErrorStop:
@ -285,6 +288,8 @@ func (d *Document) Apply(state string) error {
case OnErrorFail: case OnErrorFail:
d.failedResources++ d.failedResources++
} }
} else {
// fmt.Fprintf(os.Stderr, "%s\n", state)
} }
} else { } else {
d.ResourceDeclarations[idx].Error = fmt.Sprintf("Constraint failure: %s", d.ResourceDeclarations[idx].Requires) d.ResourceDeclarations[idx].Error = fmt.Sprintf("Constraint failure: %s", d.ResourceDeclarations[idx].Requires)

View File

@ -7,7 +7,7 @@ import (
"testing" "testing"
"os" "os"
"log/slog" "log/slog"
"decl/tests/tempdir" "decl/internal/tempdir"
_ "path/filepath" _ "path/filepath"
) )