Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LF: SBAnyExceptionMessage queries for unknown packages. #9804

Merged
merged 2 commits into from
May 26, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Add test
  • Loading branch information
remyhaemmerle-da committed May 26, 2021
commit 37f9a035b5f941e1dbb5dfd0aa8f3e14b9bf1a28
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.daml.lf.data._
import com.daml.lf.language.Ast._
import com.daml.lf.speedy.SError.{DamlEUnhandledException, SError, SErrorCrash}
import com.daml.lf.speedy.SExpr._
import com.daml.lf.speedy.SResult.{SResultError, SResultFinalValue}
import com.daml.lf.speedy.SResult.{SResultError, SResultFinalValue, SResultNeedPackage}
import com.daml.lf.speedy.SValue.{SValue => _, _}
import com.daml.lf.testing.parser.Implicits._
import com.daml.lf.value.Value
Expand Down Expand Up @@ -1485,6 +1485,22 @@ class SBuiltinTest extends AnyFreeSpec with Matchers with TableDrivenPropertyChe
}
}

"AnyExceptionMessage" - {

"request unknown packageId" in {
eval(
e"""ANY_EXCEPTION_MESSAGE (to_any_exception @Mod:Exception (Mod:Exception {}))"""
) shouldBe Right(SText("some nice error message"))
// FIXME: should be
// e"""ANY_EXCEPTION_MESSAGE (to_any_exception @'-unknown-package-':Mod:Exception ('-unknown-package-'Mod:Exception {}))"""
// but the parser seems buggy.
eval(
e"""ANY_EXCEPTION_MESSAGE (to_any_exception @'-unknown-package-':Mod:Exception (Mod:Exception {}))"""
) shouldBe Left(SErrorCrash(s"need package '-unknown-package-'"))
}

}

}

object SBuiltinTest {
Expand All @@ -1496,6 +1512,10 @@ object SBuiltinTest {
record MyUnit = { };
record Tuple a b = { fst: a, snd: b };
enum Color = Red | Green | Blue;
record @serializable Exception = {} ;
exception Exception = {
message \(e: Mod:Exception) -> "some nice error message"
} ;
}

"""
Expand Down Expand Up @@ -1527,6 +1547,7 @@ object SBuiltinTest {
val value = machine.run() match {
case SResultFinalValue(v) => v
case SResultError(err) => throw Goodbye(err)
case SResultNeedPackage(pkgId, _) => throw Goodbye(SErrorCrash(s"need package '$pkgId'"))
case res => throw new RuntimeException(s"Got unexpected interpretation result $res")
}

Expand Down