Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion cmd/wfctl/infra_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,16 @@ func isIaCNotFound(err error) bool {
return true
}
var platformNotFound *platform.ResourceNotFoundError
return errors.As(err, &platformNotFound)
if errors.As(err, &platformNotFound) {
return true
}
// gRPC fallback: typed adapter loses sentinel identity across the
// wire. The message survives as a wrapped string. Match on the
// literal ErrResourceNotFound.Error() value so adoption can still
// detect "not present yet, fall back to create" against remote
// plugin drivers (workflow-plugin-digitalocean v2+ database
// adoption is the original repro path).
return strings.Contains(err.Error(), interfaces.ErrResourceNotFound.Error())
}

func resourceStateFromLiveOutput(spec interfaces.ResourceSpec, providerType string, live *interfaces.ResourceOutput) (interfaces.ResourceState, error) {
Expand Down
41 changes: 41 additions & 0 deletions cmd/wfctl/infra_apply_isiacnotfound_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"errors"
"fmt"
"testing"

"github.com/GoCodeAlone/workflow/interfaces"
)

// TestIsIaCNotFound_TypedSentinel confirms native wrapping still works.
func TestIsIaCNotFound_TypedSentinel(t *testing.T) {
err := fmt.Errorf("database %q: %w", "multisite-pg", interfaces.ErrResourceNotFound)
if !isIaCNotFound(err) {
t.Error("expected typed sentinel to be detected")
}
}

// TestIsIaCNotFound_GRPCStringFallback is the regression test for the
// gocodealone-multisite deploy: the typed gRPC adapter strips sentinel
// identity, leaving only the wrapped error string. Adoption is meant
// to be "look up, fall back to create" — without this fallback the
// remote plugin's not-found returns made apply-prereq fail every run.
func TestIsIaCNotFound_GRPCStringFallback(t *testing.T) {
grpcErr := errors.New(`rpc error: code = Unknown desc = database "multisite-pg": iac: resource not found`)
if !isIaCNotFound(grpcErr) {
t.Error("expected gRPC-flattened not-found to be detected via string match")
}
}

func TestIsIaCNotFound_NilSafe(t *testing.T) {
if isIaCNotFound(nil) {
t.Error("nil err must not be reported as not-found")
}
}

func TestIsIaCNotFound_OtherErrorsIgnored(t *testing.T) {
if isIaCNotFound(errors.New("permission denied")) {
t.Error("non-matching error must not be reported as not-found")
}
}
Loading