Skip to content

[logging] Avoid logging cancellation as warnings/errors #300

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

Merged
merged 1 commit into from
Aug 4, 2020
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
20 changes: 14 additions & 6 deletions Sources/SourceKitD/SourceKitD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,12 @@ extension SourceKitD {

let resp = SKDResponse(api.send_request_sync(req.dict), sourcekitd: self)

logResponse(resp)

guard let dict = resp.value else {
log(resp.description, level: .error)
throw resp.error!
}

logAsync(level: .debug) { _ in dict.description }

return dict
}

Expand All @@ -98,16 +97,15 @@ extension SourceKitD {

let resp = SKDResponse(_resp, sourcekitd: self)

logResponse(resp)

guard let dict = resp.value else {
log(resp.description, level: .error)
queue.async {
reply(.failure(resp.error!))
}
return
}

logAsync(level: .debug) { _ in dict.description }

queue.async {
reply(.success(dict))
}
Expand All @@ -117,6 +115,16 @@ extension SourceKitD {
}
}

private func logResponse(_ response: SKDResponse) {
if let value = response.value {
logAsync(level: .debug) { _ in value.description }
} else if case .requestCancelled = response.error! {
log(response.description, level: .debug)
} else {
log(response.description, level: .error)
}
}

/// A sourcekitd notification handler in a class to allow it to be uniquely referenced.
public protocol SKDNotificationHandler: AnyObject {
func notification(_: SKDResponse) -> Void
Expand Down
2 changes: 1 addition & 1 deletion Sources/SourceKitLSP/Swift/CursorInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ struct CursorInfo {
}

/// An error from a cursor info request.
enum CursorInfoError: Error {
enum CursorInfoError: Error, Equatable {

/// The given URL is not a known document.
case unknownDocument(DocumentURI)
Expand Down
2 changes: 1 addition & 1 deletion Sources/SourceKitLSP/Swift/SwiftLanguageServer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ extension SwiftLanguageServer {
let position = req.params.position
cursorInfo(uri, position..<position) { result in
guard let cursorInfo: CursorInfo = result.success ?? nil else {
if let error = result.failure {
if let error = result.failure, error != .responseError(.cancelled) {
log("cursor info failed \(uri):\(position): \(error)", level: .warning)
}
return req.reply(nil)
Expand Down