How can I debug package:build?

656 views
Skip to first unread message

Philipp S

unread,
Jul 19, 2018, 6:22:33 PM7/19/18
to Dart Misc
Hello!

I'm trying to write a Builder using package:build. Right now I need to debug what I wrote, but I have serious problems to access the state of my program: The debugger doesn't stop on breakpoints or thrown exceptions.
My setup is:
- I run `pub run build_runner build` to generate a .dart_tool/build/entrypoint/build.dart file.
- I run `dart --observe --pause-isolates-on-start .dart_tool/build/entrypoint/build.dart build`.
- I set a breakpoint in my builder class. (here[1] to be exact)
- When continuing the program, the breakpoint is ignored, and some lines later an exception is thrown.
I use Dart 2.0.0-dev.68.0 and build 0.12.7+2.

I appreciate any hints how I can approach this situation. As a last resort, I tried using `print()` calls to get any information out of the program, but even the print output is somehow intercepted.

Best regards
Philipp


Nate Bosch

unread,
Jul 19, 2018, 6:33:34 PM7/19/18
to mi...@dartlang.org
On Thu, Jul 19, 2018 at 3:22 PM Philipp S <philippsc...@gmail.com> wrote:
Hello!

I'm trying to write a Builder using package:build. Right now I need to debug what I wrote, but I have serious problems to access the state of my program: The debugger doesn't stop on breakpoints or thrown exceptions.
My setup is:
- I run `pub run build_runner build` to generate a .dart_tool/build/entrypoint/build.dart file.
- I run `dart --observe --pause-isolates-on-start .dart_tool/build/entrypoint/build.dart build`.
- I set a breakpoint in my builder class. (here[1] to be exact)
- When continuing the program, the breakpoint is ignored, and some lines later an exception is thrown.
I use Dart 2.0.0-dev.68.0 and build 0.12.7+2.

This is exactly the approach we expect and is what has worked for me in the past. Is it possible there is some confusion about exactly where the throw is happening compared to the breakpoints you are setting?

You might want to try with `--verbose` since that will also print stack traces for any exceptions caught by the build system.
 

I appreciate any hints how I can approach this situation. As a last resort, I tried using `print()` calls to get any information out of the program, but even the print output is somehow intercepted.

Yes, `print()` statements are caught and turned in to `log.info`, and `log.info` lines can be overwritten. `--verbose` will make it stop overwriting INFO lines so you'll start seeing the output from your print statements. You can also `log.warning` and those are never overwritten on the console.
 
--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/dadfd9ab-7ac6-45a0-b8ee-8d7f0484c387%40dartlang.org.

Philipp S

unread,
Jul 19, 2018, 7:05:50 PM7/19/18
to Dart Misc
Thanks for the quick response!


This is exactly the approach we expect and is what has worked for me in the past. Is it possible there is some confusion about exactly where the throw is happening compared to the breakpoints you are setting?

You might want to try with `--verbose` since that will also print stack traces for any exceptions caught by the build system.
Passing `--verbose` gives me this call stack:


package:regular_scanner/builder.dart 159:3                              resolveInjectScannerArguments

package:regular_scanner/builder.dart 75:11                              ScannerGenerator.generateForAnnotatedElement.<fn>

dart:async                                                              runZoned

package:regular_scanner/builder.dart 73:12                              ScannerGenerator.generateForAnnotatedElement

package:source_gen/src/generator_for_annotation.dart 42:28              GeneratorForAnnotation.generate

package:source_gen/src/builder.dart 213:35                              _generate

package:source_gen/src/builder.dart 74:15                               _Builder._generateForLibrary

package:source_gen/src/builder.dart 68:11                               _Builder.build

package:build                                                           runBuilder

package:build_runner_core/src/generate/build_impl.dart 432:15           _SingleBuild._runForInput.<fn>

package:build_runner_core/src/generate/performance_tracker.dart 304:73  _NoOpBuilderActionTracker.track

package:build_runner_core/src/generate/build_impl.dart 431:19           _SingleBuild._runForInput

package:build_runner_core/src/generate/build_impl.dart 356:38           _SingleBuild._runBuilder.<fn>

dart:async                                                              Future.wait

package:build_runner_core/src/generate/build_impl.dart 355:36           _SingleBuild._runBuilder

dart:async                                                              _AsyncAwaitCompleter.start

package:build_runner_core/src/generate/build_impl.dart 353:40           _SingleBuild._runBuilder

package:build_runner_core/src/generate/build_impl.dart 303:32           _SingleBuild._runPhases.<fn>

dart:async                                                              _completeOnAsyncReturn

package:build_runner_core/src/generate/build_impl.dart                  _SingleBuild._matchingPrimaryInputs


I have scattered breakpoints all over those methods. At the beginning of ScannerGenerator.generateForAnnotatedElement, in the very line that contains the `throw` expression ...
Any other idea? The debugger works fine for me in other projects.

Yes, `print()` statements are caught and turned in to `log.info`, and `log.info` lines can be overwritten. `--verbose` will make it stop overwriting INFO lines so you'll start seeing the output from your print statements. You can also `log.warning` and those are never overwritten on the console.
This is a start, thanks.

Philipp S

unread,
Jul 20, 2018, 5:55:34 AM7/20/18
to Dart Misc


Am Freitag, 20. Juli 2018 00:33:34 UTC+2 schrieb Nate Bosch:

This is exactly the approach we expect and is what has worked for me in the past. Is it possible there is some confusion about exactly where the throw is happening compared to the breakpoints you are setting?

You might want to try with `--verbose` since that will also print stack traces for any exceptions caught by the build system.
I found the source of the confusion: The `throw` isn't happening **at all**! The build package caches not only successful builds, but also errors. If neither the build script nor the input file has changed, then my builder class is never called – the error messages **and the stack trace** are retrieved from a cache file. However, the build runner doesn't tell you that, the output looks identical whether your builder was executed or not. I didn't expect this in any way, so I'll open an issue and see if this can be communicated better.

If anyone else stumbles upon this: While debugging your build script, don't let it run through. If you let build_runner terminate normally, then it will create a cache file with all the output from your builder, and reuse that. If you kill the program as soon as you've got the information you wanted, this cache file will not be created and you don't have to manually delete it before the next debug run.

Best regards
Philipp

Nate Bosch

unread,
Jul 20, 2018, 2:01:08 PM7/20/18
to mi...@dartlang.org
Wow yeah that is a really confusing situation. We added the error re-reporting recently and I completely overlooked it as a factor. Thanks for raising the issue, I'll update the error messages so they look a little different.

--
For more ways to connect visit https://www.dartlang.org/community
---
You received this message because you are subscribed to the Google Groups "Dart Misc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.
Reply all
Reply to author
Forward
0 new messages