Skip to content
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

Add a BuildFailure class, and catch in the runners #981

Open
3 tasks
matanlurey opened this issue Feb 8, 2018 · 13 comments
Open
3 tasks

Add a BuildFailure class, and catch in the runners #981

matanlurey opened this issue Feb 8, 2018 · 13 comments
Labels
package:build_runner package:build type-enhancement A request for a change that isn't a bug

Comments

@matanlurey
Copy link
Contributor

matanlurey commented Feb 8, 2018

We should not display the stack trace (or do it as FINE) for these type of errors.

/cc @natebosch

@natebosch
Copy link
Member

natebosch commented Feb 8, 2018

Some other options for completeness:

  • Stop printing stack traces by default and only print them when some option is passed
  • Check the type, if its a subclass of Error don't print the stack trace, and if it's a subclass of Exception print it.

@matanlurey
Copy link
Contributor Author

I personally like BuildError, because it could also do other nice things:

  • Capture the current primaryInput (?)
  • Be extended by clients, i.e. TemplateBuildError, InjectionBuildError for us

@matanlurey
Copy link
Contributor Author

@jakemac53 any thoughts here?

@jakemac53
Copy link
Contributor

+1 I am in favor, we should also automagically wrap any normal exceptions from builders in one of these

@leonsenft
Copy link
Contributor

I'm considering trying this before #2624, but it's unclear to me where such errors should be handled in build_runner and bazel_codegen.

build_runner (and friends) in particular has so much indirection I can't quite figure out where an individual builder is even invoked. Do you have any pointers on where to get started? Thanks!

@leonsenft leonsenft self-assigned this Mar 2, 2020
@jakemac53
Copy link
Contributor

@natebosch
Copy link
Member

Builders are invoked here:

I would expect that special handling for this exception might involve the logging handler:

onError: (Object e, StackTrace s) {

@leonsenft
Copy link
Contributor

Great, thanks for the help! One last quick question before I get started. The proposal suggests an Error (based on the name), but this would be better suited as an Exception because it's intended to be caught, right?

@natebosch
Copy link
Member

Yes. This should be an exception. I would implement that interface but not include it in the name BuildFailure is my first choice.

@natebosch natebosch changed the title Add a BuildError class, and catch in the runners Add a BuildFailure class, and catch in the runners Mar 9, 2020
@leonsenft
Copy link
Contributor

Some other options for completeness:

  • Stop printing stack traces by default and only print them when some option is passed

@natebosch Is this effectively done now? Looks like the stack trace is only printed in verbose mode:

if (record.stackTrace != null && verbose) {
var trace = Trace.from(record.stackTrace).foldFrames((f) {
return f.package == 'build_runner' || f.package == 'build';
}, terse: true);
lines.add(trace);
}

@natebosch
Copy link
Member

Is this effectively done now?

Yeah I think so. We could consider having an even more suppressed stack trace for this exception type specifically, but I don't know that it is necessary.

@leonsenft
Copy link
Contributor

In that case, what differentiates an exception that is specifically a BuildFailure versus one that is not? Won't both be caught, logged, and have their stack trace shown depending on whether the verbose flag is set or not?

@natebosch
Copy link
Member

We'd have to do something like if (verbose && error is! BuildFailure) printStackTrace(). I think it's probably not really necessary though.

It's entirely possible that we don't even need to define BuildFailure and we could leave it at getting more concrete about how authors should handle failures. Things like not adding unnecessary catch and letting the exception, of any type, bubble up.

One benefit of having a single type that everyone agrees means "this isn't a bug, the build is bad" is that if builder authors do want to do some munging of exceptions they could use a pattern like:

try {
  await doBuilderWork();
} on BuildFailure {
  rethrow;
} catch (e, st) {
  throw MyBuilderHasABug(); // nice error message about filing a bug
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:build_runner package:build type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants