Skip to content

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

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

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

@Rahulatram321 Rahulatram321 commented May 18, 2026

Copy link
Copy Markdown
Contributor

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!

@Vaishnav88sk

Copy link
Copy Markdown

please pass the DCO

Signed-off-by: rahulAtram <rahulatram0226@gmail.com>
@Rahulatram321
Rahulatram321 force-pushed the fix/context-nil-guard branch from 0fb7f62 to 0b50f24 Compare May 23, 2026 19:11
@Rahulatram321

Copy link
Copy Markdown
Contributor Author

please pass the DCO

Thanks for the review and for flagging this.

I’ve updated this PR by rewriting the commit(s) with DCO sign-off and force-pushed the branch.
Each commit now includes:

Signed-off-by: Rahul Atram rahulatram0226@gmail.com

I also kept the scope unchanged to only the intended fix in this PR.
Could you please recheck when the DCO status refreshes? Thanks again.

@Rahulatram321

Rahulatram321 commented May 23, 2026 via email

Copy link
Copy Markdown
Contributor Author

@Caesarsage

Copy link
Copy Markdown
Contributor

Thanks! The context command on master now nil-guards the local config before use, so this is superseded. Appreciate the effort.

Suggest closing this

@Harsh4902

Copy link
Copy Markdown
Member

Thanks @Rahulatram321 and sorry we couldn't merge this erlier. As it's already tackled on master, we have to close this.

@Harsh4902 Harsh4902 closed this Aug 19, 2026
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.

4 participants