Exception: Lutaml::Xsd::Errors::EnhancedError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/lutaml/xsd/errors/enhanced_error.rb

Overview

Base class for enhanced errors with rich contextual information

Examples:

Creating an enhanced error

error = EnhancedError.new(
  "Type not found",
  context: {
    location: "/root/element",
    actual_value: "MyType",
    repository: schema_repository
  }
)

Getting suggestions

error.suggestions # => [Suggestion, ...]

Getting troubleshooting tips

error.troubleshooting_tips # => ["Check namespace...", ...]

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, context: {}) ⇒ EnhancedError

Initialize enhanced error



34
35
36
37
38
39
# File 'lib/lutaml/xsd/errors/enhanced_error.rb', line 34

def initialize(message, context: {})
  super(message)
  @context = context.is_a?(ErrorContext) ? context : ErrorContext.new(context)
  @suggester = nil
  @troubleshooter = nil
end

Class Attribute Details

.suggester_classClass?

Get suggester class for this error type



104
105
106
# File 'lib/lutaml/xsd/errors/enhanced_error.rb', line 104

def suggester_class
  @suggester_class
end

.troubleshooter_classClass?

Get troubleshooter class for this error type



113
114
115
# File 'lib/lutaml/xsd/errors/enhanced_error.rb', line 113

def troubleshooter_class
  @troubleshooter_class
end

Instance Attribute Details

#contextErrorContext (readonly)



28
29
30
# File 'lib/lutaml/xsd/errors/enhanced_error.rb', line 28

def context
  @context
end

Class Method Details

.use_suggester(klass) ⇒ void

This method returns an undefined value.

Register suggester for this error type



123
124
125
# File 'lib/lutaml/xsd/errors/enhanced_error.rb', line 123

def use_suggester(klass)
  self.suggester_class = klass
end

.use_troubleshooter(klass) ⇒ void

This method returns an undefined value.

Register troubleshooter for this error type



131
132
133
# File 'lib/lutaml/xsd/errors/enhanced_error.rb', line 131

def use_troubleshooter(klass)
  self.troubleshooter_class = klass
end

Instance Method Details

#error_codeString

Get error code



69
70
71
# File 'lib/lutaml/xsd/errors/enhanced_error.rb', line 69

def error_code
  "E000"
end

#severitySymbol

Get error severity



76
77
78
# File 'lib/lutaml/xsd/errors/enhanced_error.rb', line 76

def severity
  :error
end

#suggestionsArray<Suggestion>

Get error suggestions



44
45
46
47
48
# File 'lib/lutaml/xsd/errors/enhanced_error.rb', line 44

def suggestions
  return [] unless suggester

  @suggestions ||= suggester.generate_suggestions(self)
end

#to_detailed_messageString

Build detailed error message with context, suggestions, and tips



62
63
64
# File 'lib/lutaml/xsd/errors/enhanced_error.rb', line 62

def to_detailed_message
  MessageBuilder.new(self).build
end

#troubleshooting_tipsArray<String>

Get troubleshooting tips



53
54
55
56
57
# File 'lib/lutaml/xsd/errors/enhanced_error.rb', line 53

def troubleshooting_tips
  return [] unless troubleshooter

  @troubleshooting_tips ||= troubleshooter.generate_tips(self)
end