Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid raising bare runtime errors #582

Merged
merged 2 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/spoom/deadcode/remover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def delete_constant_assignment(context)
delete_chars(node.location.start_offset, next_node.location.start_offset)
else
# Should have been removed as a single MLHS node
raise "Unexpected case while removing constant assignment"
raise Error, "Unexpected case while removing constant assignment"
end
end

Expand Down Expand Up @@ -202,7 +202,7 @@ def delete_attr_accessor(context)
# ~~~
delete_chars(context.node.location.start_offset, next_node.location.start_offset)
else
raise "Unexpected case while removing attr_accessor"
raise Error, "Unexpected case while removing attr_accessor"
end

insert_accessor(context.node, send_context, was_removed: false) if need_accessor
Expand Down Expand Up @@ -399,7 +399,7 @@ def initialize(source, comments, node, nesting)
sig { returns(Prism::Node) }
def parent_node
parent = @nesting.last
raise "No parent for node #{node}" unless parent
raise Error, "No parent for node #{node}" unless parent

parent
end
Expand All @@ -408,7 +408,7 @@ def parent_node
def parent_context
nesting = @nesting.dup
parent = nesting.pop
raise "No parent context for node #{@node}" unless parent
raise Error, "No parent context for node #{@node}" unless parent

NodeContext.new(@source, @comments, parent, nesting)
end
Expand All @@ -419,7 +419,7 @@ def previous_nodes
child_nodes = parent.child_nodes.compact

index = child_nodes.index(@node)
raise "Node #{@node} not found in parent #{parent}" unless index
raise Error, "Node #{@node} not found in parent #{parent}" unless index

T.must(child_nodes[0...index])
end
Expand All @@ -435,7 +435,7 @@ def next_nodes
child_nodes = parent.child_nodes.compact

index = child_nodes.index(node)
raise "Node #{@node} not found in nesting node #{parent}" unless index
raise Error, "Node #{@node} not found in nesting node #{parent}" unless index

T.must(child_nodes.compact[(index + 1)..-1])
end
Expand Down
8 changes: 5 additions & 3 deletions lib/spoom/sorbet/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def sort_errors_by_code(errors)
class Parser
extend T::Sig

class ParseError < Spoom::Error; end

HEADER = T.let(
[
"👋 Hey there! Heads up that this is not a release build of sorbet.",
Expand Down Expand Up @@ -97,22 +99,22 @@ def match_error_line(line)

sig { params(error: Error).void }
def open_error(error)
raise "Error: Already parsing an error!" if @current_error
raise ParseError, "Error: Already parsing an error!" if @current_error

@current_error = error
end

sig { void }
def close_error
raise "Error: Not already parsing an error!" unless @current_error
raise ParseError, "Error: Not already parsing an error!" unless @current_error

@errors << @current_error
@current_error = nil
end

sig { params(line: String).void }
def append_error(line)
raise "Error: Not already parsing an error!" unless @current_error
raise ParseError, "Error: Not already parsing an error!" unless @current_error

filepath_match = line.match(/^ (.*?):\d+/)
if filepath_match && filepath_match[1]
Expand Down
Loading