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

Brian E. Lozier brian at massassi.com
Mon Nov 14 17:16:29 CET 2011

On Mon, Nov 14, 2011 at 8:11 AM, David Precious <davidp at preshweb.co.uk> wrote:
> 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."

I think this type of message would be useful, but...

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

It seems like it would be better to contribute to the YAML module
itself so it could report errors like this, as opposed to doing
post-processing on an already-failed file.  Also, aren't tabs allowed
inside quoted values?  By the time you take into account all the valid
possibilities, you will have rewritten a YAML parser.

> 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)
> _______________________________________________
> Dancer-users mailing list
> Dancer-users at perldancer.org
> http://www.backup-manager.org/cgi-bin/listinfo/dancer-users

More information about the Dancer-users mailing list