Module: Voom::Commands::ExtractErrors

Included in:
AggregateValidations, Namespace, RescueLogicalErrors
Defined in:
lib/voom/commands/extract_errors.rb

Instance Method Summary collapse

Instance Method Details

#extract_errors(e) ⇒ Object



16
17
18
19
# File 'lib/voom/commands/extract_errors.rb', line 16

def extract_errors(e)
  return e.form_errors if e.respond_to?(:form_errors) && e.form_errors.any?
  {exception: e.message}
end

#extract_fk_errors(e) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/voom/commands/extract_errors.rb', line 4

def extract_fk_errors(e)
  errmsg = e.message
  table, _foreign_key, foreign_table = e.message.match(/PG::ForeignKeyViolation: ERROR:.*\"(.*)\".*\"(.*)\"[\n].*\"(.*)\"/)&.captures
  if table && _foreign_key && foreign_table
    errmsg = "Unable to delete or update #{table.singularize.humanize.titleize}. "\
                          "It is referred to from one or more #{foreign_table.humanize.titleize}. "\
                          "You will need to update or remove any #{foreign_table.humanize.titleize} that refer to this "\
                          "#{table.singularize.humanize.titleize} first."
  end
  {exception: errmsg}
end