Skip to content

Commit 30ed5b1

Browse files
committed
move rescue for TypeError from conditional into method body
I'm moving the rescue statement from the coditional into the method body of constant_name_from_node. If we look at the code we notice that we have a couple of constant_name method calls that can throw this exception. By changing the scope we are able to prevent unintended TypeErrors to crash the program. - begin - Node.constant_name(node) - rescue Node::TypeError - nil - end + Node.constant_name(node) end + rescue Node::TypeError + nil
1 parent 9b6e61d commit 30ed5b1

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/packwerk/const_node_inspector.rb

+3-5
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ def constant_name_from_node(node, ancestors:)
1717
if constant_in_module_or_class_definition?(node, ancestors: ancestors)
1818
fully_qualify_constant(node, ancestors: ancestors)
1919
else
20-
begin
21-
Node.constant_name(node)
22-
rescue Node::TypeError
23-
nil
24-
end
20+
Node.constant_name(node)
2521
end
22+
rescue Node::TypeError
23+
nil
2624
end
2725

2826
private

0 commit comments

Comments
 (0)