Skip to content

Fix orb init failing when orb-publishing context already exists#1193

Open
nanophate wants to merge 1 commit intoCircleCI-Public:mainfrom
nanophate:fix/orb-init-context-already-exists
Open

Fix orb init failing when orb-publishing context already exists#1193
nanophate wants to merge 1 commit intoCircleCI-Public:mainfrom
nanophate:fix/orb-init-context-already-exists

Conversation

@nanophate
Copy link
Copy Markdown

@nanophate nanophate commented Mar 17, 2026

Summary

  • Fixes a string mismatch in initOrb that causes circleci orb init to fail with "Error: A context already exists with this name" when the orb-publishing context already exists in the organization (e.g., created by a teammate).
  • The existing check looked for "A context named orb-publishing already exists", which doesn't match what the REST API ("A context already exists with this name") or GQL API ("Error creating context: ALREADY_EXISTS") actually returns.
  • Replaced with a case-insensitive check for "already exists" so the CLI gracefully continues regardless of API path.

Fixes #1192

Test plan

  • Run circleci orb init in an org where orb-publishing context already exists, select "Yes, set up a publishing context with my API key" — should print `orb-publishing` context already exists, continuing on and proceed
  • Run circleci orb init in an org with no existing orb-publishing context — should create the context normally
  • Run circleci orb init and select "No, I'll do this later" — should skip context creation as before

The error string check in initOrb used a hardcoded message that no
longer matches what the REST API (or GQL API) returns when a context
with the same name already exists. Use a case-insensitive check for
"already exists" so the CLI gracefully continues regardless of which
API path is used.

Fixes CircleCI-Public#1192

Made-with: Cursor
err = contextAPI.CreateContext("orb-publishing")
if err != nil {
if strings.Contains(err.Error(), "A context named orb-publishing already exists") {
if strings.Contains(strings.ToLower(err.Error()), "already exists") {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you might need another case here in order to match the error returned by the graphql endpoint? The example you provided has an underscore in that string: "Error creating context: ALREADY_EXISTS"

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.

circleci orb init fails with "A context already exists with this name" when orb-publishing context already exists

2 participants