Skip to content

fix: improve error messages for catalog download failures - #2561

Merged
maxandersen merged 1 commit into
mainfrom
2559
Jul 1, 2026
Merged

fix: improve error messages for catalog download failures#2561
maxandersen merged 1 commit into
mainfrom
2559

Conversation

@maxandersen

@maxandersen maxandersen commented Jun 25, 2026

Copy link
Copy Markdown
Collaborator

Fixes #2559

When a catalog download fails and authentication was in play, users get an unhelpful "Unknown catalog" error with no clue that their token or credentials might be the problem.

What changed

NetUtil.describeAuthMethod(url) checks which auth method (if any) would apply for a given URL, using the same priority order as addAuthHeaderIfNeeded: GITHUB_TOKEN, GITLAB_TOKEN, URL credentials, .netrc, JBANG_AUTH_BASIC_*. Returns a human-readable label or null.

ImplicitCatalogRef.tryDownload() now calls describeAuthMethod on failure and warns when credentials were involved:

[jbang] [WARN] Could not download catalog from https://github.com/quarkusio/jbang-catalog/blob/HEAD/jbang-catalog.json. Authentication via GITHUB_TOKEN was used but may be expired or invalid. Try updating or removing the credentials.

This works for all auth methods, not just GITHUB_TOKEN.

Catalog.findImportedCatalogsWith() now passes both the exception message and the Throwable to verboseMsg, so the error reason is visible without --verbose and stack traces still print when verbose is on.

Tests cover .netrc, URL credentials, priority ordering, null returns for unmatched URLs, and invalid input.

See #2560 for a follow-up to include attempted download URLs in the "Unknown catalog" error message itself.

Summary by CodeRabbit

  • New Features
    • Improved authentication detection for remote downloads, with clearer guidance when credentials are being used.
  • Bug Fixes
    • Download failures now show more helpful warnings when authentication may be expired or invalid.
    • Error logging is more informative, making failures easier to diagnose.

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4733acb3-fb2d-4be7-ab0d-bb1b63c81c3e

📥 Commits

Reviewing files that changed from the base of the PR and between 004f649 and cf5dd94.

📒 Files selected for processing (4)
  • src/main/java/dev/jbang/catalog/Catalog.java
  • src/main/java/dev/jbang/catalog/ImplicitCatalogRef.java
  • src/main/java/dev/jbang/util/NetUtil.java
  • src/test/java/dev/jbang/util/TestDescribeAuthMethod.java

📝 Walkthrough

Walkthrough

This PR improves catalog error diagnostics: exception logging in Catalog now includes the exception object and message; NetUtil gains a describeAuthMethod utility that identifies which authentication source (token, URL userinfo, .netrc, basic auth) applies to a URL; ImplicitCatalogRef uses it to warn about possibly expired credentials on download failure; new tests cover the utility.

Changes

Auth-aware catalog download error reporting

Layer / File(s) Summary
Verbose exception logging
src/main/java/dev/jbang/catalog/Catalog.java
Catch block logging now includes the exception message and passes the exception object to Util.verboseMsg.
Auth-method detection utility
src/main/java/dev/jbang/util/NetUtil.java
Refactors host-detection into private helpers and adds describeAuthMethod(String url), which returns a description of the auth source (host token env var, URL userinfo, .netrc, or global basic-auth env vars) or null.
Wiring into download failure path
src/main/java/dev/jbang/catalog/ImplicitCatalogRef.java
On download failure, calls NetUtil.describeAuthMethod(url) and logs a warning about potentially expired/invalid credentials when an auth method is detected.
Unit tests
src/test/java/dev/jbang/util/TestDescribeAuthMethod.java
Adds tests covering URL credentials, .netrc machine/default entries, no-match/no-auth cases, invalid URLs, and credential precedence.

Estimated code review effort: 2 (Simple) | ~12 minutes

Possibly related issues

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@maxandersen
maxandersen force-pushed the 2559 branch 2 times, most recently from eec3c1c to af6f002 Compare June 25, 2026 07:27
- Warn when GITHUB_TOKEN is set and a GitHub catalog download fails,
  suggesting to update or unset the token
- Log GITHUB_TOKEN usage at verbose level so users can see auth is
  being applied
- Fix verboseMsg call in Catalog.findImportedCatalogsWith to pass the
  Throwable so --verbose actually prints stack traces

Fixes #2559
@maxandersen maxandersen added the ai-review used to explicitly request ai-review label Jul 1, 2026
@maxandersen
maxandersen merged commit f9e27b4 into main Jul 1, 2026
29 of 30 checks passed
@maxandersen
maxandersen deleted the 2559 branch July 1, 2026 06:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review used to explicitly request ai-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

catalog issue does not give good user/error info

1 participant