Skip to content

Commit 8ed2296

Browse files
ostermanclaude
andcommitted
Use sentinel error for nil command provider
Replace dynamic error with sentinel error ErrCommandNil for proper error wrapping and type-safe error checking. Changes: - Import errors package in cmd/internal/registry.go - Use fmt.Errorf with %w to wrap ErrCommandNil sentinel error - Import errors package in registry_test.go - Update test to use errors.Is() for sentinel error checking - Verify error message includes provider name for debugging This follows Atmos error handling conventions per CLAUDE.md: - All errors wrapped using static errors from errors/errors.go - Use errors.Is() for error checking - Use fmt.Errorf with %w for adding context 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bf0c81c commit 8ed2296

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

cmd/internal/registry.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"sync"
66

77
"github.com/spf13/cobra"
8+
9+
errUtils "github.com/cloudposse/atmos/errors"
810
)
911

1012
// registry is the global command registry instance.
@@ -74,7 +76,7 @@ func RegisterAll(root *cobra.Command) error {
7476
for name, provider := range registry.providers {
7577
cmd := provider.GetCommand()
7678
if cmd == nil {
77-
return fmt.Errorf("command provider %s returned nil command", name)
79+
return fmt.Errorf("%w: provider %s", errUtils.ErrCommandNil, name)
7880
}
7981

8082
root.AddCommand(cmd)

cmd/internal/registry_test.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package internal
22

33
import (
4+
"errors"
45
"fmt"
56
"testing"
67

78
"github.com/spf13/cobra"
89
"github.com/stretchr/testify/assert"
910
"github.com/stretchr/testify/require"
11+
12+
errUtils "github.com/cloudposse/atmos/errors"
1013
)
1114

1215
// mockCommandProvider is a test implementation of CommandProvider.
@@ -154,7 +157,8 @@ func TestRegisterAllNilCommand(t *testing.T) {
154157

155158
err := RegisterAll(rootCmd)
156159
assert.Error(t, err)
157-
assert.Contains(t, err.Error(), "nil command")
160+
assert.True(t, errors.Is(err, errUtils.ErrCommandNil), "error should wrap ErrCommandNil")
161+
assert.Contains(t, err.Error(), "test", "error message should include provider name")
158162
}
159163

160164
func TestGetProviderNotFound(t *testing.T) {

0 commit comments

Comments
 (0)