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

Graceful (??) error handling with undefined outer module #576

Merged
merged 1 commit into from
Jun 13, 2022
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
3 changes: 3 additions & 0 deletions lib/steep/services/type_check_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,9 @@ def type_check_file(target:, subtyping:, path:, text:)
SourceFile.with_syntax_error(path: path, content: text, error: error)
rescue EncodingError => exn
SourceFile.no_data(path: path, content: "")
rescue RuntimeError => exn
Steep.log_error(exn)
SourceFile.no_data(path: path, content: text)
end

def self.type_check(source:, subtyping:)
Expand Down
28 changes: 28 additions & 0 deletions test/type_check_service_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,32 @@ def foo: () -> B
reported_diagnostics.clear
end
end

def test_signature_error_unknown_outer_module
# Recovering from syntax error test
service = Services::TypeCheckService.new(project: project)

{
Pathname("lib.rbs") => [ContentChange.string(<<RBS)],
class Foo::Bar::Baz
end
RBS
Pathname("lib/a.rb") => [ContentChange.string(<<RUBY)],
1+2
RUBY
}.tap do |changes|
service.update_and_check(changes: changes, assignment: assignment, &reporter)

reported_diagnostics[Pathname("lib.rbs")].tap do |errors|
assert_any!(errors, size: 1) do |error|
assert_equal "RBS::UnknownTypeName", error[:code]
assert_equal "Cannot find type `::Foo::Bar`", error[:message]
end
end

reported_diagnostics[Pathname("lib/a.rb")].tap do |errors|
assert_empty errors
end
end
end
end