Repository navigation
fix: support listing and deleting orphaned or invalid contexts (#631) - #641
Open
aryarathoree wants to merge 1 commit into
Open
aryarathoree wants to merge 1 commit into
aryarathoree wants to merge 1 commit into
Conversation
…cks#631) Resolve contexts gracefully when listing so that an orphaned or invalid context does not block viewing other valid contexts. Remove contexts directly in deleteContext without requiring full context resolution, and clean up unreferenced users and servers idempotently. Fixes microcks#631 Signed-off-by: Arya Rathore <aryarathoree@gmail.com>
aryarathoree
requested review from
Caesarsage,
Harsh4902,
lbroudoux and
yada
as code owners
November 25, 2026 12:23
Harsh4902
requested changes
Nov 26, 2026
Harsh4902
left a comment
Member
There was a problem hiding this comment.
@aryarathoree Please have a look on a couple of suggestions. Happy to merge after resolving them.
| } | ||
|
|
||
| if localCfg.IsEmpty() { | ||
| if localCfg.IsEmpty() && len(localCfg.Contexts) == 0 { |
Member
There was a problem hiding this comment.
IsEmpty() only checks servers, so this can still delete a config containing a local instance’s container ID. Could we coordinate this guard with #642 and test that deleting a context preserves the records needed to stop a running instance?
| if err != nil { | ||
| return errors.Wrap(errors.KindEnvironment, err) | ||
| } | ||
| targetContext := localCfg.Contexts[contextIndex] |
Member
There was a problem hiding this comment.
Could you add a CLI regression test with current-context: broken-ctx? The command calls ReadLocalConfig before dispatching, and that validates the current context. If its server or user is missing, both list and delete still fail before reaching the new code.
This branch was successfully deployed
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.
Resolve contexts gracefully when listing so that an orphaned or invalid context does not block viewing other valid contexts. Remove contexts directly in
deleteContextwithout requiring full context resolution, and clean up unreferenced users and servers idempotently.Fixes #631
Description
listMicrocksContextsincmd/context.goto construct summaries directly fromcontextRef.NameandcontextRef.ServerusingGetServerwhen available, rather than failing the entire listing loop withResolveContextif an orphaned context references an undefined server or user.deleteContextincmd/context.goto remove contexts directly fromlocalCfg.Contextswithout requiringResolveContext(context)to resolve first, enabling users to clean up broken contexts viamicrocks context <name> --delete.RemoveUser) and servers (RemoveServer) idempotent so that already-absent resources do not trigger fatal errors (errors.KindAPI) or prevent saving configuration changes.localCfg.IsEmpty()andlen(localCfg.Contexts) == 0.cmd/context_test.gocovering JSON and text context listing with orphaned entries, programmatic and CLI context deletion, and complete cleanup when deleting the sole context.