Skip to content

fix(context): guard nil local config before context switch#406

Open
Rahulatram321 wants to merge 1 commit into
microcks:masterfrom
Rahulatram321:fix/context-nil-guard
Open

fix(context): guard nil local config before context switch#406
Rahulatram321 wants to merge 1 commit into
microcks:masterfrom
Rahulatram321:fix/context-nil-guard

Conversation

@Rahulatram321
Copy link
Copy Markdown

@Rahulatram321 Rahulatram321 commented May 18, 2026

Description

This PR fixes a crash path in the microcks context command when no local config exists yet.

Problem

When running microcks context <context-name> on a fresh machine (or after config cleanup), localCfg can be nil.
The command dereferences localCfg (localCfg.CurrentContext) without a nil guard, which can lead to a nil pointer panic instead of a user-friendly message.

Changes

  • Added a defensive localCfg == nil check in cmd/context.go before first dereference in the context-switch flow.
  • Preserved current behavior for:
    • microcks context (no args): still lists contexts / prints existing output path.
    • microcks context --delete ...: unchanged.

Result

  • No panic when config is missing.
  • Users now get a clear, deterministic error path instead of a runtime crash.

@github-actions
Copy link
Copy Markdown

👋 @Rahulatram321

Welcome to the Microcks community! 💖

Thanks and congrats 🎉 for opening your first pull request here! Be sure to follow the pull request template or please update it accordingly.

Hope you have a great time there!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant