-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SourceKit] Fail requests when an error occurs #24124
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
Conversation
Previously, requests would fail silently by returning an empty struct in the response. With this change, responses will properly report fail with the internal error.
I like the idea of providing messages on why that specific source location did not resolve to a symbol but I'm not so sure about failing the request because of it. Request failures are more about the client providing a malformed request or something went wrong with sourcekitd (e.g. it crashed), they should not be happening if both the client and sourcekitd are operating properly. |
What would the alternative be though? For all of these failures, the general information struct will be completely empty. Maybe a new response type should be added? It seems odd to add an error field to each potential response (which would only be set by itself). FWIW, |
The cursor info response could get an extra field with a message that is set only when a symbol could not be resolved in that particular source location, as justification.
Do you mean that I'm not aware of a request that works like this, for example code-completion is not failing the request if it doesn't find any symbols to return at a particular source location.
The IDE can already see that no symbol is present at that specific source location, if it wants to also show a message or log it for debugging purposes it can pick it up from the the extra field. |
Ah my bad, it's actually
Gotcha. I think part of this change makes sense to keep as failure: e.g. bad invocations, if you think that the cursor info in particular should be changed to add a field as well let me know. |
I think bad invocations (e.g. missing compiler arguments) are fine to fail the request. To make the distinction (should something fail the request or not) think of it like this: If it is possible to know in advance that the request is going to fail (e.g. some field is missing, or the compiler arguments don't include the file you want information from), then this is failable. If there is no way for the client to know in advance just by looking at the request (e.g. there is no symbol at a source location, or no completion results at that location), then the response should not be that the request itself is erroneous. |
What do you think of the case when an internal error occurs (something unexpected happened)? Still don't fail the request? Anyways, then for both the CursorInfo and NameInfo, a new Error field should be added? Or should I just leave it as is with an empty response? |
They should fail the request, abnormal situations like sourcekitd crashing, or other unexpected things, should fail the request.
How about adding an |
Yeah that sounds reasonable, I'll go ahead and add that |
Added the |
Friendly ping |
@@ -12,4 +12,4 @@ let a = 12 | |||
// rdar://problem/38162017 | |||
// REQUIRES: OS=macosx | |||
|
|||
// CHECK: <empty cursor info> | |||
// CHECK: (Request Failed): Unable to resolve the start of the token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rintaro, in your fix for rdar://30346106 you had the request return an empty response for out-of-range offset, are you ok with the response failing instead ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe it should be OK.
Previously, requests would fail silently by returning an empty struct in the response. With this change, responses will properly report fail with the internal error.
Made the changes you requested, please let me know if the |
Friendly ping |
(Just an FYI, @DavidGoldman I did a friendly re-request review drive by.) |
sourcekitd_variant_dictionary_get_string(Info, KeyInternalDiagnostic); | ||
if (InternalDiagnostic) { | ||
OS << "<diagnostic \"" << InternalDiagnostic << "\">\n"; | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me, this makes it look like a (true) failure instead of just an empty result. I suggest something like
<empty cursor info>
<internal diagnostic "...">
Or
<empty cursor info; internal diagnostic: "...">
Made the requested fixes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this!
@swift-ci smoke test |
No problem! let me know if i need to merge/rebase onto master |
Could you open a PR for swift-5.1 branch ? |
Will do, how much time do you think I have though? |
There's time; worst can happen is we reject it if it is too late. |
This is causing a bunch of tests to fail in CI: https://ci.swift.org/job/oss-swift-incremental-ASAN-RA-osx/3368/consoleText Failing Tests (7): I'm going to revert. |
Previously, requests would fail silently by returning an empty struct
in the response.
With this change, responses will properly report fail with the internal
error.
This allows IDEs to: