Skip to content

Commit 2ede61f

Browse files
author
Kevin Paulisse
committed
Move catalog compilation errors to errors class
1 parent 6689007 commit 2ede61f

5 files changed

Lines changed: 19 additions & 19 deletions

File tree

lib/octocatalog-diff/catalog.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
require_relative 'catalog/puppetdb'
1010
require_relative 'catalog/puppetmaster'
1111
require_relative 'catalog-util/fileresources'
12+
require_relative 'errors'
1213

1314
module OctocatalogDiff
1415
# This class represents a catalog. Generation of the catalog is handled via one of the
@@ -18,11 +19,6 @@ class Catalog
1819
# Readable
1920
attr_reader :built, :catalog, :catalog_json
2021

21-
# Error classes that we can throw
22-
class PuppetVersionError < RuntimeError; end
23-
class CatalogError < RuntimeError; end
24-
class ReferenceValidationError < RuntimeError; end
25-
2622
# Constructor
2723
# @param :backend [Symbol] If set, this will force a backend
2824
# @param :json [String] JSON catalog content (will avoid running Puppet to compile catalog)
@@ -159,8 +155,8 @@ def resource(opts = {})
159155
# This is a compatibility layer for the resources, which are in a different place in Puppet 3.x and Puppet 4.x
160156
# @return [Array] Resource array
161157
def resources
162-
raise CatalogError, 'Catalog does not appear to have been built' if !valid? && error_message.nil?
163-
raise CatalogError, error_message unless valid?
158+
raise OctocatalogDiff::Errors::CatalogError, 'Catalog does not appear to have been built' if !valid? && error_message.nil?
159+
raise OctocatalogDiff::Errors::CatalogError, error_message unless valid?
164160
return @catalog['data']['resources'] if @catalog['data'].is_a?(Hash) && @catalog['data']['resources'].is_a?(Array)
165161
return @catalog['resources'] if @catalog['resources'].is_a?(Array)
166162
# This is a bug condition
@@ -183,7 +179,7 @@ def valid?
183179
end
184180

185181
# Determine if all of the (before, notify, require, subscribe) targets are actually in the catalog.
186-
# Raise a ReferenceValidationError for any found to be missing.
182+
# Raise a OctocatalogDiff::Errors::ReferenceValidationError for any found to be missing.
187183
# Uses @options[:validate_references] to influence which references are checked.
188184
def validate_references
189185
# Skip out early if no reference validation has been requested.
@@ -223,7 +219,7 @@ def validate_references
223219
formatted_references.flatten!
224220
plural = formatted_references.size == 1 ? '' : 's'
225221
errors = formatted_references.join('; ')
226-
raise ReferenceValidationError, "Catalog has broken reference#{plural}: #{errors}"
222+
raise OctocatalogDiff::Errors::ReferenceValidationError, "Catalog has broken reference#{plural}: #{errors}"
227223
end
228224

229225
private

lib/octocatalog-diff/errors.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class ConfigurationFileContentError < RuntimeError; end
1010
# Error classes for building catalogs
1111
class BootstrapError < RuntimeError; end
1212
class CatalogError < RuntimeError; end
13+
class PuppetVersionError < RuntimeError; end
14+
class ReferenceValidationError < RuntimeError; end
1315

1416
# Error classes for retrieving facts
1517
class FactSourceError < RuntimeError; end

spec/octocatalog-diff/integration/integration_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require_relative '../tests/spec_helper'
22
require OctocatalogDiff::Spec.require_path('/cli')
3+
require OctocatalogDiff::Spec.require_path('/errors')
34

45
require 'json'
56
require 'ostruct'

spec/octocatalog-diff/integration/reference_validation_spec.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def self.catalog_contains_resource(result, type, title)
9999
end
100100

101101
it 'should raise ReferenceValidationError' do
102-
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Catalog::ReferenceValidationError)
102+
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::ReferenceValidationError)
103103
end
104104

105105
it 'should have formatted error messages' do
@@ -122,7 +122,7 @@ def self.catalog_contains_resource(result, type, title)
122122
end
123123

124124
it 'should raise ReferenceValidationError' do
125-
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Catalog::ReferenceValidationError)
125+
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::ReferenceValidationError)
126126
end
127127

128128
it 'should have formatted error messages' do
@@ -141,7 +141,7 @@ def self.catalog_contains_resource(result, type, title)
141141
end
142142

143143
it 'should raise ReferenceValidationError' do
144-
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Catalog::ReferenceValidationError)
144+
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::ReferenceValidationError)
145145
end
146146

147147
it 'should have formatted error messages' do
@@ -160,7 +160,7 @@ def self.catalog_contains_resource(result, type, title)
160160
end
161161

162162
it 'should raise ReferenceValidationError' do
163-
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Catalog::ReferenceValidationError)
163+
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::ReferenceValidationError)
164164
end
165165

166166
it 'should have formatted error messages' do
@@ -220,7 +220,7 @@ def self.catalog_contains_resource(result, type, title)
220220
end
221221

222222
it 'should raise ReferenceValidationError' do
223-
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Catalog::ReferenceValidationError)
223+
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::ReferenceValidationError)
224224
end
225225

226226
it 'should have formatted error messages' do
@@ -285,7 +285,7 @@ def self.catalog_contains_resource(result, type, title)
285285
end
286286

287287
it 'should raise ReferenceValidationError' do
288-
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Catalog::ReferenceValidationError)
288+
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::ReferenceValidationError)
289289
end
290290

291291
it 'should have formatted error messages' do
@@ -329,7 +329,7 @@ def self.catalog_contains_resource(result, type, title)
329329
end
330330

331331
it 'should raise ReferenceValidationError' do
332-
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Catalog::ReferenceValidationError)
332+
expect(@result.exception).to be_a_kind_of(OctocatalogDiff::Errors::ReferenceValidationError)
333333
end
334334

335335
it 'should have formatted error messages from to-catalog only' do

spec/octocatalog-diff/tests/catalog_spec.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
require_relative '../mocks/puppetdb'
55

66
require OctocatalogDiff::Spec.require_path('/catalog')
7+
require OctocatalogDiff::Spec.require_path('/errors')
78

89
describe OctocatalogDiff::Catalog do
910
context 'backends' do
@@ -311,15 +312,15 @@
311312
it 'should raise error' do
312313
expect do
313314
@catalog.resource(type: 'System::User', title: 'alice')
314-
end.to raise_error(OctocatalogDiff::Catalog::CatalogError, /Broken!/)
315+
end.to raise_error(OctocatalogDiff::Errors::CatalogError, /Broken!/)
315316
end
316317
end
317318

318319
describe '#resources' do
319320
it 'should throw an error' do
320321
expect do
321322
@catalog.resources
322-
end.to raise_error(OctocatalogDiff::Catalog::CatalogError, /Broken!/)
323+
end.to raise_error(OctocatalogDiff::Errors::CatalogError, /Broken!/)
323324
end
324325
end
325326

@@ -476,7 +477,7 @@
476477
'exec[subscribe caller 2] -> subscribe[Exec[subscribe target 2]]',
477478
'exec[subscribe caller 3] -> subscribe[Exec[subscribe target]]'
478479
].join('; ')
479-
expect { catalog.validate_references }.to raise_error(OctocatalogDiff::Catalog::ReferenceValidationError, error_str)
480+
expect { catalog.validate_references }.to raise_error(OctocatalogDiff::Errors::ReferenceValidationError, error_str)
480481
end
481482
end
482483

0 commit comments

Comments
 (0)