Suggest latest version in SymbolNotFound when no near matches#66
Suggest latest version in SymbolNotFound when no near matches#66
Conversation
There was a problem hiding this comment.
Pull request overview
Updates CellarError.SymbolNotFound messaging to guide users toward using :latest when a symbol might exist only in newer artifact versions, aligning with the CLI/library support for the latest version sentinel.
Changes:
- Append a
Try 'group:artifact:latest'...hint whennearMatchesis empty and the coordinate version isn’t alreadylatest. - Add tests covering the hint being shown for versioned coordinates and suppressed for
latest.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/src/cellar/CellarError.scala | Adds the conditional “try :latest” hint to SymbolNotFound.getMessage when there are no near matches. |
| lib/test/src/cellar/CellarErrorTest.scala | Adds unit tests to validate the new hint behavior for latest vs non-latest coordinates. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if nearMatches.nonEmpty then s"$base Did you mean one of: ${nearMatches.mkString(", ")}?" | ||
| else if coord.version != "latest" then | ||
| s"$base\nTry '${coord.copy(version = "latest").render}' if the symbol was introduced in a newer version." | ||
| else base |
There was a problem hiding this comment.
The sentinel string "latest" is now duplicated here and in MavenCoordinate.resolveLatest. Consider centralizing it (e.g., MavenCoordinate.LatestVersion / coord.isLatest) so future changes to the sentinel don’t require hunting for string literals.
| test("SymbolNotFound with empty nearMatches and version=latest does not add a Try hint"): | ||
| val latestCoord = MavenCoordinate("org.example", "lib", "latest") | ||
| val e = CellarError.SymbolNotFound("Foo", latestCoord, Nil) | ||
| assert(!e.getMessage.contains("Try")) |
There was a problem hiding this comment.
This assertion is very broad and could become flaky if the base message ever contains the word "Try" for other reasons. Consider asserting that the specific latest-version hint line (or the "Try 'org.example:lib:latest'" prefix) is absent instead.
| assert(!e.getMessage.contains("Try")) | |
| assert(!e.getMessage.contains("Try 'org.example:lib:latest'")) |
Fixes #59.
Summary
CellarError.SymbolNotFound.getMessage, whennearMatchesis empty and the coordinate version is not alreadylatest, appends a hint suggestinggroup:artifact:latestlatestTest plan
./mill lib.testpasses (372/372)