[DRE-commits] [librarian-puppet] 73/153: Issue #269 Better error message if metadata.json is bad

Stig Sandbeck Mathisen ssm at debian.org
Wed Jun 1 20:30:44 UTC 2016


This is an automated email from the git hooks/post-receive script.

ssm pushed a commit to branch master
in repository librarian-puppet.

commit d5b28765f2c0f6ed0e09b62a6c76f833e1cb0113
Author: Carlos Sanchez <carlos at apache.org>
Date:   Wed Nov 19 09:26:38 2014 +0100

    Issue #269 Better error message if metadata.json is bad
---
 Changelog.md                         | 2 ++
 features/install.feature             | 8 ++++++++
 lib/librarian/puppet/dsl.rb          | 7 ++++++-
 lib/librarian/puppet/source/local.rb | 6 +++++-
 4 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/Changelog.md b/Changelog.md
index b93fed4..09b169d 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -4,6 +4,7 @@
 
 ### 2.1.0
 
+ * [Issue #269](https://github.com/rodjek/librarian-puppet/issues/269) Better error message if metadata.json is bad
  * [Issue #264](https://github.com/rodjek/librarian-puppet/issues/264) Copying files can cause permission problems on Windows
 
 ### 2.0.0
@@ -15,6 +16,7 @@
 
 ### 1.5.0
 
+ * [Issue #269](https://github.com/rodjek/librarian-puppet/issues/269) Better error message if metadata.json is bad
  * [Issue #264](https://github.com/rodjek/librarian-puppet/issues/264) Copying files can cause permission problems on Windows
 
 ### 1.4.0
diff --git a/features/install.feature b/features/install.feature
index 037930a..fced039 100644
--- a/features/install.feature
+++ b/features/install.feature
@@ -8,6 +8,14 @@ Feature: cli/install
     Then the output should match /^Metadata file does not exist: .*metadata.json$/
     And the exit status should be 1
 
+  Scenario: Running install with bad metadata.json
+    Given a file named "metadata.json" with:
+    """
+    """
+    When I run `librarian-puppet install`
+    Then the output should match /^Unable to parse json file .*metadata.json: .*$/
+    And the exit status should be 1
+
   Scenario: Install a module dependency from git and forge should be deterministic
     Given a file named "Puppetfile" with:
     """
diff --git a/lib/librarian/puppet/dsl.rb b/lib/librarian/puppet/dsl.rb
index 373c4ab..771f6a6 100644
--- a/lib/librarian/puppet/dsl.rb
+++ b/lib/librarian/puppet/dsl.rb
@@ -70,7 +70,12 @@ module Librarian
               raise Error, msg
             end
           end
-          dependencyList = JSON.parse(File.read(f))['dependencies']
+          begin
+            json = JSON.parse(File.read(f))
+          rescue JSON::ParserError => e
+            raise Error, "Unable to parse json file #{f}: #{e}"
+          end
+          dependencyList = json['dependencies']
           dependencyList.each do |d|
             mod(d['name'], d['version_requirement'])
           end
diff --git a/lib/librarian/puppet/source/local.rb b/lib/librarian/puppet/source/local.rb
index eda14be..84f22d7 100644
--- a/lib/librarian/puppet/source/local.rb
+++ b/lib/librarian/puppet/source/local.rb
@@ -105,7 +105,11 @@ module Librarian
         def parsed_metadata
           if @metadata.nil?
             @metadata = if metadata?
-              JSON.parse(File.read(metadata))
+              begin
+                JSON.parse(File.read(metadata))
+              rescue JSON::ParserError => e
+                raise Error, "Unable to parse json file #{metadata}: #{e}"
+              end
             elsif modulefile?
               # translate Modulefile to metadata.json
               evaluated = evaluate_modulefile(modulefile)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ruby-extras/librarian-puppet.git



More information about the Pkg-ruby-extras-commits mailing list