Exception: Lutaml::Xml::Schema::Xsd::Errors::EnhancedError

Inherits:
StandardError
  • Object
show all
Defined in:
lib/lutaml/xml/schema/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

Parameters:

  • message (String)

    Error message

  • context (Hash, ErrorContext) (defaults to: {})

    Error context



36
37
38
39
40
41
# File 'lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb', line 36

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

Returns:

  • (Class, nil)

    Suggester class



106
107
108
# File 'lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb', line 106

def suggester_class
  @suggester_class
end

.troubleshooter_classClass?

Get troubleshooter class for this error type

Returns:

  • (Class, nil)

    Troubleshooter class



115
116
117
# File 'lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb', line 115

def troubleshooter_class
  @troubleshooter_class
end

Instance Attribute Details

#contextErrorContext (readonly)

Returns Error context.

Returns:



30
31
32
# File 'lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb', line 30

def context
  @context
end

Class Method Details

.use_suggester(klass) ⇒ void

This method returns an undefined value.

Register suggester for this error type

Parameters:

  • klass (Class)

    Suggester class



125
126
127
# File 'lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb', line 125

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

Parameters:

  • klass (Class)

    Troubleshooter class



133
134
135
# File 'lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb', line 133

def use_troubleshooter(klass)
  self.troubleshooter_class = klass
end

Instance Method Details

#error_codeString

Get error code

Returns:

  • (String)

    Error code



71
72
73
# File 'lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb', line 71

def error_code
  "E000"
end

#severitySymbol

Get error severity

Returns:

  • (Symbol)

    Error severity (:error, :warning, :info)



78
79
80
# File 'lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb', line 78

def severity
  :error
end

#suggestionsArray<Suggestion>

Get error suggestions

Returns:



46
47
48
49
50
# File 'lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb', line 46

def suggestions
  return [] unless suggester

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

#to_detailed_messageString

Build detailed error message with context, suggestions, and tips

Returns:

  • (String)

    Detailed error message



64
65
66
# File 'lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb', line 64

def to_detailed_message
  MessageBuilder.new(self).build
end

#troubleshooting_tipsArray<String>

Get troubleshooting tips

Returns:

  • (Array<String>)

    List of troubleshooting tips



55
56
57
58
59
# File 'lib/lutaml/xml/schema/xsd/errors/enhanced_error.rb', line 55

def troubleshooting_tips
  return [] unless troubleshooter

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