Skip to content

Asserts are no longer enabled by default for non-debug sessions #4379

Closed

Description

@bwilkerson

There might already be a way to do this that I didn't find, but I would like to be able to run code with asserts enabled without having to be running under the debugger. The primary motivation for not using the debugger is that the code runs slower.

My guess is that this would need to be a preference setting, but I'm happy with any solution you think would be best.

Activity

  1. added
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    on Feb 8, 2023
  2. DanTup commented on Feb 8, 2023

    @DanTup
    Member

    Hmmm, on the surface this feels like a bug to me. I was under the impression we always ran with asserts enabled from the IDE by default (because I assumed at dev time that's what you'd want), however I can repro this doesn't work and it's because of this isDebug here:

    if (isDebug && debugConfig.enableAsserts !== false) // undefined = on
    this.addArgsIfNotExist(args, "--enable-asserts");

    It was added during the migration of flags from inside the debug adapter into the VS Code extension (to simplify the new debug adapters), but it doesn't appear to have had this condition when it was in the debug adapter. The change doesn't describe that it was deliberate, although it seems hard to do this accidentally.

    I'm going to try removing that condition and running the bots and see what happens.

    In the meantime, if you have a launch.json you can add --enable-asserts to toolArgs. This will apply to running using the Run/Debug menu (and pressing F5 etc.), but to make it apply to the Run/Debug CodeLens (the links above main/test/group methods), it needs to be marked as a template with templateFor: "":

    {
    	"version": "0.2.0",
    	"configurations": [
    		{
    			"name": "dart",
    			"request": "launch",
    			"type": "dart",
    			"toolArgs": [
    				"--enable-asserts" // enable asserts
    			],
    			"templateFor": "", // use as the template for Run/Debug for the whole project (this is a path prefix, empty string matches the entire project)
    		}
    	]
    }
  3. DanTup commented on Feb 8, 2023

    @DanTup
    Member

    This was originally implemented in af06b7f for #3702 but had no tests which would've probably have picked up the regression.

    Bots are all green so I'm going to restore this (and add tests).

  4. changed the title [-]A way to enable asserts when not running the debugger[/-] [+]Asserts are no longer enabled by default for non-debug sessions[/+] on Feb 8, 2023
  5. added
    in debuggingRelates to the debug adapter or process of running debug sessions
    and removed
    is enhancementAn enhancement or improvement that should be listed in release notes but is not a bug fix.
    on Feb 8, 2023
  6. added this to the v3.60.0 milestone on Feb 8, 2023
  7. added a commit that references this issue on Feb 8, 2023
    661da2d
  8. DanTup commented on Feb 8, 2023

    @DanTup
    Member

    @bwilkerson btw I kicked off a pre-release version with this in it earlier. If you're on the pre-release Dart extension and have updated to v3.59.20230208 (note the last digit is an 8, there was a pre-release yesterday ending 7 but otherwise the same) and reloaded, then asserts should be on by default and not need the launch.json gymnastics above (unless you want to disable asserts).

    I can't be certain this change in default behaviour won't upset anyone, but it was the original and intended behaviour. If this poses a problem we can add a setting to make it easier to control without needing a launch configuration.

  9. added a commit that references this issue on Sep 2, 2025
    c0e0203
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    in debuggingRelates to the debug adapter or process of running debug sessionsis bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions