Skip to content

fix(cli): classify failures and stop panicking in the client library#489

Open
Caesarsage wants to merge 3 commits into
microcks:masterfrom
Caesarsage:pr1/classify-errors-and-depanic
Open

fix(cli): classify failures and stop panicking in the client library#489
Caesarsage wants to merge 3 commits into
microcks:masterfrom
Caesarsage:pr1/classify-errors-and-depanic

Conversation

@Caesarsage

Copy link
Copy Markdown
Contributor

Part of the Microcks CLI v2 work #255.

Introduces a small Failure Kind vocabulary in pkg/errors (Kind, Wrap/Wrapf, KindOf, and an ErrTestFailed sentinel) and makes the client library return classified errors instead of panicking or exiting.

Why

pkg/connectors and keycloak_client previously panic'd on runtime errors (bad response body, unreachable server). A library that can take down its host process is unsafe to embed, which the planned VS Code extension needs to do. Kinds are the library's vocabulary; exit codes stay a CLI concern (added in next PR ()), so pkg/* never depends on them.

Notable

Fixes two real latent bugs found while de-panicking:

  • Keycloak swallowed request-creation errors: nil-pointer dereference.
  • Unchecked openIDResp["access_token"].(string): the CLI crashed on a Keycloak 401 instead of reporting it.

Scope / safety

Additive and non-breaking: the legacy CheckError/Fatal shim and the existing constructor signatures are untouched here (removed/changed in later PRs). Build + tests green.

@Vaishnav88sk

Copy link
Copy Markdown

supersede #481

Comment thread pkg/errors/error_test.go

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please add copyright block at start

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added

Comment on lines 195 to 200
u, err := url.Parse(apiURL)
if err != nil {
// url.Parse only fails on a malformed URL; returning it needs a
// signature change, done with the RunE command migration.
panic(err)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This reintroduces a panic in library code, which conflicts with the stated goal of this PR.

Even if malformed URLs are a narrower case, a library constructor still should not panic here. If we cannot change the constructor signature in this PR, then I’d rather keep this work scoped differently than claim we have removed panics from the client layer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment on lines 52 to 56
u, err := url.Parse(realmURL)
if err != nil {
// url.Parse only fails on a malformed URL; returning it needs a
// signature change, done with the RunE command migration.
panic(err)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Same concern here: this keeps a panic path in the client library.

For embeddability, constructors should ideally return errors instead of terminating the host process. If that signature migration has to happen separately, please call that out more explicitly and avoid over-claiming the scope of this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks, this has been fixed on the next PR

#490

Comment on lines +257 to +259
if enabled, _ := configResp["enabled"].(bool); !enabled {
return "null", nil
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should not silently treat a missing / malformed enabled field as “Keycloak disabled”.

If the response shape is wrong, please return an API error instead. Otherwise a bad server/proxy response can be misclassified as a valid “no Keycloak” setup.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Similarly, it was addressed on the #490 PR

@Vaishnav88sk

Copy link
Copy Markdown

DCO is required.

@Caesarsage
Caesarsage force-pushed the pr1/classify-errors-and-depanic branch from c44f139 to f8c27a0 Compare July 23, 2026 08:48
Signed-off-by: caesarsage <destinyerhabor6@gmail.com>
Signed-off-by: caesarsage <destinyerhabor6@gmail.com>
Signed-off-by: caesarsage <destinyerhabor6@gmail.com>
@Caesarsage
Caesarsage force-pushed the pr1/classify-errors-and-depanic branch from f8c27a0 to 732b4ae Compare July 23, 2026 08:57
@Caesarsage

Copy link
Copy Markdown
Contributor Author

fixed @Vaishnav88sk

@Vaishnav88sk

Copy link
Copy Markdown

Suggestion:

@Vaishnav88sk

Copy link
Copy Markdown

After that LGTM. 👍🏻

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.

2 participants