Debug.trap - Deprecated?

I have a make file in axon:

MOC ?= $(shell vessel bin)/moc
# MOC ?= $(shell dfx cache show)/moc
SOURCES = $(shell vessel sources)

TESTS=$(wildcard *.test.mo)
TEST_TARGETS = $(patsubst %.mo,%.wasm,$(TESTS))

.PHONY: $(TESTS)

all: $(TEST_TARGETS)

%.wasm: %.mo
	$(MOC) $(SOURCES) -wasi-system-api -o $@ $< && wasmtime $@
	rm -f $@

clean:
	rm *.wasm

I’m getting this error:

../../../.vessel/.bin/0.6.2/moc --package base ../../../.vessel/base/aafcdee0c8328087aeed506e64aa2ff4ed329b47/src --package map ../../../.vessel/map/v7.0.0/src --package map_7_0_0 ../../../.vessel/map_7_0_0/v7.0.0/src --package matchers ../../../.vessel/matchers/v1.2.0/src --package stablebuffer ../../../.vessel/stablebuffer/v0.2.0/src --package stablebuffer_0_2_0 ../../../.vessel/stablebuffer_0_2_0/v0.2.0/src -wasi-system-api -o Axon.test.wasm Axon.test.mo && wasmtime Axon.test.wasm
../../../.vessel/base/aafcdee0c8328087aeed506e64aa2ff4ed329b47/src/Prelude.mo:18.5-18.10: type error [M0072], field trap does not exist in type
  module {print : Text -> ()}
../../../.vessel/base/aafcdee0c8328087aeed506e64aa2ff4ed329b47/src/Prelude.mo:22.5-22.10: type error [M0072], field trap does not exist in type
  module {print : Text -> ()}
../../../.vessel/base/aafcdee0c8328087aeed506e64aa2ff4ed329b47/src/Prelude.mo:30.5-30.10: type error [M0072], field trap does not exist in type
  module {print : Text -> ()}

Can anyone spot what is going on? I’m guessing that it is the vessel compiler version? Actually it isn’t…same error with compiler = Some “0.7.3” in my vessel file.

Prelude.mo is

/// General utilities
///
/// This prelude file proposes standard library features that _may_
/// belong in the _language_ (compiler-internal) prelude sometime, after
/// some further experience and discussion.  Until then, they live here.

import Debug "Debug";

module {

  /// Not yet implemented
  ///
  /// Mark incomplete code with the `nyi` and `xxx` functions.
  ///
  /// Each have calls are well-typed in all typing contexts, which
  /// trap in all execution contexts.
  public func nyi() : None {
    Debug.trap("Prelude.nyi()");
  };

  public func xxx() : None {
    Debug.trap("Prelude.xxx()");
  };

  /// Mark unreachable code with the `unreachable` function.
  ///
  /// Calls are well-typed in all typing contexts, and they
  /// trap in all execution contexts.
  public func unreachable() : None {
    Debug.trap("Prelude.unreachable()")
  };

}

1 Like

trap was commented out in Debug.mo for base with hash aafcdee0c8328087aeed506e64aa2ff4ed329b47. Is this intentional? What should we use instead?

I have been having to override the base module version in the package-set file when using vessel, it’s stuck on an old version

   additions = 
     [ 
       { 
          name = "base" 
          , version = "moc-0.7.4" 
          , repo = "https://github.com/dfinity/motoko-base" 
          , dependencies = [] : List Text 
       } 
     ] : List Package

This is a merge commit

commit aafcdee0c8328087aeed506e64aa2ff4ed329b47 (tag: moc-0.7.3)
Merge: c2b221a ab4e38d
Author: Claudio Russo <claudio@dfinity.org>
Date:   Tue Nov 1 14:57:24 2022 +0000

    Merge pull request #424 from dfinity/crusso/update-moc-0.7.3
    
    chore: update to moc 0.7.3

I am looking into it.

Edit: GitHub shows a straightforward history and no deprecation:

Can you paste the Debug.mo contents here (along with the git commit) for my sanity’s sake? :slight_smile:

The base lib example of Debug.trap does not trap. Is this correct?

Tried in Playground and DFX 0.13.1

But when removing async from the fail function and not awaiting it, the call to foo does trap

It does actually trap, but the trap is then returned as an error from fail and caught and silently ignored by foo.

Here’s a better example that illustrates it:

1 Like