[Dancer-users] config.yml YAML tabs vs spaces

Assaf Gordon gordon at cshl.edu
Thu Nov 10 19:04:49 CET 2011


Alex Mestiashvili wrote, On 11/10/11 11:47:
> On 11/10/2011 04:53 PM, Philippe Bruhat (BooK) wrote:
>> On Thu, Nov 10, 2011 at 02:39:14PM +0100, Alex Mestiashvili wrote:
>>   
>>> using spaces solved the problem . So I think that it will be not bad
>>> to mention somewhere in the documentation that tabs shouldn't be used
>>> in config.yml .
>>>
>>
>>   
> I agree  and after all I learned something new, but Dancer positions
> itself like "Dead Simple" and imho it won't hurt to have a line stating
> that config.yml should use YAML syntax .
> Such obvious fact that .yml means man YAML wasn't clear for me .

I couldn't agree more.

The YAML-related Dancer error message is anything but "dead simple" (it is very perlish-wise informative, though).
It took me a long time to understand what's wrong, way too much time compare to the minor offense of a single tab.

Here's the error I get in current Dancer due to Tab in "config.yml":
====
Use of uninitialized value in subtraction (-) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 726, <$IN> line 1.
Use of uninitialized value in numeric eq (==) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 361, <$IN> line 1.
Use of uninitialized value in numeric eq (==) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 361, <$IN> line 1.
Use of uninitialized value in numeric eq (==) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 361, <$IN> line 1.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 331, <$IN> line 1.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 338, <$IN> line 1.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 342, <$IN> line 1.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 407, <$IN> line 1.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 407, <$IN> line 1.
Unable to parse the configuration file: /home/gordon/projects/perl_dancer_test/badyaml/config.yml: YAML Error: Invalid element in map
   Code: YAML_LOAD_ERR_BAD_MAP_ELEMENT
   Line: 27
   Document: 1
 at /usr/local/share/perl/5.12.4/YAML.pm line 36
 at /usr/local/share/perl/5.12.4/Dancer/Config.pm line 204
	Dancer::Config::load_settings_from_yaml('/home/gordon/projects/perl_dancer_test/badyaml/config.yml') called at /usr/local/share/perl/5.12.4/Dancer/Config.pm line 181
	Dancer::Config::load('Dancer::Config') called at /usr/local/share/perl/5.12.4/Dancer.pm line 230
	Dancer::import('Dancer') called at ./bin/app.pl line 2
	main::BEGIN() called at /usr/local/share/perl/5.12.4/Dancer.pm line 2
	eval {...} called at /usr/local/share/perl/5.12.4/Dancer.pm line 2
BEGIN failed--compilation aborted at ./bin/app.pl line 2.
====

As a Dancer newbie, it takes some time to find the only relevant message in the middle of this mess: "unable to parse the configuration file".

Perhaps something like this minor change would be friendlier ?
  https://github.com/agordon/Dancer/commit/f3aea9d810b9f08d34946a1acc657e78686ba73d


The error message would then become:
=====
Use of uninitialized value in subtraction (-) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 726, <$IN> line 1.
Use of uninitialized value in numeric eq (==) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 361, <$IN> line 1.
Use of uninitialized value in numeric eq (==) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 361, <$IN> line 1.
Use of uninitialized value in numeric eq (==) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 361, <$IN> line 1.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 331, <$IN> line 1.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 338, <$IN> line 1.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 342, <$IN> line 1.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 407, <$IN> line 1.
Use of uninitialized value in substitution (s///) at /usr/local/share/perl/5.12.4/YAML/Loader.pm line 407, <$IN> line 1.


YAML Error: Invalid element in map
   Code: YAML_LOAD_ERR_BAD_MAP_ELEMENT
   Line: 27
   Document: 1
 at /usr/local/share/perl/5.12.4/YAML.pm line 36


Error in configuration file:
  /home/gordon/projects/perl_dancer_test/badyaml/config.yml
Please ensure it is a valid YAML file.

BEGIN failed--compilation aborted at ./bin/app.pl line 2.
=====

It's still too verbose (couldn't find a way to disable YAML's warnings, and the "BEGIN failed" is there to stay) - but at least it's easier to read.


-gordon


More information about the Dancer-users mailing list