Skip to content

Commit

Permalink
Merge pull request #151 from projecthydra/add_filename_to_error_message
Browse files Browse the repository at this point in the history
Add filename to error message
  • Loading branch information
mjgiarlo committed Apr 11, 2017
2 parents a831f7c + 37c4991 commit a0f828e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
23 changes: 11 additions & 12 deletions lib/hydra/derivatives/processors/active_encode.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
require 'active_encode'

module Hydra::Derivatives::Processors
class ActiveEncodeError < StandardError
def initialize(status, source_path, errors = [])
msg = "ActiveEncode status was \"#{status}\" for #{source_path}"
msg = "#{msg}: #{errors.join(' ; ')}" unless errors.empty?
super(msg)
end
end

class ActiveEncode < Processor
def process
encode = ::ActiveEncode::Base.create(source_path, directives)

# Wait until the encoding job is finished
# while(encode.reload.running?) { sleep 10 }

raise_exception_if_encoding_failed(encode)
raise_exception_if_encoding_cancelled(encode)
raise ActiveEncodeError.new(encode.state, source_path, encode.errors) unless encode.completed?

# TODO: call output_file_service with the output url
end

def raise_exception_if_encoding_failed(encode)
return unless encode.failed?
raise StandardError.new("Encoding failed: #{encode.errors.join(' ; ')}")
end

def raise_exception_if_encoding_cancelled(encode)
return unless encode.cancelled?
raise StandardError.new("Encoding cancelled: #{source_path}")
end
end
end
6 changes: 4 additions & 2 deletions spec/processors/active_encode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
# encode finished and returned a certain status.
let(:failed_status) { false }
let(:cancelled_status) { false }
let(:completed_status) { false }
let(:errors) { [] }
let(:encode_double) do
double('encode double',
reload: self, state: state, errors: errors,
:completed? => completed_status,
:failed? => failed_status,
:cancelled? => cancelled_status)
end
Expand All @@ -33,7 +35,7 @@
end

it 'raises an exception' do
expect { subject }.to raise_error('Encoding failed: error 1 ; error 2')
expect { subject }.to raise_error(Hydra::Derivatives::Processors::ActiveEncodeError, "ActiveEncode status was \"failed\" for #{file_path}: error 1 ; error 2")
end
end

Expand All @@ -46,7 +48,7 @@
end

it 'raises an exception' do
expect { subject }.to raise_error("Encoding cancelled: #{file_path}")
expect { subject }.to raise_error(Hydra::Derivatives::Processors::ActiveEncodeError, "ActiveEncode status was \"cancelled\" for #{file_path}")
end
end
end
Expand Down

0 comments on commit a0f828e

Please sign in to comment.