Malformed poll causing server error

I made a mistake making a quick manual adjustment to a poll. The draft saved fine, but when I tried to post it, I got an “Internal Server Error.” I wasted quite a bit of time trying to figure out what was wrong. Some better feedback would have helped. I had no suspicion concerning my poll.

1 Like

A server error definitely shouldn’t happen for a malformed poll! Can you post the markup you used here? (Enclose it in [code][/code] if it decides to cause an issue here :wink: )

4 Likes

The reason I didn’t suspect the poll is because it renders fine in the preview area. Here’s the code (and yes, I tried to post the actual poll, but it did the same thing here):

[poll type=single results= on_vote min=1 max=4]

* Regularly
* Sometimes
* Rarely
* Never

[/poll]
6 Likes
ArgumentError ('single' is not a valid type)
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.0/lib/active_record/enum.rb:140:in `assert_valid_value'

/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.0/lib/active_record/enum.rb:140:in `assert_valid_value'
/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activemodel-5.2.0/lib/active_model/attribute.rb:71:in `with_value_from_user'

....

/var/www/discourse/vendor/bundle/ruby/2.5.0/gems/activerecord-5.2.0/lib/active_record/persistence.rb:52:in `create!'
/var/www/discourse/plugins/poll/plugin.rb:238:in `create!'

We are trying to set a value on an enum that is not allowed and not handling the exception.

5 Likes

That’s a good repro, thanks!

3 Likes

@nbianca can you make sure we’re properly handling this exception and showing the proper error message to the user?

4 Likes

Added argument validation in

https://github.com/discourse/discourse/pull/6740

6 Likes