[Dancer-users] User-friendly errors on YAML parsing failures (was: Re: dancer croaking with a strange error in config.yml)

David Precious davidp at preshweb.co.uk
Mon Nov 14 17:11:25 CET 2011


On Monday 14 November 2011 15:33:19 Mr. Puneet Kishor wrote:
> Solved... (it was an invisible character, but see below) --
[...] 
> Opened the file again in vi and `:set list`, and bingo! there was a
> character that looked like ^I, a result of pressing 'tab'
> 
> Seems like YAML doesn't like tabs. I deleted that character, and now
> everything is well.

Ah, good stuff, glad to hear you got it sorted.

I'm beginning to wonder if we should add a little magic to Dancer to catch 
YAML parsing errors, and, at the very least, output a message making it 
clearer that the problem is not with Dancer but that YAML.pm couldn't parse 
the YAML and provide a link to the YAML spec, and perhaps also, look for any 
tabs in the file (before any non-whitespace chars) and, if found, output a "It 
looks like you've got tabs in the file; don't do that" message.

I agree to some degree with previous messages on the subject of YAML parsing 
failures that it's not Dancer's problem, but if we can make things easier for 
the user at little cost, I think we should.

So, what I propose is, if the parsing fails, log a message something like:

  "It wasn't possible to parse your config.yml file.  This file needs to be 
valid YAML in order to be parsed by YAML.pm - please see the YAML 
specifications for details.  In particular, YAML is sensitive to indentation - 
use a consistent number of spaces, do not use tabs."

Also, if the parsing failed, open config.yml and skim over it, and report any 
lines which included tabs, with the line number.

This would be a fairly small amount of code, and would only come into play if 
the parsing of config.yml failed (in which case, the app is unlikely to start 
anyway, so it's not like it's extra complexity / expense in the majority of 
cases).


If other devs agree that makes sense, I'll rock up something like this, 
initially for Dancer then see about porting it forwards to Dancer2.

I was going to append "when I have a circular tuit", but unfortunately I no 
longer have that excuse, thanks to the guys at LPW2011:

http://www.preshweb.co.uk/downloads/tuit/lpw2011-tuit-bothsides.jpg

:)

(I should have picked up a whole bag ;) )


-- 
David Precious  ("bigpresh")
http://www.preshweb.co.uk/

   "Programming is like sex. One mistake and you have to support
   it for the rest of your life". (Michael Sinz)


More information about the Dancer-users mailing list