Skip to content

fix: fix parsing of PC when a inner transaction fails #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/code/classes/types_logic_error.LogicError.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Error.constructor

#### Defined in

[src/types/logic-error.ts:52](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L52)
[src/types/logic-error.ts:56](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L56)

## Properties

Expand All @@ -86,7 +86,7 @@ ___

#### Defined in

[src/types/logic-error.ts:40](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L40)
[src/types/logic-error.ts:44](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L44)

___

Expand All @@ -96,7 +96,7 @@ ___

#### Defined in

[src/types/logic-error.ts:42](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L42)
[src/types/logic-error.ts:46](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L46)

___

Expand Down Expand Up @@ -134,7 +134,7 @@ ___

#### Defined in

[src/types/logic-error.ts:41](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L41)
[src/types/logic-error.ts:45](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L45)

___

Expand All @@ -148,7 +148,7 @@ Error.stack

#### Defined in

[src/types/logic-error.ts:44](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L44)
[src/types/logic-error.ts:48](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L48)

___

Expand All @@ -158,7 +158,7 @@ ___

#### Defined in

[src/types/logic-error.ts:43](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L43)
[src/types/logic-error.ts:47](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L47)

___

Expand Down Expand Up @@ -258,4 +258,4 @@ The logic error details if any, or undefined

#### Defined in

[src/types/logic-error.ts:26](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L26)
[src/types/logic-error.ts:28](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L28)
10 changes: 5 additions & 5 deletions docs/code/interfaces/types_logic_error.LogicErrorDetails.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ The full error description

#### Defined in

[src/types/logic-error.ts:14](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L14)
[src/types/logic-error.ts:16](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L16)

___

Expand All @@ -38,7 +38,7 @@ The error message

#### Defined in

[src/types/logic-error.ts:12](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L12)
[src/types/logic-error.ts:14](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L14)

___

Expand All @@ -50,7 +50,7 @@ The program counter where the error was

#### Defined in

[src/types/logic-error.ts:10](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L10)
[src/types/logic-error.ts:12](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L12)

___

Expand All @@ -62,7 +62,7 @@ Any trace information included in the error

#### Defined in

[src/types/logic-error.ts:16](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L16)
[src/types/logic-error.ts:18](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L18)

___

Expand All @@ -74,4 +74,4 @@ The ID of the transaction with the logic error

#### Defined in

[src/types/logic-error.ts:8](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L8)
[src/types/logic-error.ts:10](https://github.com/algorandfoundation/algokit-utils-ts/blob/main/src/types/logic-error.ts#L10)
33 changes: 33 additions & 0 deletions src/types/app-factory-and-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import * as algokit from '..'
import arc56Json from '../../tests/example-contracts/arc56_templates/artifacts/Templates.arc56_draft.json'
import largeAppArc56Json from '../../tests/example-contracts/extra-pages/large.arc56.json'
import smallAppArc56Json from '../../tests/example-contracts/extra-pages/small.arc56.json'
import errorInnerAppArc56Json from '../../tests/example-contracts/inner_error/artifacts/InnerApp.arc56.json'
import errorMiddleAppArc56Json from '../../tests/example-contracts/inner_error/artifacts/MiddleApp.arc56.json'
import errorOuterAppArc56Json from '../../tests/example-contracts/inner_error/artifacts/OuterApp.arc56.json'
import { getTestingAppContract } from '../../tests/example-contracts/testing-app/contract'
import { algoKitLogCaptureFixture, algorandFixture } from '../testing'
import { asJson } from '../util'
Expand Down Expand Up @@ -757,6 +760,36 @@ describe('ARC56: app-factory-and-app-client', () => {
})
}, 10_000)

test('ARC56 error messages from inner app error', async () => {
const innerFactory = localnet.algorand.client.getAppFactory({
// @ts-expect-error TODO: Fix this
appSpec: errorInnerAppArc56Json,
defaultSender: localnet.context.testAccount.addr,
})

const { appClient: innerClient } = await innerFactory.deploy({ createParams: { method: 'createApplication' } })

const middleFactory = localnet.algorand.client.getAppFactory({
// @ts-expect-error TODO: Fix this
appSpec: errorMiddleAppArc56Json,
defaultSender: localnet.context.testAccount.addr,
})

const { appClient: middleClient } = await middleFactory.deploy({ createParams: { method: 'createApplication' } })

const outerFactory = localnet.algorand.client.getAppFactory({
// @ts-expect-error TODO: Fix this
appSpec: errorOuterAppArc56Json,
defaultSender: localnet.context.testAccount.addr,
})

const { appClient: outerClient } = await outerFactory.deploy({ createParams: { method: 'createApplication' } })

await expect(
outerClient.send.call({ method: 'callMiddle', args: [middleClient.appId, innerClient.appId], extraFee: algokit.microAlgos(2000) }),
).rejects.toThrow('custom error message')
})

test('ARC56 error messages with dynamic template vars (cblock offset)', async () => {
const { appClient } = await factory.deploy({
createParams: {
Expand Down
6 changes: 5 additions & 1 deletion src/types/logic-error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const LOGIC_ERROR = /transaction ([A-Z0-9]+): logic eval error: (.*). Details: .*pc=([0-9]+).*/
// inner tx 0 failed: logic eval error: err opcode executed. Details: app=6248, pc=29, opcodes=tx
const INNER_LOGIC_ERROR = /inner tx (\d+) failed:.*?pc=([0-9]+)/

/**
* Details about a smart contract logic error
Expand Down Expand Up @@ -26,13 +28,15 @@ export class LogicError extends Error {
static parseLogicError(error: any): LogicErrorDetails | undefined {
const errorMessage = error.message
const res = LOGIC_ERROR.exec(errorMessage)
const innerRes = INNER_LOGIC_ERROR.exec(errorMessage)

if (res === null || res.length <= 3) return undefined

return {
txId: res[1],
msg: res[2],
desc: errorMessage,
pc: parseInt(res[3] ? res[3] : '0'),
pc: parseInt(innerRes?.[2] ?? res[3] ?? '0'),
traces: error.traces,
} as LogicErrorDetails
}
Expand Down
3 changes: 3 additions & 0 deletions tests/example-contracts/inner_error/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
artifacts/*
!artifacts/*.arc56.json
!artifacts/*.approval.teal
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#pragma version 10
intcblock 1

// This TEAL was generated by TEALScript v0.106.3
// https://github.com/algorandfoundation/TEALScript

// This contract is compliant with and/or implements the following ARCs: [ ARC4 ]

// The following ten lines of TEAL handle initial program flow
// This pattern is used to make it easy for anyone to parse the start of the program and determine if a specific action is allowed
// Here, action refers to the OnComplete in combination with whether the app is being created or called
// Every possible action for this contract is represented in the switch statement
// If the action is not implemented in the contract, its respective branch will be "*NOT_IMPLEMENTED" which just contains "err"
txn ApplicationID
!
pushint 6
*
txn OnCompletion
+
switch *call_NoOp *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *create_NoOp *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED *NOT_IMPLEMENTED

*NOT_IMPLEMENTED:
// The requested action is not implemented in this contract. Are you using the correct OnComplete? Did you set your app ID?
err

// throwError()void
*abi_route_throwError:
// execute throwError()void
callsub throwError
intc 0 // 1
return

// throwError(): void
throwError:
proto 0 0

// custom error message
err
retsub

*abi_route_createApplication:
intc 0 // 1
return

*create_NoOp:
pushbytes 0xb8447b36 // method "createApplication()void"
txna ApplicationArgs 0
match *abi_route_createApplication

// this contract does not implement the given ABI method for create NoOp
err

*call_NoOp:
pushbytes 0x3d870d87 // method "throwError()void"
txna ApplicationArgs 0
match *abi_route_throwError

// this contract does not implement the given ABI method for call NoOp
err
Loading