-
Notifications
You must be signed in to change notification settings - Fork 82
"getter 'id' was called on null" when calling addBreakpointWithScriptUri #657
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
Comments
It looks like we don't support |
Fwiw @DanTup we basically only support I think we probably could support this though, but we will have to convert the absolute uri into a |
Gary is confused how this ever worked for him if VS Code is always sending file: URLs and we don't have any support for those. |
In particular, using the custom version of the VS Code plugin and running with Flutter Web (not through the CLI, but with |
So just to be clear on this, what do the file URLs look like for other circumstances. I think it boils down to three cases a) as above, they're references into application files in the lib directory. These should be dealt with like package: URLs internally But it seems to me that if we can rely on dwds always having a current directory that is the root of the current package, then we can handle this without ever dealing with proper package resolution. So the question is what they look like for case (c) and if we can deal with that simply. Worst case we can go through the .packages file, but I'm not sure we have to. |
How else would we deal with (c) without going through the Also note that |
I never actually had this work myself, but I now see the always-file-uris change was only merged into the previous release (even though it was done a while ago), so you may have been using a build from before then while I was always testing with latest code. There are several reasons I had preferences for file URIs:
I don't think there's an obvious answer, but I do think any decisions made should documented explicitly somewhere (for ex. in the VM Service spec - FYI @bkonyi). A lot of VS Code's debugger decisions are based on "see what the IntelliJ source does" or "try both and see which work" and then when bugs crop up it's always difficult to know "is VS Code doing something wrong, or is this a bug in the VM?" which complicates getting things fixed. |
In Dart libraries are identified by their URI. Historically at least the same file imported by absolute Recently I think this may have changed (at least for the application entrypoint file) where an absolute
This is the original DEP https://github.com/lrhn/dep-pkgspec/blob/master/DEP-pkgspec.md#proposal. It isn't in the language spec because afaik the language itself isn't opinionated about uris at all - its completely up to the implementations how uris are resolved.
It makes a lot of sense from an IDE perspective for sure - but it is trivial to map from a
Correct - and those should always be |
Also note that the |
Yeah, I recall some changes around that (possibly dart-lang/sdk#33076). It was another step in the direction of "file paths working everywhere" which seemed great at the time :)
Heh, apparently my nervousness is justified :D Some of those changes definitely sound like they'll break VS Code - I'll add a note on there - if they go ahead, I'll definitely need to update my code.
But here that reverse work isn't going away, it's just being pushed to the IDE to do it instead (the editor is giving us file paths and you want package URIs). My concern is that complicated error-prone work seems better done closer to the source/SDK (in "official" code) since it's less likely to not be updated if things change (for example the change discussed above I was completely unaware of) and it's backwards/forwards compatibility demands are lessened (you can add SDK version constraints to packages and SDK tools are versioned with the SDK, but the IDE is expected to work with older SDKs as well as newer ones). |
I confirmed that it is still the case that for imports at least absolute file uris and package uris are not the same thing, the following program: import '<user-dir>/playground/lib/b.dart' as bFile;
import 'package:playground/b.dart' as bPkg;
main() {
bPkg.printA(bFile.A());
} Gives this CFE error from the dart vm and also an analyzer error.
Even if you add the cast you get a runtime failure, so the VM internally also treats these as different libraries:
So, I don't see how supporting absolute file uris can be correct at all, and really shouldn't even be supported in the VM. There is no way to correctly identify which of these two libraries you want to operate on by absolute file uri. |
Ok, so this is weird. Seems like it works as long as you don't end up with both imported. So for example, if I take this code in VS Code:
And put a breakpoint inside {
"jsonrpc": "2.0",
"error": {
"code": 102,
"message": "Cannot add breakpoint",
"data": {
"request": {
"method": "addBreakpointWithScriptUri",
"params": {
"isolateId": "isolates\/1370140353987883",
"scriptUri": "file:\/\/\/Users\/dantup\/Desktop\/tttttttt\/lib\/a.dart",
"line": "4"
}
},
"details": "addBreakpointWithScriptUri: Cannot add breakpoint at line '4'"
}
},
"id": "10"
} However, if I comment out either of those imports and the corresponding line, the breakpoint is hit. So it seems like the VM may be happy to accept either, as long as they can only resolve to one library. If there are multiple, it rejects the breakpoint (I don't know if there are other places it'd do the same). |
Correct, this is exactly why the vm shouldn't be supporting absolute file uris for things that are actually loaded with a package: uri. It is actually lying about the uri for the library it returns to you. As soon as both exist in the program it now can't disambiguate. |
So on the web, does that mean that a package: URL and an http: URL would be two different things? A file: URL isn't really possible there, so we'd either have to reject it outright or turn it into one of the others. |
I think it's more complicated than this. It is possible for the user to load a file using a file URI (as the above shows), so blindly converting them to |
Try and set it both ways? lol. |
On a serious not that is a good point though, it is unreasonable for the IDE to know all the transitive ways a library was imported in an app. In general, by convention at least, nothing under The examples I brought up really do indicate a user error imo, and would not even be allowed in a web context anyways. That being said most defensive thing the IDE could do is try it both ways. In theory that would be the correct thing to do in the manufactured case above to set the breakpoint in each version of the library as well. That obviously kind of sucks though. |
I think in general given all the complexities here I think I have come around to just adding in support for When we are constructing the This also brings our behavior in line with the VM, for better or worse, which has generally been our overarching strategy. It isn't technically correct, but it makes things easier on the ide's and should work out of the box for more tools that work today. |
That's actually what we used to do - but there were other complexities (because we have to map breakpoints between VS Code and the VM, and if this mapping isn't one-to-one, you get interesting behaviour like having to delete a breakpoint twice for it to disappear... it's stuff we can work around, but the easier fix was to just not do it :-))
That's true, but you could also argue the same for the VM. If the IDE is just going to send both, the VM could just interpret one of them as both. It seems weird to teach the IDE that "we're just going to always treat these things as the same" if the VM could do it and shield the IDE from the complexity.
Yeah, it'd be nice if this was enforced and there was never any ambiguity.. I think that ship has sailed though. That said, if we had a lint that enforced it or something, it would give more weight for IDEs only working with one way.
Sounds good to me 😄 If it doesn't work out, I'm not against changing things - as long as we can write them down explicitly. There's a lot of ambiguity in these things (because there aren't really many clients) and it makes it hard to ensure they work the same (I've spent a lot of time chasing bugs around breakpoints not being hit and the like). Of course, I'd prefer to keep that complexity closer to the source though :-) |
Interesting side point. In the VM it appears these are actually two separate libraries. If I make a program that imports both package: and file: and debug in observatory they are two separate libraries with two separate URIs. Observatory won't let me set a breakpoint on either one. |
That matches what I found from VS Code above. I don't know it if's always been that way, or has happened as fixes have been made to handle paths/package URIs better. It doesn't feel quite right, but then I'm not sure that loading the same file under both URIs is right either. I can't imagine that situation is ever done deliberately (besides us testing!), if it happens it's likely a mistake on the users part (and often causes weird issues - like ending up library-level state duplicated). |
Great, thanks! Do I need to wait for a release to try this out? I tried running |
Unfortunately it's a bit awkward right now. There's another change that's breaking for Flutter, so we need to fix that. I'll see about getting that done. |
I've created a Flutter pull request. flutter/flutter#41805 that you'll need in order to test this. |
Closing this as it's published. If there are still problems re-open or file another bug. |
Awesome, thanks! I'll try it out once that PR lands. |
From here:
When I sent breakpoints with
addBreakpointWithScriptUri
like this:I get this error:
It may be related to the paths (we're sending paths, not package URIs), and there's still an open discussion about the format of these.
The text was updated successfully, but these errors were encountered: