Skip to content

Validate --repository URLs and name the flag in the error (#123) - #145

Merged
rochala merged 1 commit into
mainfrom
issue-123
Aug 23, 2026
Merged

Validate --repository URLs and name the flag in the error (#123)#145
rochala merged 1 commit into
mainfrom
issue-123

Conversation

@rochala

@rochala rochala commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Fixes #123.

Scope

The issue names two repository sources: the -r/--repository flag and maven.repositories in cellar.conf. The config source comes from #121, which is still open — there is no config-file repository path on main yet. This PR fixes the pre-existing gap the issue calls out: -r was never validated.

RepositoryUrl.parse returns the rejection reason without naming a source, so the caller supplies it. When #121 lands, its config path can reuse the same check and prefix reasons with the config file instead of the flag.

What changed

  • cli/src/cellar/cli/RepositoryUrl.scala (new) — parse(raw): Either[String, MavenRepository]. Trims, then rejects empty strings, unparseable URIs, a missing scheme, schemes other than http/https/file, and http(s) URLs with no host.
  • cli/src/cellar/cli/CellarApp.scalaextraReposOpt uses mapValidated, prefixing each reason with Invalid --repository:. Dropped the now-unused MavenRepository import.
  • cli/test/src/cellar/cli/RepositoryUrlTest.scala (new) — 7 tests over accepted and rejected forms.
  • README.md — the -r flag row states the accepted schemes.

Verification

Rejected before, the bad URL and the flag both named:

$ cellar get-external -r artifactory.company.com/maven org.typelevel:cats-core_3:2.10.0 cats.Monad
Invalid --repository: 'artifactory.company.com/maven' has no scheme (expected one of http://, https://, file://)
Usage: cellar get-external [...]

Exits non-zero instead of surfacing later as CoordinateNotFound with coordinate suggestions. A valid -r https://repo1.maven.org/maven2 still renders cats.Monad correctly end-to-end.

./mill __.test (623 tasks) and ./mill _.fix --check both pass.

🤖 Generated with Claude Code

`MavenRepository.of` accepts any string verbatim, so a typo like a
missing scheme survived until resolution failed — and it then failed as
`CoordinateNotFound`, pointing at the coordinate with coordinate
suggestions rather than at the repository that was actually wrong.

Reject the URL at parse time instead: empty strings, unparseable URIs,
a missing scheme, schemes other than http/https/file, and http(s) URLs
with no host. The rejection reason carries no source prefix of its own,
so the caller names where the URL came from; that keeps the config-file
source #121 adds able to reuse the same check.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@rochala
rochala merged commit 8373a7e into main Aug 23, 2026
6 checks passed
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.

Validate Maven repository URLs and name the offending repo in errors

1 participant