# Incorrect logs decoding of errors in cross-contract calls

**URL:** <https://forum.fuel.network/t/incorrect-logs-decoding-of-errors-in-cross-contract-calls/5381>\
**Category:** TypeScript SDK\
**Tags:** testnet, feedback\
**Created:** [May 27, 2024, 6:52pm UTC](https://forum.fuel.network/t/incorrect-logs-decoding-of-errors-in-cross-contract-calls/5381 "2024-05-27T18:52:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![theAusicist](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/theausicist/32/1987_2.png) [@theAusicist](https://forum.fuel.network/u/theAusicist)\
**Post date:** [May 27, 2024, 6:52pm UTC](https://forum.fuel.network/t/incorrect-logs-decoding-of-errors-in-cross-contract-calls/5381/1 "2024-05-27T18:52:22Z")

</div>

Contract `B` calls a method in contract `A` which fails an invariant. Both contracts have error-enum structs like so:

```rust
// contract A
pub enum Error {
    ContrABlah1: (),
    ContrABlah2: ()
}

// contract B
pub enum Error {
    ContrBBlah1: (),
    ContrBBlah2: ()
}

```

invariant in method in contract `A` fails:

```rust
// invariant in method in contract A
require(false, Error::ContrABlah2);

```

if I do the following:

```rust
// fn in contract B
contr_A.call_fn_that_fails_invariant();

```

the decoded logs in the TS SDK show that the decoded error is: `ContrBBlah2` (even though this wasn’t the error message). Through tests, I have determined that if an error of index `i` in the enum definition as above in contract `A` is the failed message, the error of index `i` in the enum definition of contract `B` will be the one displayed.

Minimal example: [callee-errors.sw · GitHub](https://gist.github.com/theausicist/82341f40a2a950ce458f4daa51cb01d2)

Expected error message in decoded logs: `CaleeError5`  
Actual error message in decoded logs: `CallerError6940`

This has been a bug in all the earlier versions of the TS SDK. I haven’t tested this for the Rust SDK yet.

@Dhaiwat10 @naz3eh @IGI-111

---

<div class="post-metadata">

**Author:** ![naz3eh](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/naz3eh/32/2025_2.png) [@naz3eh](https://forum.fuel.network/u/naz3eh)\
**Post date:** [May 28, 2024, 5:16am UTC](https://forum.fuel.network/t/incorrect-logs-decoding-of-errors-in-cross-contract-calls/5381/2 "2024-05-28T05:16:02Z")

</div>

Hey @theAusicist, thanks for reporting it. Let me confirm it with the team and get back to you.

---

<div class="post-metadata">

**Author:** ![theAusicist](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/theausicist/32/1987_2.png) [@theAusicist](https://forum.fuel.network/u/theAusicist)\
**Post date:** [May 28, 2024, 12:05pm UTC](https://forum.fuel.network/t/incorrect-logs-decoding-of-errors-in-cross-contract-calls/5381/3 "2024-05-28T12:05:36Z")

</div>

the exact error trace is:

```bash
 FuelError: The transaction reverted because a "require" statement has thrown "CallerError6940".
      at extractTxError (node_modules/@fuel-ts/account/src/providers/transaction-request/helpers.ts:43:5)
      at _Provider.extractDryRunError (node_modules/@fuel-ts/account/src/providers/provider.ts:1725:11)
      at _Provider.getTransactionCost (node_modules/@fuel-ts/account/src/providers/provider.ts:1136:7)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at FunctionInvocationScope.getTransactionCost (node_modules/@fuel-ts/program/src/functions/base-invocation-scope.ts:239:6)
      at FunctionInvocationScope.fundWithRequiredCoins (node_modules/@fuel-ts/program/src/functions/base-invocation-scope.ts:261:7)
      at FunctionInvocationScope.call (node_modules/@fuel-ts/program/src/functions/base-invocation-scope.ts:360:12)

```

TS SDK version: `fuels v0.88.0`

It appears that the `functionInvocationScopes` in `BaseInvocationScopes` doesn’t include the `abis` of contracts other than the calling contract

[this line](https://github.com/FuelLabs/fuels-ts/blob/80e0c2361306ffaeb43f35a7b3db4f47706a4f9c/packages/program/src/functions/base-invocation-scope.ts#L200) is where the `main` and `otherContractsAbis` abis are grabbed:

```rust
this.transactionRequest.abis = getAbisFromAllCalls(this.functionInvocationScopes);

// value of this.transactionRequest.abis.otherContractsAbis is {}

```

Here’s where the [logs are decoded](https://github.com/FuelLabs/fuels-ts/blob/80e0c2361306ffaeb43f35a7b3db4f47706a4f9c/packages/account/src/providers/transaction-response/getDecodedLogs.ts#L31):

```rust
const interfaceToUse = new Interface(externalAbis[receipt.id] || mainAbi);

// since externalAbis is {}, it always defaults to "mainAbi"

```

---

<div class="post-metadata">

**Author:** ![theAusicist](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/theausicist/32/1987_2.png) [@theAusicist](https://forum.fuel.network/u/theAusicist)\
**Post date:** [May 28, 2024, 12:34pm UTC](https://forum.fuel.network/t/incorrect-logs-decoding-of-errors-in-cross-contract-calls/5381/4 "2024-05-28T12:34:32Z")

</div>

I fixed this by using `.addContracts` to the function scope before calling the contract like so:

```typescript
// In TS
await caller.functions.call_callee_that_fails(toContract(callee)).addContracts([callee]).call()

// yields the correct error: CalleeError5

```

this is a bug, no doubt. I _shouldn’t_ have to use `.addContracts` for Fuel to be able to figure out where the error originated from.

Edit: Posted an [issue in the `fuels-ts` Github](https://github.com/FuelLabs/fuels-ts/issues/2403)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex022/uploads/fuel/original/2X/5/57d5a345cc15a64b636e0d56e042857f8a0e80b1.png) [@system](https://forum.fuel.network/u/system)\
**Post date:** [June 18, 2024, 8:34am UTC](https://forum.fuel.network/t/incorrect-logs-decoding-of-errors-in-cross-contract-calls/5381/5 "2024-06-18T08:34:34Z")

</div>

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.
