diff --git a/lib/puppet-languageserver/document_validator.rb b/lib/puppet-languageserver/document_validator.rb index 928c7a07..2ed025e0 100644 --- a/lib/puppet-languageserver/document_validator.rb +++ b/lib/puppet-languageserver/document_validator.rb @@ -88,18 +88,20 @@ def self.validate(content, workspace, _max_problems = 100) validation_environment.check_for_reparse validation_environment.known_resource_types.clear rescue StandardError => detail - # Somtimes the error is in the cause not the root object itself - detail = detail.cause if !detail.respond_to?(:line) && detail.respond_to?(:cause) && detail.cause.respond_to?(:line) - + # Sometimes the error is in the cause not the root object itself + detail = detail.cause if !detail.respond_to?(:line) && detail.respond_to?(:cause) + ex_line = detail.respond_to?(:line) && !detail.line.nil? ? detail.line - 1 : nil # Line numbers from puppet exceptions are base 1 + ex_pos = detail.respond_to?(:pos) && !detail.pos.nil? ? detail.pos : nil # Pos numbers from puppet are base 1 + message = detail.respond_to?(:message) ? detail.message : nil message = detail.basic_message if message.nil? && detail.respond_to?(:basic_message) - unless detail.line.nil? || detail.pos.nil? || message.nil? + unless ex_line.nil? || ex_pos.nil? || message.nil? result << LanguageServer::Diagnostic.create('severity' => LanguageServer::DIAGNOSTICSEVERITY_ERROR, - 'fromline' => detail.line - 1, # Line numbers from puppet are base 1 - 'toline' => detail.line - 1, # Line numbers from puppet are base 1 - 'fromchar' => detail.pos - 1, # Pos numbers from puppet are base 1 - 'tochar' => detail.pos + 1 - 1, # Pos numbers from puppet are base 1 + 'fromline' => ex_line, + 'toline' => ex_line, + 'fromchar' => ex_pos, + 'tochar' => ex_pos + 1, 'source' => 'Puppet', 'message' => message) end