Discussion:
[dart-misc] How can I debug package:build?
Philipp S
2018-07-19 22:22:32 UTC
Permalink
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

[1]: https://github.com/pschiffmann/regular_scanner.dart/blob/57cbd5bf824ad1f76e94db1c08fdf2f7f2f2a048/lib/builder.dart#L71
--
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+***@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.
'Nate Bosch' via Dart Misc
2018-07-19 22:33:17 UTC
Permalink
Post by Philipp S
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.
- 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.
Post by Philipp S
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.
Post by Philipp S
Best regards
Philipp
https://github.com/pschiffmann/regular_scanner.dart/blob/57cbd5bf824ad1f76e94db1c08fdf2f7f2f2a048/lib/builder.dart#L71
--
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
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
<https://groups.google.com/a/dartlang.org/d/msgid/misc/dadfd9ab-7ac6-45a0-b8ee-8d7f0484c387%40dartlang.org?utm_medium=email&utm_source=footer>
.
--
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+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CA%2B%3DXefcofHJQnSgHmWoK%3DYufR4uQ0rSrKbeo3BpGzFKYv-%2B2%3DQ%40mail.gmail.com.
Philipp S
2018-07-19 23:05:50 UTC
Permalink
Thanks for the quick response!

This is exactly the approach we expect and is what has worked for me in the
Post by 'Nate Bosch' via Dart Misc
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 `
Post by 'Nate Bosch' via Dart Misc
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.
--
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+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/d0720858-4d18-48df-a1b9-a6b54f2e8d02%40dartlang.org.
Philipp S
2018-07-20 09:55:34 UTC
Permalink
Post by 'Nate Bosch' via Dart Misc
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
--
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+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/ebe1ac5a-0e1c-47f4-b5e6-420ea809ca65%40dartlang.org.
'Nate Bosch' via Dart Misc
2018-07-20 18:00:50 UTC
Permalink
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.
Post by Philipp S
Post by 'Nate Bosch' via Dart Misc
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
--
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
To view this discussion on the web visit
https://groups.google.com/a/dartlang.org/d/msgid/misc/ebe1ac5a-0e1c-47f4-b5e6-420ea809ca65%40dartlang.org
<https://groups.google.com/a/dartlang.org/d/msgid/misc/ebe1ac5a-0e1c-47f4-b5e6-420ea809ca65%40dartlang.org?utm_medium=email&utm_source=footer>
.
--
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+***@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/misc/CA%2B%3DXefd7UqGcyFsi3Q-6MfPHNmMg2_if7bTqBKOgWhjjPoG-uw%40mail.gmail.com.
Loading...