Issue with exceptions

Hey,

I’m trying to experiment with exceptions but I get a weird error. (Daml SDK 1.14.0)

I took a test from the Daml repo:

module Main where

import DA.Exception

test1 : ActionCatch m => m Int
test1 =
    try
        pure (10 / 0)
    catch
        (_: ArithmeticError) -> pure 0

I get the following error when compiling:

 $ daml build
Compiling daml-new to a DAR.
File:     daml/Main.daml
Hidden:   no
Range:    5:9-5:20
Source:   typecheck
Severity: DsError
Message:  daml/Main.daml:5:9: error:Not in scope: type constructor or class ‘ActionCatch’
File:     daml/Main.daml
Hidden:   no
Range:    7:5-10:39
Source:   typecheck
Severity: DsError
Message: 
  daml/Main.daml:7:5: error:
  Not in scope: ‘DA.Internal.Desugar._tryCatch’
  Perhaps you meant one of these:
  ‘DA.Internal.Desugar.create’ (imported from DA.Internal.Desugar),
  ‘DA.Internal.Desugar.fetch’ (imported from DA.Internal.Desugar),
  ‘DA.Internal.Desugar.concat’ (imported from DA.Internal.Desugar)
  Module ‘DA.Internal.Desugar’ does not export ‘_tryCatch’.
File:     daml/Main.daml
Hidden:   no
Range:    10:9-10:39
Source:   typecheck
Severity: DsError
Message: 
  daml/Main.daml:10:9: error:
  Not in scope: ‘DA.Internal.Desugar.fromAnyException’
  Perhaps you meant one of these:
  ‘DA.Internal.Desugar.fromAnyChoice’ (imported from DA.Internal.Desugar),
  ‘DA.Internal.Desugar.fromAnyTemplate’ (imported from DA.Internal.Desugar),
  ‘DA.Internal.Desugar._fromAnyChoice’ (imported from DA.Internal.Desugar)
  Module ‘DA.Internal.Desugar’ does not export ‘fromAnyException’.
File:     daml/Main.daml
Hidden:   no
Range:    10:13-10:28
Source:   typecheck
Severity: DsError
Message:  daml/Main.daml:10:13: error:Not in scope: type constructor or class ‘ArithmeticError’
ERROR: Creation of DAR file failed.

Since this is a working test, I assume something is wrong with my setup. However other features work in Daml, only the use of exceptions triggers this.

Any suggestions? Thank you!

I can reproduce this by running daml new t and then adding your code snippet.

While the error message could be improved, this is essentially expected behaviour: exceptions are not supported until Daml LF 1.14, which is not the default compiler output version in current stable Daml releases. To force the compiler to emit Daml LF 1.14, you can add

build-options:
  - --target=1.14

to your daml.yml file.

With that addition, this code snippet works for me. Can you confirm this fixes it for you too?

4 Likes

Yep, that indeed fixed it, thank you!

1 Like