Skip to content

Cannot list or delete contexts when an orphaned or invalid context exists in local config #631

Open

Description

@aryarathoree

Describe the bug

When the local configuration file contains an orphaned or broken context (for example, referencing a server or user that no longer exists in servers or users), the CLI becomes difficult to recover:

  1. microcks context (list) aborts completely, preventing users from viewing even valid contexts.
  2. microcks context <name> --delete also fails before removing the context, making it impossible to clean up the broken entry through the CLI.

As a result, users are forced to manually locate and edit ~/.config/microcks/config to remove the invalid YAML entry.

Expected behavior

  1. microcks context should list all defined contexts, displaying the server reference from contextRef.Server without failing when the full context resolution cannot find the associated server or user.
  2. microcks context <name> --delete should remove the context reference directly from contexts, without requiring ResolveContext(context) to succeed first.
  3. Garbage collection of unreferenced servers or users during context deletion should be idempotent. If a server or user is already missing, the command should continue without failing or aborting the configuration save.

Actual behavior

  • Running microcks context fails with:

    Error: resolving context "<context-name>": Server '<server-name>' undefined
    

    As a result, no contexts are displayed to the user.

  • Running microcks context <context-name> --delete fails with:

    Error: Server '<server-name>' undefined
    

    The context is not deleted, and the configuration file on disk remains unchanged.

How to Reproduce?

Steps to Reproduce

  1. Create a configuration file (e.g. /tmp/test-config or ~/.config/microcks/config) containing one valid context and one orphaned context referencing a non-existent server:

    current-context: prod
    contexts:
      - name: prod
        server: https://microcks-prod.example.com
        user: prod-user
      - name: broken-ctx
        server: https://missing-server.example.com
        user: prod-user
    servers:
      - server: https://microcks-prod.example.com
    users:
      - name: prod-user
  2. Attempt to list contexts:

    microcks context --config /tmp/test-config

    Result: The command aborts with:

    Error: resolving context "broken-ctx": Server 'https://missing-server.example.com' undefined
    

    No contexts are displayed, including the valid prod context.

  3. Attempt to delete the broken context:

    microcks context broken-ctx --delete --config /tmp/test-config

    Result: The command aborts with:

    Error: Server 'https://missing-server.example.com' undefined
    

    The broken-ctx entry remains in the configuration file.

Microcks version or git rev

master branch (HEAD)

Install method (docker-compose, helm chart, operator, docker-desktop extension,...)

Built from source (make build-local) / binary release

Additional information

No response

Activity

  1. AyushmanMohapatra015 commented on Nov 19, 2026

    @AyushmanMohapatra015

    I reproduced this on current master (d3fced2) using a temporary config with one valid context and one context referencing a missing server.

    Listing contexts aborts when resolving the broken entry, and deleting that entry fails before RemoveContext is reached, leaving the configuration unchanged.

    I’d like to fix both recovery paths and add regression tests covering listing and deleting an orphaned context. Would this approach be welcome?

  2. aryarathoree commented on Nov 19, 2026

    @aryarathoree
    ContributorAuthor

    @AyushmanMohapatra015 actually I am waiting for the maintainers to review the issue and then will be working on it.

  3. AyushmanMohapatra015 commented on Nov 19, 2026

    @AyushmanMohapatra015

    Sure @aryarathoree thanks for lmk !!

  4. aryarathoree commented on Nov 19, 2026

    @aryarathoree
    ContributorAuthor

    hey @Caesarsage , would love to know your take on this issue

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions