What does it mean when Click exits with exit code 2?
Asked Answered
S

2

6

I am currently testing a Click CLI application and get result.exit_code == 2. Why does that happen?

Stollings answered 30/8, 2018 at 13:6 Comment(10)
Where are you getting that error? It's probably almost same as any other exit code 2. Usually means bad input data.Sowell
What's your code, and what are the arguments you passed to the script?Everybody
Related. From your deleted answer, it seems that you realize you're passing the input data incorrectly, so I'm a bit unsure of what you're asking.Sowell
I thought I figured it out and wrote the answer while I was running the tests. Still failed, even with the adjustments :-(Stollings
I had this error 2 a couple of times in other projects before and thought I'd help my future self with that question / answer.Stollings
I pass a list of strings to the function. I have no idea what is wrong there and I cannot share all of the code. Is there any way to get more information from click?Stollings
You don't have to (and shouldn't) share all of the code. You should post a minimal reproducible example.Everybody
@Everybody You're funny^^ - Do you assume with 35k points I don't know this link?Stollings
Then why have you not provided one?Sowell
Because it is not that simple and not necessary for this question (as proven by my answer and the answer of Chris).Stollings
S
4

I ran

result = runner.invoke(cli, ['sync'])

instead of

result = runner.invoke(cli, ['--debug', 'sync'])

So you need to specify the flag as entered via CLI, not only pass the parameters consumed by the function if you use @click.option.

Additionally, the I made a typo for one of the flags.

How to debug

  1. Look at the parameters you pass to runner.invoke (simplest: print it)
  2. Execute it via CLI (e.g. cli(['--debug', 'sync']))

In my case this gave me the message

Error: no such option: --sync  Did you mean --syncs?
Stollings answered 30/8, 2018 at 13:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.