Photo-1 Photo-2 Photo-3 Photo-4 Photo-5 Photo-6



Full-time web developer. Part-time smart ass.

I'm Brent Collier.

After a year and a half as an engineer on Twitter's Trust & Safety team, I'm looking for my next gig. Contact me if you know of something interesting.


TypeError: expected Array (got String) for param WTF

Posted on 10/17/2014

I was in the middle of completely overhauling some backend code, while attempting to reuse as much as possible of the semi-complex frontend. The form and js were basically the same, but I had to do some minor modifications to make it jive with the new ActiveRecord model that was backing it.

I had made what appeared to be the necessary changes, so why not give it a try? It's not like you can write tests for this stuff, right? RIGHT? I mean, it's javascript, client-side code, c'mon...

Anyway, I clicked the submit button on my form, expecting to watch the dev log for my incoming request, expecting to verify that my input params were correct, expecting to see something. But I didn't.

Blank terminal window


In the browser there was a flash message with an error. That means there was definitely a request. But nothing in the dev log. How does that happen?

I checked the Network tab in the Chrome dev tools. There it was, a 500. Looking at the response, I could see the problem...

It had blown up in rack, not even making it to the Rails app. That explained why there was nothing in the dev log.

It was complaining about the source input, but what was the problem? I double-checked the input name...

<input name="source[]" type="text">

...made sure that it was the right format to return an array. It was. What the hell was going on? Finally, after searching through the view template, I realized the problem. There was another input - a hidden one, with the same name.

<input name="source" type="hidden">

That was it. Two inputs, both named "source". One a string, and the other an array. Fuck me.

I renamed one of the inputs, and BOOM, everything worked. Life goes on.