Skip to content

Commit

Permalink
improve error messages for JSON syntax errors in perl-side configurat…
Browse files Browse the repository at this point in the history
…ion file loading. fixes #1061
  • Loading branch information
rbuels authored and cmdcolin committed Jun 2, 2018
1 parent 6cd1f5d commit 1ba503e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 1 deletion.
3 changes: 3 additions & 0 deletions release-notes.md
Expand Up @@ -27,6 +27,9 @@
dataset-selection page. Many thanks to @srobb1 for noticing this and reporting it!
(issue #1057, @rbuels)

* JSON syntax errors in the new configuration loading code now have better error messages.
Thanks to @billzt for pointing out the need for this! (issue #1061, @rbuels)

# Release 1.14.1 2018-05-02 22:04:33 UTC

## Minor improvements
Expand Down
4 changes: 3 additions & 1 deletion src/perl5/Bio/JBrowse/ConfigurationManager.pm
Expand Up @@ -29,7 +29,9 @@ sub slurpJSON {
<$f>
};

return JSON->new->decode($text)
my $json = eval { JSON->new->decode($text) };
die "syntax error in $file: $@" if $@;
return $json;
}

sub get_final_config {
Expand Down
1 change: 1 addition & 0 deletions tests/data/conf/malformed.json
@@ -0,0 +1 @@
{
21 changes: 21 additions & 0 deletions tests/perl_tests/configuration_manager.t
Expand Up @@ -45,4 +45,25 @@ is($config->{tracks}[5]{label}, 'zoo');

# print Dumper($config);

{
eval {
my $errorConfig = Bio::JBrowse::ConfigurationManager
->new(
conf => {
include => [ 'tests/data/conf/malformed.json' ],
baseUrl => '.',
overrideMe => 'rootConfig',
foo => 1,
tracks => [
{ label => "zoo", zonk => "quux"},
{ label => "zaz", honk => "beep" => root => "root!"}
]
})
->get_final_config;
};
my $error = $@;
like($error, qr/^syntax error in/, 'thrown error is explicitly a syntax error');
like($error, qr/malformed\.json\b/, 'thrown error contains malformed JSON file name');
}

done_testing;

0 comments on commit 1ba503e

Please sign in to comment.