Skip to content
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

feat: improve error handling in TraceManager with TraceError class #5603

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
31 changes: 19 additions & 12 deletions libs/remix-debug/src/trace/traceManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import { TraceCache } from './traceCache'
import { TraceStepManager } from './traceStepManager'
import { isCreateInstruction } from './traceHelper'

export class TraceError extends Error {
constructor(message: string, public readonly stepIndex?: number) {
super(message)
this.name = 'TraceError'
Object.setPrototypeOf(this, TraceError.prototype)
}
}

export class TraceManager {
web3
fork: string
Expand Down Expand Up @@ -126,38 +134,38 @@ export class TraceManager {
try {
this.checkRequestedStep(stepIndex)
} catch (check) {
throw new Error(check)
throw new TraceError(`Invalid step index: ${check.message}`, stepIndex)
}
const callsPath = util.buildCallPath(stepIndex, this.traceCache.callsTree.call)
if (callsPath === null) throw new Error('no call path built')
if (callsPath === null) throw new TraceError('Failed to build call path: no valid path found', stepIndex)
return callsPath
}

getCallStackAt (stepIndex) {
try {
this.checkRequestedStep(stepIndex)
} catch (check) {
throw new Error(check)
throw new TraceError(`Invalid step index: ${check.message}`, stepIndex)
}
const call = util.findCall(stepIndex, this.traceCache.callsTree.call)
if (call === null) {
throw new Error('no callstack found')
throw new TraceError('No callstack found for the given step index', stepIndex)
}
return call.callStack
}

getStackAt (stepIndex) {
this.checkRequestedStep(stepIndex)
if (this.trace[stepIndex] && this.trace[stepIndex].stack) { // there's always a stack
try {
this.checkRequestedStep(stepIndex)
} catch (check) {
throw new TraceError(`Invalid step index: ${check.message}`, stepIndex)
}
if (this.trace[stepIndex] && this.trace[stepIndex].stack) {
if (Array.isArray(this.trace[stepIndex].stack)) {
const stack = this.trace[stepIndex].stack.slice(0)
stack.reverse()
return stack.map(el => toHexPaddedString(el))
} else {
// it's an object coming from the VM.
// for performance reasons,
// we don't turn the stack coming from the VM into an array when the tx is executed
// but now when the app needs it.
const stack = []
for (const prop in this.trace[stepIndex].stack) {
if (prop !== 'length') {
Expand All @@ -167,9 +175,8 @@ export class TraceManager {
stack.reverse()
return stack
}
} else {
throw new Error('no stack found')
}
throw new TraceError('No stack data found for the given step index', stepIndex)
}

getLastCallChangeSince (stepIndex) {
Expand Down