truffle debugger: TypeError: Cannot read property 'line' of undefined

truffle debugger: TypeError: Cannot read property 'line' of undefined

我正在尝试使用 Truffle 4.1.0 调试 Solidity 代码。 调试器正常启动,显示第一行,但您无法单步执行合约!

终端显示的错误的完整堆栈跟踪是:

 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)

深入研究方法formatRangeLines: function(source, range, contextBefore)console.log(range); 它打印:

{ start: undefined, end: undefined }

实际上,在这个块访问 range.start 时引发的异常:

var startBeforeIndex = Math.max(
  range.start.line - contextBefore, 0
);

有什么建议吗? 谢谢,

更新: 此问题已在 Truffle 版本 4.1.4 (reference) 中得到解决。

然而,如果您更新了您的 Truffle 版本,您仍然会遇到这个问题。在您的控制台上尝试 运行(这是为了强制更新您所有已编译的智能合约的字节码以使其符合最新版本):

truffle migrate --reset --compile-all


由于当前版本的 Truffle Debugger(即实验版)存在错误,因此 Debugger 无法跳转到另一个文件。

错误出现在这里:https://github.com/trufflesuite/truffle/issues/826

因此,为了克服当前的错误,所有智能合约代码都必须在一个文件中。希望有一个工具可以帮助解决这个问题:https://github.com/poanetwork/solidity-flattener