Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/src/cellar/CellarError.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ object CellarError:
extends CellarError:
override def getMessage: String =
val base = s"Symbol '$fqn' not found in '${coord.render}'."
if nearMatches.isEmpty then base
else s"$base Did you mean one of: ${nearMatches.mkString(", ")}?"
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
Comment on lines +29 to +32
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.

final case class PartialResolution(fqn: String, coord: Option[MavenCoordinate], resolvedFqn: String, missingMember: String)
extends CellarError:
Expand Down
9 changes: 9 additions & 0 deletions lib/test/src/cellar/CellarErrorTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@ class CellarErrorTest extends munit.FunSuite:
val e = CellarError.SymbolNotFound("Foo", coord, Nil)
assert(!e.getMessage.contains("Did you mean"))

test("SymbolNotFound with empty nearMatches and non-latest version suggests latest"):
val e = CellarError.SymbolNotFound("Foo", coord, Nil)
assert(e.getMessage.contains("org.example:lib:latest"))

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 'org.example:lib:latest'"))

test("SymbolNotFound with nearMatches lists all of them"):
val e = CellarError.SymbolNotFound("Foo", coord, List("bar.Foo", "baz.Foo"))
assert(e.getMessage.contains("bar.Foo"))
Expand Down
Loading