Skip to content
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

Handle error when value is not a string #187

Open
lulalala opened this issue Aug 21, 2022 · 0 comments
Open

Handle error when value is not a string #187

lulalala opened this issue Aug 21, 2022 · 0 comments

Comments

@lulalala
Copy link

Describe the problem

I accidentally provided a hash {} as value, and this gives cryptic error:

Steps to reproduce the problem

prompt.ask("Foo?", value: {})

Actual behaviour

Foo? {}  (rib):18:in `main'
tty-prompt-0.23.1/lib/tty/prompt.rb:202:in `ask'
tty-prompt-0.23.1/lib/tty/prompt.rb:181:in `invoke_question'
tty-prompt-0.23.1/lib/tty/prompt/question.rb:110:in `call'
tty-reader-0.9.0/lib/tty/reader.rb:118:in `subscribe'
tty-prompt-0.23.1/lib/tty/prompt/question.rb:111:in `block in call'
tty-prompt-0.23.1/lib/tty/prompt/question.rb:121:in `render'
tty-prompt-0.23.1/lib/tty/prompt/question.rb:162:in `process_input'
tty-prompt-0.23.1/lib/tty/prompt/question.rb:178:in `read_input'
tty-reader-0.9.0/lib/tty/reader.rb:265:in `read_line'
tty-reader-0.9.0/lib/tty/reader.rb:344:in `clear_display'
tty-reader-0.9.0/lib/tty/reader/line.rb:256:in `size'
tty-reader-0.9.0/lib/tty/reader/line.rb:249:in `text_size'
tty-reader-0.9.0/lib/tty/reader/line.rb:18:in `sanitize'
NoMethodError: undefined method `gsub' for {}:Hash

Expected behaviour

I think there are a few ways this can be more friendly:

  • Update the document to clarify String as the expected value
  • If non-String is provided, maybe raise an error before user input

Describe your environment

  • OS version: Mac OS X 12.4
  • Ruby version: 2.7.6
  • TTY::Prompt version: 0.23.1
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

No branches or pull requests

1 participant