dredd init generates invalid file

Created on 13 Feb 2019  路  8Comments  路  Source: apiaryio/dredd

Describe the bug
I ran dredd init which generates a dredd.yml config file.
When I run dredd --dry-run I get the following error:

error: unknown tag !<tag:yaml.org,2002:js/undefined> at line 4, column 47:
     ... g:yaml.org,2002:js/undefined> ''

Looking in the generated config there is this line:

language: !<tag:yaml.org,2002:js/undefined> ''

This seems to be what is broken.

Deleting that line fixes the problem.

What's your dredd --version output?

dredd v8.0.0 (Darwin 18.2.0; x64)
configuration bug easy to fix released

Most helpful comment

ha, ok I have found the problem

when you run dredd init it asks you several questions

If you answer "no" here:

? Do you want to use hooks to customize Dredd's behavior? No

...then it gives you

language: !<tag:yaml.org,2002:js/undefined> ''

Answering "yes" and choosing a language option gives you e.g.:

language: python

All 8 comments

Wow, thanks for reporting this! Did you run dredd init in an empty folder or do you have any files there? Could you send me ls of that folder in that case? I'm interested mainly in filenames and extensions. The init script does some guessing on which programming language you might be using or which API description format you're using and the bug could be there.

CODEOWNERS                              celeryconfig.pyc                        celeryconfig_test_dead_letter.py        docker-compose.yml                      requirements-test.txt
Dockerfile                              celeryconfig_broadcast_events.py        celeryconfig_test_dead_letter.pyc       dredd.py                                requirements.txt
Dockerfile.aws                          celeryconfig_broadcast_events.pyc       celeryconfig_test_worker.py             dredd.yml                               run_in_env.sh
Makefile                                celeryconfig_broadcast_events_worker.py celeryconfig_test_worker.pyc            garage                                  runtime.txt
Perffile                                celeryconfig_graph.py                   celeryconfig_worker.py                  newrelic.ini                            test_garage.sqlite
README.md                               celeryconfig_graph.pyc                  clear_cloudfront_cache.py               orig.pyc                                test_ordered_logs.sqlite
VENV                                    celeryconfig_graph_worker.py            databases.yaml                          pyproject.toml                          test_report.sqlite
bin                                     celeryconfig_test.py                    db                                      requirements-aws.txt                    uwsgi.ini
celeryconfig.py                         celeryconfig_test.pyc                   docker                                  requirements-dev.txt

Thanks, I'll try to debug the issue 馃槄 If you by any chance manage to isolate the problem to a certain combination of files, please let us know here.

ha, ok I have found the problem

when you run dredd init it asks you several questions

If you answer "no" here:

? Do you want to use hooks to customize Dredd's behavior? No

...then it gives you

language: !<tag:yaml.org,2002:js/undefined> ''

Answering "yes" and choosing a language option gives you e.g.:

language: python

Awesome, thanks! 馃檹

Bear in mind that questions which when resolves to false are not getting asked, and thus their default value gets ignored (https://github.com/SBoudrias/Inquirer.js/issues/740). For example:

https://github.com/apiaryio/dredd/blob/07c8c8157de47658d5e8f8f4c58ee10ea1f8ef21/lib/init.js#L117-L123

When detected.ci doesn't include the mentioned string, the question won't be asked, and the gathered answers will not have key appveyor: true. If this is the intended behavior then leave it as-is.

However, if the intended behavior is to use defaults even when the question is not asked, we may need to adopt a generic handler for such cases. I would suggest that for such keys their default values reside outside the prompt (i.e. in a default config Object), while prompt's answers serve as an overrides to the default config.

Thanks @kettanaito for figuring out the issue. Not using the default when the question isn't asked is not the intended behavior, I assumed Inquirer would use the default in that case when I was writing the code.

prompt's answers serve as an overrides to the default config

That sounds like a good idea.

:tada: This issue has been resolved in version 8.0.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

Was this page helpful?
0 / 5 - 0 ratings