# Malformed poll causing server error

**URL:** https://meta.discourse.org/t/malformed-poll-causing-server-error/103468
**Category:** Bug
**Created:** [December 4, 2018, 3:11pm UTC](https://meta.discourse.org/t/malformed-poll-causing-server-error/103468 "2018-12-04T15:11:45Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![jtbayly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jtbayly/32/119510_2.png) [@jtbayly](https://meta.discourse.org/u/jtbayly)
#### Post date: [December 4, 2018, 3:11pm UTC](https://meta.discourse.org/t/malformed-poll-causing-server-error/103468/1 "2018-12-04T15:11:46Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [December 4, 2018, 3:17pm UTC](https://meta.discourse.org/t/malformed-poll-causing-server-error/103468/2 "2018-12-04T15:17:28Z")

</div>

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 😉 )

---

<div class="post-metadata">

### Author: ![jtbayly](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jtbayly/32/119510_2.png) [@jtbayly](https://meta.discourse.org/u/jtbayly)
#### Post date: [December 4, 2018, 3:21pm UTC](https://meta.discourse.org/t/malformed-poll-causing-server-error/103468/3 "2018-12-04T15:21:24Z")

</div>

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):

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

* Regularly
* Sometimes
* Rarely
* Never

[/poll]
```

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [December 4, 2018, 11:05pm UTC](https://meta.discourse.org/t/malformed-poll-causing-server-error/103468/4 "2018-12-04T23:05:37Z")

</div>

```plaintext
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.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [December 5, 2018, 1:09am UTC](https://meta.discourse.org/t/malformed-poll-causing-server-error/103468/6 "2018-12-05T01:09:36Z")

</div>

That’s a good repro, thanks!

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [December 7, 2018, 2:11pm UTC](https://meta.discourse.org/t/malformed-poll-causing-server-error/103468/8 "2018-12-07T14:11:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![nbianca](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/nbianca/32/157984_2.png) [@nbianca](https://meta.discourse.org/u/nbianca)
#### Post date: [December 9, 2018, 6:23pm UTC](https://meta.discourse.org/t/malformed-poll-causing-server-error/103468/9 "2018-12-09T18:23:26Z")

</div>

Added argument validation in

[https://github.com/discourse/discourse/pull/6740](https://github.com/discourse/discourse/pull/6740)

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [December 10, 2018, 3:41am UTC](https://meta.discourse.org/t/malformed-poll-causing-server-error/103468/10 "2018-12-10T03:41:14Z")

</div>


