class Structured::Errors::MultipleErrors
Attributes
errors[R]
root[R]
Public Class Methods
new(stack, errors)
click to toggle source
Calls superclass method
Structured::Errors::Base::new
# File lib/structured/errors/multiple_errors.rb, line 6 def initialize(stack, errors) @errors = errors messages = errors.map { |msg| "- #{msg}" }.join("\n") super(stack, "Failed to parse #{stack.type.type_name} due to #{errors.length} errors:\n#{messages}") end
union(stack, exceptions)
click to toggle source
# File lib/structured/errors/multiple_errors.rb, line 23 def self.union(stack, exceptions) return exceptions.first if exceptions.size == 1 flattened_exceptions = exceptions.flat_map do |exception| case exception when MultipleErrors then exception.errors when Base then [exception] else raise "Cannot wrap a #{exception.class.name} in a ParsingFailed exception" end end new(stack, flattened_exceptions) end
Public Instance Methods
annotation(header: true)
click to toggle source
# File lib/structured/errors/multiple_errors.rb, line 13 def annotation(header: true) annotations = errors.map { |error| error.annotation(header: false) } if header head = "Failed to compile #{CGI.escape_html(stack.root.type.type_name)} due to #{errors.length} errors:" head + "\n\n" + annotations.join("\n\n") else annotations.join("\n\n") end end