Exception: ArchUnit::SourceParseError
- Inherits:
-
TechnicalError
- Object
- StandardError
- TechnicalError
- ArchUnit::SourceParseError
- Defined in:
- lib/archunit/error/source_parse_error.rb
Overview
An included source could not be analyzed; never an ordinary architecture violation.
Instance Attribute Summary collapse
-
#diagnostics ⇒ Array<Common::Extraction::ParseDiagnostic>
readonly
Immutable source diagnostics.
Class Method Summary collapse
-
.validate!(result, path:) ⇒ Prism::ParseResult
The complete result, or a technical failure.
Instance Method Summary collapse
-
#initialize(diagnostics) ⇒ SourceParseError
constructor
A new instance of SourceParseError.
Constructor Details
#initialize(diagnostics) ⇒ SourceParseError
Returns a new instance of SourceParseError.
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/archunit/error/source_parse_error.rb', line 25 def initialize(diagnostics) unless diagnostics.is_a?(Array) && !diagnostics.empty? && diagnostics.all?(Common::Extraction::ParseDiagnostic) raise ArgumentError, 'source parse error requires non-empty parse diagnostics' end @diagnostics = diagnostics.dup.freeze details = @diagnostics.map do |item| "#{item.path}:#{item.line}:#{item.column}: #{item.}" end super("Cannot analyze malformed Ruby source:\n#{details.join("\n")}") end |
Instance Attribute Details
#diagnostics ⇒ Array<Common::Extraction::ParseDiagnostic> (readonly)
Returns immutable source diagnostics.
10 11 12 |
# File 'lib/archunit/error/source_parse_error.rb', line 10 def diagnostics @diagnostics end |
Class Method Details
.validate!(result, path:) ⇒ Prism::ParseResult
Returns the complete result, or a technical failure.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/archunit/error/source_parse_error.rb', line 13 def self.validate!(result, path:) return result if result.success? diagnostics = result.errors.map do |error| Common::Extraction::ParseDiagnostic.new( path: path.to_s, line: error.location.start_line, column: error.location.start_column + 1, message: error. ) end raise SourceParseError, diagnostics end |
ArchUnitRuby