fix(plugin/external): propagate plugin errors instead of swallowing as nil#515
Merged
Conversation
…s nil
The external plugin adapter's ModuleFactories returned bare nil on any
CreateModule failure (gRPC error OR plugin-reported error in
createResp.Error). Callers got no signal about WHY the factory failed —
just a generic "iac.provider factory returned nil" message that hid the
actual plugin diagnostic.
This was the diagnostic gap that hid two core-dump P1 schema mistakes
behind a generic message during the 2026-05-02 first-deploy attempt.
The plugin had returned "digitalocean: missing required config key
'token'", but the operator saw "factory returned nil".
Fix: when CreateModule fails (gRPC error OR createResp.Error), return
an *errorModule wrapping the underlying message. Same pattern already
used for configErr a few lines earlier — this just extends it to the
remote-create-fail path. Engine and wfctl callers already handle
errorModule, so this is a uniform convention rather than a contract
change. (StepFactories already propagates both error paths correctly.)
Add exported helpers AsModuleError + NewErrorModule so callers in other
packages can surface and simulate factory failures without depending on
the unexported errorModule type.
Caller in cmd/wfctl/deploy_providers.go: extract findIaCPluginDir +
plugin load + ModuleFactories into a loadIaCPlugin var (injectable for
tests). discoverAndLoadIaCProvider now calls external.AsModuleError to
detect the *errorModule before the nil check; surfaces the wrapped error
message. Bare-nil branch becomes a defensive backstop with "file an
issue" hint.
Regression invariant proven for both tests: with fix reverted,
TestModuleFactoriesPropagatesPluginError got nil (swallowed);
TestResolveIaCProviderSurfacesPluginError got wrong error
("does not support service invocation" instead of plugin message).
See docs/plans/2026-05-02-wfctl-bootstrap-diagnostics-design.md PR 2.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves diagnostics for external IaC plugins by ensuring plugin-reported CreateModule failures propagate as actionable errors (via a non-nil sentinel module) instead of being swallowed and later surfacing as generic “factory returned nil”/type assertion failures in wfctl.
Changes:
- Update
ExternalPluginAdapter.ModuleFactories()to return anerrorModule(carrying the underlying gRPC/plugin error) whenCreateModulefails or the plugin returns a non-emptyHandleResponse.Error. - Export
external.AsModuleError(modular.Module) errorandexternal.NewErrorModule(name, err) modular.Moduleso callers/tests can detect/simulate factory failures without referencing an unexported type. - Refactor wfctl IaC plugin discovery/load into an injectable
loadIaCPluginand ensurediscoverAndLoadIaCProviderchecksexternal.AsModuleErrorbefore the nil-module backstop.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| plugin/external/adapter.go | Propagates CreateModule failures via errorModule; adds exported helpers to detect/simulate factory errors. |
| plugin/external/adapter_test.go | Adds regression test ensuring plugin HandleResponse.Error is not swallowed as nil. |
| cmd/wfctl/deploy_providers.go | Makes IaC plugin load injectable and surfaces errorModule failures as clear user-facing errors. |
| cmd/wfctl/deploy_providers_test.go | Adds regression test ensuring wfctl returns the plugin’s diagnostic message when factory creation fails. |
⏱ Benchmark Results✅ No significant performance regressions detected. benchstat comparison (baseline → PR)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the diagnostic gap that hid two core-dump P1 schema mistakes behind a generic "factory returned nil" message during the 2026-05-02 deploy attempt (run 25244152181).
ExternalPluginAdapter.ModuleFactories()now returns an*errorModule(wrapping the actual plugin / gRPC error) instead of bare nil whenCreateModulefails.StepFactories()already propagated both error paths correctly — no change needed there.AsModuleError(modular.Module) errorandNewErrorModule(name, err) modular.Moduleexports so callers outside the package can surface and test factory failures without depending on the unexported type.ModuleFactories()into an injectableloadIaCPluginvar incmd/wfctl/deploy_providers.go.discoverAndLoadIaCProvidernow callsexternal.AsModuleErrorbefore the nil check; the bare-nil branch becomes a defensive backstop.Engine and wfctl both already handle
errorModuleon the configErr branch — this is a uniform convention extension, not a new contract.Test plan
TestModuleFactoriesPropagatesPluginError— fake gRPC client returnsHandleResponse.Error; asserts returned module is*errorModulewhose error contains the plugin's message.TestResolveIaCProviderSurfacesPluginError— injected factory returnsexternal.NewErrorModule; assertsdiscoverAndLoadIaCProviderreturns error wrapping the plugin message.plugin/external/...andcmd/wfctl/...test suites green.🤖 Generated with Claude Code