Skip to content

Sealed constructors return a typed nil on the error path: DiscoverResource wraps a nil struct pointer in a non-nil interface #807

Closed

Description

@David-Noble-at-work

Found sealing file (#645), present since phase 1.

Every sealed provider's exported constructor returns the interface by delegating to the struct-returning form:

func DiscoverResource(runtimeEnvironment *op.RuntimeEnvironment, value any) (Resource, error) {
	return discoverResource(runtimeEnvironment, value)
}

discoverResource returns (*resource, error). On its error path the *resource is nil, and Go converts that
nil pointer to a non-nil Resource interface value holding a nil pointer. A caller that checks err first is
unaffected; one that checks resource != nil, or a framework path that receives the pair, sees a resource that
is not there.

Affected: service, git, appnet, json, yaml, mem, function, pkg — every provider sealed in phases
1–6. file (phase 7) returns an explicit nil, err and is the shape to copy:

	built, err := discoverRegular(runtimeEnvironment, value)
	if err != nil {
		return nil, err
	}
	return built, nil

Acceptance

  • every exported sealed constructor returns a literal nil interface on its error path
  • a unit test per provider asserts resource == nil when err != nil

Placement: its own worktree after #645, or folded into #649, whose sweep touches the same files.

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions