Module: Kumi::Core::ErrorReporting
- Included in:
- Analyzer::Passes::PassBase, RubyParser::ExpressionConverter, RubyParser::InputBuilder, RubyParser::Parser, RubyParser::SchemaBuilder
- Defined in:
- lib/kumi/core/error_reporting.rb
Overview
Mixin module providing error reporting capabilities to classes that need to report localized errors consistently.
Usage:
class MyAnalyzer
include ErrorReporting
def analyze(errors)
report_error(errors, "Something went wrong", location: some_location)
raise_localized_error("Critical error", location: some_location)
end
end
Instance Method Summary collapse
-
#inferred_location ⇒ Syntax::Location
Get current location from caller stack (fallback method).
-
#raise_localized_error(message, location: nil, error_class: Errors::SemanticError, type: :semantic, context: {}) ⇒ Object
Immediately raise a localized error (parser pattern).
-
#raise_syntax_error(message, location: nil, context: {}) ⇒ Object
Immediately raise a syntax error.
-
#raise_type_error(message, location: nil, context: {}) ⇒ Object
Immediately raise a type error.
-
#report_enhanced_error(errors, message, location: nil, suggestions: [], similar_names: [], type: :semantic) ⇒ Object
Create an enhanced error with suggestions.
-
#report_error(errors, message, location: nil, type: :semantic, context: {}) ⇒ ErrorReporter::ErrorEntry
Report an error to an accumulator (analyzer pattern).
-
#report_semantic_error(errors, message, location: nil, context: {}) ⇒ Object
Report a semantic error to an accumulator.
-
#report_syntax_error(errors, message, location: nil, context: {}) ⇒ Object
Report a syntax error to an accumulator.
-
#report_type_error(errors, message, location: nil, context: {}) ⇒ Object
Report a type error to an accumulator.
Instance Method Details
#inferred_location ⇒ Syntax::Location
Get current location from caller stack (fallback method)
89 90 91 92 93 94 |
# File 'lib/kumi/core/error_reporting.rb', line 89 def inferred_location fallback = caller_locations.find(&:absolute_path) return nil unless fallback Syntax::Location.new(file: fallback.path, line: fallback.lineno, column: 0) end |
#raise_localized_error(message, location: nil, error_class: Errors::SemanticError, type: :semantic, context: {}) ⇒ Object
Immediately raise a localized error (parser pattern)
37 38 39 |
# File 'lib/kumi/core/error_reporting.rb', line 37 def raise_localized_error(, location: nil, error_class: Errors::SemanticError, type: :semantic, context: {}) ErrorReporter.raise_error(, location: location, error_class: error_class, type: type, context: context) end |
#raise_syntax_error(message, location: nil, context: {}) ⇒ Object
Immediately raise a syntax error
57 58 59 |
# File 'lib/kumi/core/error_reporting.rb', line 57 def raise_syntax_error(, location: nil, context: {}) raise_localized_error(, location: location, error_class: Kumi::Core::Errors::SyntaxError, type: :syntax, context: context) end |
#raise_type_error(message, location: nil, context: {}) ⇒ Object
Immediately raise a type error
62 63 64 |
# File 'lib/kumi/core/error_reporting.rb', line 62 def raise_type_error(, location: nil, context: {}) raise_localized_error(, location: location, error_class: Errors::TypeError, type: :type, context: context) end |
#report_enhanced_error(errors, message, location: nil, suggestions: [], similar_names: [], type: :semantic) ⇒ Object
Create an enhanced error with suggestions
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/kumi/core/error_reporting.rb', line 74 def report_enhanced_error(errors, , location: nil, suggestions: [], similar_names: [], type: :semantic) entry = ErrorReporter.create_enhanced_error( , location: location, suggestions: suggestions, similar_names: similar_names, type: type ) errors << entry entry end |
#report_error(errors, message, location: nil, type: :semantic, context: {}) ⇒ ErrorReporter::ErrorEntry
Report an error to an accumulator (analyzer pattern)
26 27 28 |
# File 'lib/kumi/core/error_reporting.rb', line 26 def report_error(errors, , location: nil, type: :semantic, context: {}) ErrorReporter.add_error(errors, , location: location, type: type, context: context) end |
#report_semantic_error(errors, message, location: nil, context: {}) ⇒ Object
Report a semantic error to an accumulator
52 53 54 |
# File 'lib/kumi/core/error_reporting.rb', line 52 def report_semantic_error(errors, , location: nil, context: {}) report_error(errors, , location: location, type: :semantic, context: context) end |
#report_syntax_error(errors, message, location: nil, context: {}) ⇒ Object
Report a syntax error to an accumulator
42 43 44 |
# File 'lib/kumi/core/error_reporting.rb', line 42 def report_syntax_error(errors, , location: nil, context: {}) report_error(errors, , location: location, type: :syntax, context: context) end |
#report_type_error(errors, message, location: nil, context: {}) ⇒ Object
Report a type error to an accumulator
47 48 49 |
# File 'lib/kumi/core/error_reporting.rb', line 47 def report_type_error(errors, , location: nil, context: {}) report_error(errors, , location: location, type: :type, context: context) end |