Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

harmonize error handling #400

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
proformaxml (1.3.0)
proformaxml (1.4.0)
activemodel (>= 5.2.3, < 8.0.0)
activesupport (>= 5.2.3, < 8.0.0)
dachsfisch (~> 1.0.0)
Expand Down
5 changes: 2 additions & 3 deletions lib/proformaxml/services/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(zip:, expected_version: nil)
@expected_version = expected_version

xml = filestring_from_zip('task.xml')
raise PreImportValidationError if xml.nil?
raise PreImportValidationError.new(['no task_xml found']) if xml.blank?

@doc = Nokogiri::XML(xml, &:noblanks)
@task = Task.new
Expand All @@ -28,8 +28,7 @@ def proforma_namespace

def perform
errors = validate

raise PreImportValidationError.new(errors) if errors.any?
raise PreImportValidationError.new(errors.map(&:message)) if errors.any?

@pro_ns = proforma_namespace
@task_node = @doc.xpath("/#{@pro_ns}:task")
Expand Down
2 changes: 1 addition & 1 deletion lib/proformaxml/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module ProformaXML
VERSION = '1.3.0'
VERSION = '1.4.0'
end
13 changes: 12 additions & 1 deletion spec/proformaxml/importer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
expect(importer.instance_variable_get(:@expected_version)).to eql '2.0'
end
end

context 'when zip-file does not contain task.xml' do
before do
zip_file.write('Foobar')
zip_file.rewind
end

it 'raises correct error' do
expect { importer }.to raise_error(ProformaXML::PreImportValidationError, /no task_xml found/)
end
end
end

describe '#perform' do
Expand Down Expand Up @@ -242,7 +253,7 @@
let(:export_version) { '2.1' }

it 'raises an error' do
expect { perform }.to raise_error ProformaXML::PreImportValidationError
expect { perform }.to raise_error ProformaXML::PreImportValidationError, /No matching global declaration available for the validation root/
end
end
end
Expand Down