Custom revert errors not showing w/ TypeScript SDK

Deployed a contract (see below) that has custom revert error messages on my local Fuel node, but when testing out some methods which fail, I only get the following error: RequireRevertError: The script reverted with reason RequireFailed and not the actual error (like I get with the Rust SDK). Any idea how to fix this?

enum Error {
    CustomErrorWhichShouldDisplayErrorMessage: (),
}

impl Test for Contract {
    #[storage(read, write)]
    fn do_something() {
        require(false, Error::CustomErrorWhichShouldDisplayErrorMessage);
    }
}

I use the typegen feature to get the Typescript types for my contract, and use it like so:

const contract = TestFactory.deployContract(TestBytecode, wallet)
await contract.functions.do_something().call()

The error stack trace I get:

     RequireRevertError: The script reverted with reason RequireFailed
      at revertErrorFactory (node_modules/@fuel-ts/program/src/revert/revert-error.ts:173:14)
      at RevertErrorCodes.getError (node_modules/@fuel-ts/program/src/revert/revert-error-codes.ts:41:12)
      at RevertErrorCodes.assert (node_modules/@fuel-ts/program/src/revert/revert-error-codes.ts:22:30)
      at new ScriptResultDecoderError (node_modules/@fuel-ts/program/src/errors.ts:34:43)
      at decodeCallResult (node_modules/@fuel-ts/program/src/script-request.ts:118:11)
      at decodeContractCallScriptResult (node_modules/@fuel-ts/program/src/contract-call-script.ts:179:3)
      at FunctionInvocationResult.getDecodedValue (node_modules/@fuel-ts/program/src/functions/invocation-results.ts:89:28)
      at new InvocationResult (node_modules/@fuel-ts/program/src/functions/invocation-results.ts:59:23)
      at new FunctionInvocationResult (node_modules/@fuel-ts/program/src/functions/invocation-results.ts:151:5)
      at Function.build (node_modules/@fuel-ts/program/src/functions/invocation-results.ts:175:22)

This is quite annoying because I have several dozen invariants within the function, and it’s impossible to figure out which invariant failed.

Using TS SDK: v0.74.0

thanks!

1 Like

@theAusicist I created a minimal example based on the provided snippets and I got the correct error message in the error, but it’s underneath the initial RequireRevertError: the script reverted with reason RequireFailed stack trace:

RequireRevertError: The script reverted with reason RequireFailed
    at revertErrorFactory (fuel/ts/packages/program/src/utils.ts:175:14)
    at RevertErrorCodes.getError (fuel/ts/packages/program/src/utils.ts:212:12)
    at RevertErrorCodes.assert (fuel/ts/packages/program/src/utils.ts:196:30)
    at new ScriptResultDecoderError (fuel/ts/packages/program/src/utils.ts:242:43)
    at decodeCallResult (fuel/ts/packages/program/src/utils.ts:356:11)
    ... 4 lines matching cause stack trace ...
    at Function.build (fuel/ts/packages/program/src/utils.ts:745:22) {
  receipt: {
    type: 4,
    id: '0x89c45dcd786f4701bd1e02cda59f71e9ae1585108483acc9e3987e90d7e1764b',
    val: <BN: 0xffffffffffff0000>,
    pc: <BN: 0x3388>,
    is: <BN: 0x2d68>
  },
  cause: ScriptResultDecoderError: Execution of the script associated with contract fuel138z9mntcdarsr0g7qtx6t8m3axhptpgssjp6ej0rnplfp4lpwe9smeh57n resulted in a non-zero exit code: 1.
  
  {
    "doc": "https://docs.rs/fuel-asm/latest/fuel_asm/enum.PanicReason.html",
    "reason": "unknown"
  }
  
  Logs:
  [
    "CustomErrorWhichShouldDisplayErrorMessage"
  ]
  
  Receipts:
  [
    {
      "type": "Call",
      "from": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "to": "0x89c45dcd786f4701bd1e02cda59f71e9ae1585108483acc9e3987e90d7e1764b",
      "amount": "0x0",
      "assetId": "0x0000000000000000000000000000000000000000000000000000000000000000",
      "gas": "0x3c",
      "param1": "0x55d63568",
      "param2": "0x28d0",
      "pc": "0x2d68",
      "is": "0x2d68"
    },
    {
      "type": "LogData",
      "id": "0x89c45dcd786f4701bd1e02cda59f71e9ae1585108483acc9e3987e90d7e1764b",
      "val0": "0x0",
      "val1": "0x0",
      "ptr": "0x35d8",
      "len": "0x8",
      "digest": "0xaf5570f5a1810b7af78caf4bc70a660f0df51e42baf91d4de5b2328de0e83dfc",
      "pc": "0x3380",
      "is": "0x2d68",
      "data": "0x0000000000000000"
    },
    {
      "type": "Revert",
      "id": "0x89c45dcd786f4701bd1e02cda59f71e9ae1585108483acc9e3987e90d7e1764b",
      "val": "0xffffffffffff0000",
      "pc": "0x3388",
      "is": "0x2d68"
    },
    {
      "type": "ScriptResult",
      "result": "0x1",
      "gasUsed": "0x102"
    }
  ]
      at decodeCallResult (fuel/ts/packages/program/src/utils.ts:356:11)
      at decodeContractCallScriptResult (fuel/ts/packages/program/src/utils.ts:557:95)
      at FunctionInvocationResult.getDecodedValue (fuel/ts/packages/program/src/utils.ts:684:28)
      at new InvocationResult (fuel/ts/packages/program/src/utils.ts:658:23)
      at new FunctionInvocationResult (fuel/ts/packages/program/src/utils.ts:727:5)
      at Function.build (fuel/ts/packages/program/src/utils.ts:745:22)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at Module.safeExec (fuel/ts/packages/errors/src/test-utils/safeExec.ts:6:14)
      at fuel/ts/packages/fuel-gauge/src/revert-error.test.ts:96:23
      at runTest (file://fuel/ts/node_modules/.pnpm/@vitest+runner@1.2.1/node_modules/@vitest/runner/dist/index.js:675:11) {
    logs: [ 'CustomErrorWhichShouldDisplayErrorMessage' ]
  }
}
1 Like

thanks @nedsalk. got the same after some experimentation. wouldn’t it be better though, like the Rust SDK, to display the error message along with the reason at the top of the stacktrace? Something like: RequireRevertError: The script reverted with reason "CustomErrorWhichShouldDisplayErrorMessage"? Cleaner imo and easier to debug quickly

im also facing the same challenge here, hope its sorted soon

this no longer works in v0.76.0. It’s back to the same generic error (as here).

@Dhaiwat10 is looking into it via issue 823.

2 Likes