trufflesuite / truffle

:warning: The Truffle Suite is being sunset. For information on ongoing support, migration options and FAQs, visit the Consensys blog. Thank you for all the support over the years.
https://consensys.io/blog/consensys-announces-the-sunset-of-truffle-and-ganache-and-new-hardhat?utm_source=github&utm_medium=referral&utm_campaign=2023_Sep_truffle-sunset-2023_announcement_
MIT License
14.02k stars 2.31k forks source link

Parsing issue with multiple spaces #399

Closed illuzen closed 2 years ago

illuzen commented 7 years ago

Issue

Not sure when this was introduced, but in the yargs-parser node module, we now break when double spaces are introduced between certain tokens, so

MultiSigWallet.new(web3.eth.accounts, 3 ).then(function(i){wallet = i}) is fine, but

MultiSigWallet.new(web3.eth.accounts, 3 ).then(function(i){wallet = i}) throws

TypeError: Cannot read property 'match' of undefined at parse (/usr/local/lib/node_modules/truffle/node_modules/yargs-parser/index.js:122:12) at Function.Parser.detailed (/usr/local/lib/node_modules/truffle/node_modules/yargs-parser/index.js:756:10) at parseArgs (/usr/local/lib/node_modules/truffle/node_modules/yargs/yargs.js:873:27) at Object.Yargs.self.parse (/usr/local/lib/node_modules/truffle/node_modules/yargs/yargs.js:499:18) at Command.getCommand (/usr/local/lib/node_modules/truffle/lib/command.js:19:24) at TruffleInterpreter.interpret (/usr/local/lib/node_modules/truffle/lib/repl.js:104:20) at bound (domain.js:280:14) at REPLServer.runBound [as eval] (domain.js:293:12) at REPLServer.onLine (repl.js:536:10) at emitOne (events.js:96:13) at REPLServer.emit (events.js:191:7) at REPLServer.Interface._onLine (readline.js:238:10) at REPLServer.Interface._line (readline.js:581:8) at REPLServer.Interface._ttyWrite (readline.js:860:14) at REPLServer.self._ttyWrite (repl.js:609:7) at ReadStream.onkeypress (readline.js:117:10)

Printing out args from yargs-parser.parse shows it is tokenizing funny

[ 'MultiSigWallet.new(web3.eth.accounts,',
  '3',
  ').then(function(i){wallet',
  ,                     // <--------- empty string is token?
  '=',
  'i})' ]

sorry I don't have time right now to debug further, it's not critical, just spent half an hour chasing it down. It might be an issue in yargs-parser?

to Reproduce

truffle console

(dev)> MyContract.new(args).then(function(i){ c = i})

Expected Behavior

just eat the extra space

Actual Results

trys to consume empty string as a token

Environment

bingtimren commented 6 years ago

Encountered the same problem. The only difference between (below) the first command (failed) and the second (success), is an extra space after "=" in the first command

truffle(develop)> msgHash = web3.sha3('\x19Ethereum Signed Message:\n' + message.length + message); TypeError: Cannot read property 'match' of undefined at parse (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:319624:13) at Function.Parser.detailed (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:320258:10) at parseArgs (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:322455:27) at Object.Yargs.self.parse (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:322081:18) at Command.getCommand (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:160684:24) at Console.interpret (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:202605:20) at ReplManager.interpret (/usr/local/lib/node_modules/truffle/build/cli.bundled.js:203345:18) at bound (domain.js:301:14) at REPLServer.runBound [as eval] (domain.js:314:12) at REPLServer.onLine (repl.js:468:10)

truffle(develop)> msgHash = web3.sha3('\x19Ethereum Signed Message:\n' + message.length + message); '0xa3cf95943562e78a694789d6ff02163344c42aa6e4495117eba9a9da6e60c866'

gnidan commented 5 years ago

Is this still an issue on v5? Let us know! Thanks!

bingtimren commented 5 years ago

Yes it's still an issue. Below, the second command failed only because of an extra space after "=". Truffle version is

$ truffle version Truffle v5.0.1 (core: 5.0.1) Solidity v0.5.0 (solc-js) Node v8.10.0

truffle(develop)> msgHash = web3.utils.sha3('\x19Ethereum Signed Message:\n' + message.length + message);
'0xe28f5ff58ff3f1b24d6ba6e3b3e95e49589e8dd59b91296e76189d6ad2857b22'
truffle(develop)> msgHash =  web3.utils.sha3('\x19Ethereum Signed Message:\n' + message.length + message);
TypeError: Cannot read property 'match' of undefined
    at ReadStream.onData (readline.js:1011:36)
    at emitKeys.next (<anonymous>)
    at emitKeys (internal/readline.js:420:14)
    at ReadStream.emit (events.js:214:7)
    at emitTwo (events.js:126:13)
    at ReadStream.onkeypress (readline.js:160:10)
    at REPLServer.self._ttyWrite (repl.js:537:7)
    at REPLServer.Interface._ttyWrite (readline.js:911:14)
    at REPLServer.Interface._line (readline.js:631:8)
    at REPLServer.Interface._onLine (readline.js:282:10)
    at REPLServer.emit (events.js:211:7)
    at emitOne (events.js:116:13)
    at REPLServer.onLine (repl.js:468:10)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at bound (domain.js:301:14)
    at ReplManager.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/repl.js:118:1)
    at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/console.js:138:1)
    at Command.getCommand (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/command.js:21:1)
    at Object.Yargs.self.parse (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/~/yargs/yargs.js:532:1)
    at Object.Yargs.self._parseArgs (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/~/yargs/yargs.js:938:1)
    at Function.Parser.detailed (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/~/yargs-parser/index.js:761:1)
    at parse (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/~/yargs-parser/index.js:125:1)
haltman-at commented 2 years ago

OK, this should be fixed now!