From ef79322a96243f5d09ccc50c0d091ffe5405afc8 Mon Sep 17 00:00:00 2001 From: rochala Date: Thu, 23 Apr 2026 13:46:18 +0200 Subject: [PATCH 1/2] Suggest latest version in SymbolNotFound when no near matches --- lib/src/cellar/CellarError.scala | 6 ++++-- lib/test/src/cellar/CellarErrorTest.scala | 9 +++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lib/src/cellar/CellarError.scala b/lib/src/cellar/CellarError.scala index 3146334..5ee9574 100644 --- a/lib/src/cellar/CellarError.scala +++ b/lib/src/cellar/CellarError.scala @@ -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 final case class PartialResolution(fqn: String, coord: Option[MavenCoordinate], resolvedFqn: String, missingMember: String) extends CellarError: diff --git a/lib/test/src/cellar/CellarErrorTest.scala b/lib/test/src/cellar/CellarErrorTest.scala index 65c5005..12d0a67 100644 --- a/lib/test/src/cellar/CellarErrorTest.scala +++ b/lib/test/src/cellar/CellarErrorTest.scala @@ -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")) + 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")) From 8164eb30df24a0c68c4cfc0169413ab61b259b2d Mon Sep 17 00:00:00 2001 From: rochala Date: Thu, 23 Apr 2026 14:38:01 +0200 Subject: [PATCH 2/2] Tighten SymbolNotFound test assertion per review --- lib/test/src/cellar/CellarErrorTest.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/test/src/cellar/CellarErrorTest.scala b/lib/test/src/cellar/CellarErrorTest.scala index 12d0a67..a06c267 100644 --- a/lib/test/src/cellar/CellarErrorTest.scala +++ b/lib/test/src/cellar/CellarErrorTest.scala @@ -26,7 +26,7 @@ class CellarErrorTest extends munit.FunSuite: 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")) + 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"))