Skip to content

Invalid second argument. Expected object but received string. #959

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

Closed
DenisCarriere opened this issue Dec 1, 2017 · 6 comments · Fixed by #968
Closed

Invalid second argument. Expected object but received string. #959

DenisCarriere opened this issue Dec 1, 2017 · 6 comments · Fixed by #968

Comments

@DenisCarriere
Copy link

Invalid second argument. Expected object but received string.

  • version: 5.3.3
  • running: CLI

Seems to be an error in the latest release of the CLI, maybe yargs updated their build and it's throwing this error, it's not critical since documentation still continues running after the Error message.

You can replicate this issue by using any of the CLI commands.

$ documentation readme --help

YError: Invalid second argument. Expected object but received string.
    at argumentTypeError (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/lib/argsert.js:65:9)
    at parsed.optional.forEach (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/lib/argsert.js:47:39)
    at Array.forEach (<anonymous>)
    at argsert (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/lib/argsert.js:42:21)
    at Object.option (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/yargs.js:550:5)
    at Object.keys.forEach (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/lib/command.js:210:20)
    at Array.forEach (<anonymous>)
    at Object.runCommand (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/lib/command.js:209:43)
    at Object.parseArgs [as _parseArgs] (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/yargs.js:970:30)
    at Object.get [as argv] (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/yargs.js:912:21)
YError: Invalid second argument. Expected object but received string.
    at argumentTypeError (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/lib/argsert.js:65:9)
    at parsed.optional.forEach (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/lib/argsert.js:47:39)
    at Array.forEach (<anonymous>)
    at argsert (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/lib/argsert.js:42:21)
    at Object.option (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/yargs.js:550:5)
    at Object.keys.forEach (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/lib/command.js:210:20)
    at Array.forEach (<anonymous>)
    at Object.runCommand (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/lib/command.js:209:43)
    at Object.parseArgs [as _parseArgs] (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/yargs.js:970:30)
    at Object.get [as argv] (/Users/deniscarriere/GitHub/osmlinter/node_modules/yargs/yargs.js:912:21)
node_modules/.bin/documentation readme [input..]

Options:
  --version        Show version number                                 [boolean]
  --help           Show help                                           [boolean]
  --readme-file    The markdown file into which to inject documentation
                                                          [default: "README.md"]
  --section, -s    The section heading after which to inject generated
                   documentation                                      [required]
  --diff-only, -d  Instead of updating the given README with the generated
                   documentation, just check if its contents match, exiting
                   nonzero if not.                              [default: false]
  --quiet, -q      Quiet mode: do not print messages or README diff to stdout.
                                                                [default: false]
@parro-it
Copy link

parro-it commented Dec 5, 2017

I got the same error, and did some investigation on the error.
It seems yargs is expeting to receive a string and an object
as key and opt arguments at node_modules/yargs/yargs.js:550.
It throw because it receive instead:

key: 'usage',
opt: 'Usage: documentation readme [--readme-file=README.md] --section "API" [--compare-only] [other documentationjs options]'

It happens I'm using wrong argument to call docuemntation, and it is messing something
trying to write usage to stderr.

The error go away when I correct call syntax.
It seems 'documentation readme --help` is wrong synatx, too.

Hop it help...

@SirMcPotato
Copy link

Yep, same error for me, using documentation readme index.js --section=doc, like found in examples.
Anyway, documentation still generating correctly the markdown doc despite this error, as @DenisCarriere said.

@tmcw
Copy link
Member

tmcw commented Dec 6, 2017

🤔 Yep, looks like yargs is throwing some chaos into minor version updates. I'll try a few versions and maybe just pin us to one that works.

@parro-it
Copy link

parro-it commented Dec 6, 2017

@tmcw please note also that the reported usage is incongruent with the readme file: the former says to use --section="API" while the latter says --section "API"

@mmoss
Copy link

mmoss commented Dec 7, 2017

@parro-it did you manage to get it working with either of those syntaxes? I can't seem to get around this error (i.e. my README.md is never updated...)

@hugojosefson
Copy link
Contributor

hugojosefson commented Dec 8, 2017

@tmcw I found what causes yargs to bark. It's the usage and example keys with string values here:

module.exports.builder = {
usage:
'Usage: documentation readme [--readme-file=README.md] --section "API"' +
' [--compare-only] [other documentationjs options]',
example: 'documentation readme index.js -s "API Docs" --github',
'readme-file': {
describe: 'The markdown file into which to inject documentation',
default: 'README.md'
},

yargs@>=7 starts throwing when it's given non-object values. Even before, it ignored them.

So I deleted and moved them in PR #968.

Now you don't need to pin to yargs@<7 😄 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants