besom icon indicating copy to clipboard operation
besom copied to clipboard

Improve compile error message for values that cannot be exported

Open lbialy opened this issue 2 years ago • 2 comments

Currently for types that do not have an instance of Encoder[A] compile error for exports function looks like this:

Compiling project (Scala 3.3.1, JVM (11))
[error] ./Main.scala:113:22
[error] Encoder[os.Path] is missing
[error]     kubeconfigPath = os.pwd / "kubeconfig.conf"
[error]                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
Error compiling project (Scala 3.3.1, JVM (11))
Compilation failed

for code:

  yield exports(
    leaderIp = leaderIp,
    kubeconfigPath = os.pwd / "kubeconfig.conf"
  )

We should improve the error message here and explain what's going on. Maybe even offer public Encoder access with contravariant combinator?

lbialy avatar Nov 12 '23 12:11 lbialy

This happens in Exports.scala:24-56, applyDynamicNamedImpl macro method scope. Precise location Exports.scala:39 but it gets called on line 44.

lbialy avatar Nov 12 '23 12:11 lbialy

The workaround is to convert your type here to something that has an obvious Encoder instance like any numeric type, Strings and spray.json JSON AST values.

lbialy avatar Nov 12 '23 12:11 lbialy