fixed the issues where an empty property will cause a crash due to index out of range#2066
fixed the issues where an empty property will cause a crash due to index out of range#2066mourra950 wants to merge 3 commits intocookiecutter:mainfrom
Conversation
for more information, see https://pre-commit.ci
| if no_input: | ||
| return rendered_options[0] | ||
| if len(rendered_options) != 0: | ||
| return rendered_options[0] | ||
| else: | ||
| return None | ||
| return read_user_choice(key, rendered_options, prompts, prefix) |
There was a problem hiding this comment.
This cannot return None -- that contradicts the return type annotation (OrderedDict or str).
This should be formulated as:
if not rendered_options:
raise ValueError
if no_input:
return rendered_options[0]
return read_user_choice(key, rendered_options, prompts, prefix)read_user_choice() has a condition to ensure that the list of options isn't empty, but we can catch that here.
This also needs to have a test added to the test suite so that this issue is not simply fixed, but provably and permanently fixed.
There was a problem hiding this comment.
I ran into the same issue where an empty list raises an exception and kills the process. Would you accept this solution if it returned an empty string rather than None? and tests of course
There was a problem hiding this comment.
@meganlkm I don't have the ability to merge PRs in this repo, I can only review PRs.
It's been over a year since I provided feedback on this so I'm closing the PR, but if you're hitting this issue and have the ability to submit a PR, please do!
as described in the issue #2065 i have tried to manually fix it by checking the len of the array before returning the first element and avoid crashing other wise return None