I am trying to use Truffle 4.1.0 to debug Solidity code. Debugger starts up properly, displaying the first lines, but you can't step through contract!
The full stacktrace of the error as shown at the Terminal is:
TypeError: Cannot read property 'line' of undefined
at Object.formatRangeLines (/usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-debug-utils/index.js:201:1)
at printState (/usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-core/lib/commands/debug.js:125:1)
at Object.interpreter (/usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-core/lib/commands/debug.js:404:1)
at ReplManager.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/~/truffle-core/lib/repl.js:119:1)
at bound (domain.js:280:14)
at REPLServer.runBound [as eval] (domain.js:293:12)
at REPLServer.<anonymous> (repl.js:539:10)
at emitOne (events.js:96:13)
at REPLServer.emit (events.js:188:7)
at REPLServer.Interface._onLine (readline.js:232:10)
at REPLServer.Interface._line (readline.js:583:8)
at REPLServer.Interface._ttyWrite (readline.js:860:14)
at REPLServer.self._ttyWrite (repl.js:612:7)
at ReadStream.onkeypress (readline.js:119:10)
at emitTwo (events.js:106:13)
at ReadStream.emit (events.js:191:7)
at emitKeys (internal/readline.js:389:14)
at next (native)
at ReadStream.onData (readline.js:970:36)
at emitOne (events.js:96:13)
at ReadStream.emit (events.js:188:7)
at readableAddChunk (_stream_readable.js:176:18)
at ReadStream.Readable.push (_stream_readable.js:134:10)
at TTY.onread (net.js:547:20)
Digging into method formatRangeLines: function(source, range, contextBefore)
When console.log(range);
it prints:
{ start: undefined, end: undefined }
Actually, the exception raised when accessing range.start
at this block:
var startBeforeIndex = Math.max(
range.start.line - contextBefore, 0
);
Any suggestions? Thanks,
Update: This issue was resolved at Truffle version 4.1.4 (reference).
However, if you updated your Truffle version but you still face the issue. Try running at your console (this is to enforce updating all your compiled smart contracts' bytecode to be according to the latest version):
truffle migrate --reset --compile-all
Due to a bug at the current version of Truffle Debugger (that is experimental version), the Debugger cannot jump to another file.
The bug is raised here: https://github.com/trufflesuite/truffle/issues/826
So to overcome the current bug, all the Smart Contracts code has to be in one file. Hopefully, There is a tool that can help with this: https://github.com/poanetwork/solidity-flattener