Skip to content

Commit

Permalink
[Fix rubocop/rubocop-ast#7] Reimport error from rubocop-ast
Browse files Browse the repository at this point in the history
  • Loading branch information
marcandre committed May 15, 2020
1 parent 60be129 commit 49681a0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/rubocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require_relative 'rubocop/platform'
require_relative 'rubocop/name_similarity'
require_relative 'rubocop/string_interpreter'
require_relative 'rubocop/error' unless RuboCop.const_defined?(:Error)
require_relative 'rubocop/warning'

require_relative 'rubocop/cop/util'
Expand Down
34 changes: 34 additions & 0 deletions lib/rubocop/error.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# frozen_string_literal: true

module RuboCop
# An Error exception is different from an Offense with severity 'error'
# When this exception is raised, it means that RuboCop is unable to perform
# a requested action (probably due to misconfiguration) and must stop
# immediately, rather than carrying on
class Error < StandardError; end

class ValidationError < Error; end

# A wrapper to display errored location of analyzed file.
class ErrorWithAnalyzedFileLocation < Error
def initialize(cause:, node:, cop:)
@cause = cause
@cop = cop
@location = node.is_a?(RuboCop::AST::Node) ? node.loc : node
end

attr_reader :cause, :cop

def line
@location&.line
end

def column
@location&.column
end

def message
"cause: #{cause.inspect}"
end
end
end
6 changes: 5 additions & 1 deletion lib/rubocop/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,11 @@ def get_processed_source(file)
if @options[:stdin]
ProcessedSource.new(@options[:stdin], ruby_version, file)
else
ProcessedSource.from_file(file, ruby_version)
begin
ProcessedSource.from_file(file, ruby_version)
rescue Errno::ENOENT
raise RuboCop::Error, "No such file or directory: #{file}"
end
end
end

Expand Down

0 comments on commit 49681a0

Please sign in to comment.