Skip to content

Commit 5ef2f5d

Browse files
Use EnvironmentFromContextOrLoad for consistent error handling
- Replace LoadEnvironment with ignored errors with EnvironmentFromContextOrLoad - Ensures consistent pattern across all environment loading fallbacks - Addresses PR #2 review comments
1 parent 1e75e4b commit 5ef2f5d

4 files changed

Lines changed: 5 additions & 5 deletions

File tree

cmd/diagnostics/status.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func runStatus(cmd *cobra.Command, args []string) error {
4848

4949
// Fallback: Load environment if not already in context (e.g., in tests)
5050
if env == nil {
51-
env, _ = utils.LoadEnvironment(cmd.Context())
51+
env = utils.EnvironmentFromContextOrLoad(cmd.Context())
5252
}
5353

5454
// Header

cmd/shell/prompt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func isGoProject() bool {
223223
// Use manager API for consistent parsing
224224
if utils.PathExists(config.ToolVersionsFileName) {
225225
cfg := config.Load()
226-
env, _ := utils.LoadEnvironment(context.Background())
226+
env := utils.EnvironmentFromContextOrLoad(context.Background())
227227
mgr := manager.NewManager(cfg, env)
228228
_ = cfg // unused but required by SetupContext
229229

cmd/shims/sh-rehash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func runShRehash(cmd *cobra.Command, args []string) error {
4242

4343
// Fallback: Load environment if not already in context (e.g., in tests)
4444
if env == nil {
45-
env, _ = utils.LoadEnvironment(cmd.Context())
45+
env = utils.EnvironmentFromContextOrLoad(cmd.Context())
4646
}
4747

4848
// Determine shell type

internal/cmdutil/helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ func GetContexts(cmd *cobra.Command, keys ...any) *CmdContext {
8080
result.Config = config.Load()
8181
}
8282
if result.Environment == nil {
83-
result.Environment, _ = utils.LoadEnvironment(ctx)
83+
result.Environment = utils.EnvironmentFromContextOrLoad(ctx)
8484
}
8585
result.Manager = manager.NewManager(result.Config, result.Environment)
8686
}
8787
case utils.EnvironmentContextKey:
8888
result.Environment = utils.EnvironmentFromContext(ctx)
8989
// Fallback for tests that don't set up context
9090
if result.Environment == nil {
91-
result.Environment, _ = utils.LoadEnvironment(ctx)
91+
result.Environment = utils.EnvironmentFromContextOrLoad(ctx)
9292
}
9393
}
9494
}

0 commit comments

Comments
 (0)