Skip to content

Custom error message not working #2957

Description

@KieranP

Bug description

Using either:

class LocationOccupied extends Error {
  constructor(message: string) {
    super(`LocationOccupied(${message})`);
  }
}

OR

class LocationOccupied extends Error {
  constructor(message: string) {
    this.message = `LocationOccupied(${message})`;
  }
}

OR

class LocationOccupied extends Error {
  toString(): string {
    return `LocationOccupied(${this.message})`
  }
}

and calling this:

throw new LocationOccupied(`${x}-${y}`)

I'm not getting a custom message:

› wasmer run build/release.wasm
⠁ Compiling to WebAssembly                                                                                                                                                                                                                                  abort: 0-0 in assembly/world.ts(107:7)

› wasmtime run build/release.wasm
abort: 0-0 in assembly/world.ts(107:7)
Error: failed to run main module `build/release.wasm`

Notice only "0-0" is getting output, which is what is passed into the throw.

The change of the message in the custom error class doesn't apply.

Steps to reproduce

See above

AssemblyScript version

v0.28.9

Activity

  1. CountBleck commented on Oct 27, 2025

    @CountBleck
    Member

    I suspect something like throw (new LocationOccupied(...)) would work, due to a quirk/optimization in how throw statements are compiled (most likely to avoid allocating an object just so the program can subsequently abort).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions