Skip to content

Commit

Permalink
Add error logging to imports (#282)
Browse files Browse the repository at this point in the history
* Capture any resucued errors during imports
* Log import error messages and stack traces
* Persist error messages to the job graph
* Display error indicators in the job status graph
* Provide the error text via hover-text
  • Loading branch information
mark-dce authored Oct 13, 2022
1 parent db09ca0 commit 284677e
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def user_options
users.all.collect { |u| [u.user_key, u.display_name] }
end

def status_span_generator(status)
def status_span_generator(status, description = nil)
status_text = status.to_s.titleize
case status_text
when 'Submitted'
Expand All @@ -44,7 +44,7 @@ def status_span_generator(status)
status_classes = 'status-unrecognized'
status_text = '-?-'
end
tag.span(status_text, class: 'job-status badge rounded-pill ' + status_classes)
tag.span(status_text, class: 'job-status badge rounded-pill ' + status_classes, title: description)
end

def collection_permission_template_form_for(form:)
Expand Down
34 changes: 15 additions & 19 deletions app/lib/tenejo/csv_importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,26 +72,22 @@ def search_members(type, file_id)
end

def update_status(item, start_state, end_state)
member = search_members(item.class, item.identifier)
if member
member.status = start_state
# rubocop:disable Rails/SkipsModelValidations
@job.update_attribute(:graph, @job.graph) # forces AR to write the graph column, regardless of what it thinks
begin
yield if block_given?
member.status = end_state
rescue
member.status = 'errored'
end
# rubocop:disable Rails/SkipsModelValidations
@job.update_attribute(:graph, @job.graph)
elsif block_given?
begin
yield # still need to call the block if the member doesn't exist in the graph somehow. this seems like a bug related to test setup
rescue
@logger.error "CSV Importer couldn't update status for < #{item.identifier} >"
end
member = search_members(item.class, item.identifier) || PreFlightObj.new
member.status = start_state
# rubocop:disable Rails/SkipsModelValidations
@job.update_attribute(:graph, @job.graph) # forces AR to write the graph column, regardless of what it thinks
begin
yield if block_given?
member.status = end_state
rescue => e
@logger.error "CSV Importer couldn't update status for < #{item.identifier} >"
@logger.error e.message
@logger.error e.backtrace.join("\n")
member.messages << e.message
member.status = 'errored'
end
# rubocop:disable Rails/SkipsModelValidations
@job.update_attribute(:graph, @job.graph)
end

def create_or_update_collection(pfcollection)
Expand Down
5 changes: 3 additions & 2 deletions app/lib/tenejo/pf_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def rights_statement_authority
class PreFlightObj
include ActiveModel::Validations
include ActiveModel::Serializers::JSON
attr_accessor :lineno, :children, :visibility, :type, :status
attr_accessor :lineno, :children, :visibility, :type, :status, :messages

def warnings
@warnings ||= Hash.new { |h, k| h[k] = [] }
Expand Down Expand Up @@ -110,7 +110,7 @@ def attributes=(hash)
end

def attributes
{ lineno: nil, children: [], visibility: nil, warnings: [], type: nil, status: 'not_started' }
{ lineno: nil, children: [], visibility: nil, warnings: [], type: nil, status: 'not_started', messages: [] }
end

def initialize(row = {}, lineno = 0, type: self.class.name)
Expand All @@ -121,6 +121,7 @@ def initialize(row = {}, lineno = 0, type: self.class.name)
set_attribute(field_name, value, lineno)
end
@children = []
@messages = []
@lineno = lineno
@visibility = transform_visibility
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/jobs/_child.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<% end %>
</td>
<td class="item_status">
<%= status_span_generator(node.status) %>
<%= status_span_generator(node.status, node.messages.join("\n")) %>
</td>
<td class="identifier">
<%= node.identifier %>
Expand Down
4 changes: 4 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
example "accepts symbols" do
expect(helper.status_span_generator(:in_progress)).to include "In Progress"
end

example "provides hover text" do
expect(helper.status_span_generator(:errored, 'something bad happened here')).to include 'title="something bad'
end
end
end

0 comments on commit 284677e

Please sign in to comment.