Repository navigation
Description
Hopefully I'm not asking for something that already exists.
Essentially I want to be able to add a break point to a specific exception.
Whenever that exception is thrown, the code should break.
This could be a library exception or one of my own exceptions.
In eclipse I can add an exception and eclipse will show me a list of all classes that extend Throwable (mine and library classes).
I can then simply select the exception that I want to break on. In dart we would need to allow the user to break on Exception or Error derived classes.
Of course Dart makes things harder by allowing you to throw anything and I guess we should cater to users that do that sort of thing but its not a feature I would use.
Perhaps this could be split into two different features.
- allow user to select from a list of classes that derive from or implement Exception or Error.
- use the node.js method of adding break points which allows a user to enter an expression to match the exception.
error.startsWith('x')
I'm guessing they call toString on the exception object.
I should note that the dart code documentation states:
Note: Production-quality code usually throws types that implement Error or Exception.
This could be used to justify only supporting Error/Exception derived classes and the lack of break points on other objects may encourage better programming practices. Of course I'm not certain that is the role of a IDE.
Here is the python discussion on adding break points.
I really don't like the idea of making the user have to pre-configure the list of possible exception classes.
microsoft/vscode-python#850
Activity
DanTup commentedon Oct 18, 2021
This doesn't currently exist, we only allow controlling exceptions with the checkboxes for None/Uncaught/All which goes through to this VM Service call:
https://github.com/dart-lang/sdk/blob/master/runtime/vm/service/service.md#setexceptionpausemode
I can think of two ways to implement this:
I'm not entirely sold on any of the UI options shown in the Python thread though. Listing them in launch.json doesn't seem very accessible (and requires you have a launch.json), adding them to the Debug side bar looks very messy (and doesn't allow for arbitrary matching), and the pick-lists shown for Mono seems like only a slight improvement.
It does seem like we can add conditions to exception breakpoint filters though:
This would only allow one expression though - do you think that would be enough?
bsutton commentedon Oct 18, 2021
In must cases I'm only trying to break on a single exception but I do occasionally need/want to break on two or three different exceptions.
I assume editing the Uncaught exception is something you have added because I can't do it in current version of dart-code.
The only obvious issue is that just because I'm trying to break on a specific exception doesn't mean I don't also want to break on any uncaught exception which this option seems to preclude.
Probably not a major issue as generally I am focused on one exception.
The syntax of the expression is also unclear. When reading the python issue around this it wasn't clear what the expression evaluated against so if we go this way we would need to document how the expression works.
So I guess my preference would be to be able to add additional catch break points rather re-using the Uncaught exceptions but I could live with this.
I assume that the express also works for caught exceptions as that would be a requirement.
So in summary; I could live with this but adding multiples would be better. Needs some doco on the expressions.
DanTup commentedon Oct 19, 2021
Sorry, this was a TypeScript project. I was just checking how the UI worked. I don't have a Dart implementation of it currently.
If you add a condition to "uncaught exception" it would change that condition to be "any uncaught exception that matches this condition", so it would not break on other (non-matching) uncaught exceptions. If you wanted to break on all uncaught exceptions, but also caught exceptions matching a specific condition, you could add the condition to the "all exceptions" checkbox.
Yep. I think we can add tooltips to this tickboxes, so we may be able to include details there (I think there's also a VS Code issue open about supporting tooltips with hyperlinks to link to other docs). My thinking was that you could enter a string that would be matched against the exception type name and it's toString() value. I'm not sure the user should need to type a whole valid expression (although whether that should also be possible, I'm not sure).
I would prefer this too - although as far as I can tell, the API doesn't currently support adding additional entries after the debug session is initialised.
@isidorn is this (a better way for users to be able to add additional exception breakpoint filters without the DA needing to pre-declare them up-front) something that has been discussed? I think the "Add function breakpoint" functionality would work well if the user could instead pick "Add exception breakpoint" and then just type an expression. The current ability to add expressions to the existing exception filters doesn't allow the user to add more (eg. if they want to break on two types of exceptions). It seems like extensions are all doing their own things (launch.json, pick-lists, listing exceptions in the exception tickboxes) and seems like a good candidate for something consistent and more flexible?
isidorn commentedon Oct 19, 2021
@DanTup This has not been discussed as far as I know.
@roblourens and @weinand would know more.
weinand commentedon Oct 19, 2021
DAP provides flexible exception support by means of the ExceptionOptions and ExceptionPathSegment types. See microsoft/vscode-debugadapter-node#64 for details.
Examples for the supported use cases are here: microsoft/vscode-debugadapter-node#64 (comment)
And here is a summary of the discussions: microsoft/vscode-debugadapter-node#64 (comment)
Today VS Code does not implement a generic UI for that DAP feature.
But for VS Code release 1.11 I've implemented a QuickPick based UI for the "exception configuration API".
Search for "Usage example for exception configuration API" in the VS Code 1.11 release notes
bkonyi commentedon Oct 20, 2021
This functionality seems like it would be useful and could probably just live in DDS so we don't need to deal with multiple implementations in the VM service and DWDS. Can you file an issue in the SDK for this? I'm not sure when I'd have time to get to this, but I'll put it on my queue.
DanTup commentedon Oct 26, 2021
@weinand ah, interesting - thanks!
@bkonyi filed dart-lang/sdk#47552, thanks!