Skip to content

Skip logging stack traces of an Exception. #4040

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

Merged
merged 1 commit into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions build_runner/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## 2.5.1-wip

- Don't show stack traces if a generator throws `InvalidGenerationSourceError`
from `source_gen`.
- Don't log stack traces for subclasses of `Exception`.

## 2.5.0

Expand Down
3 changes: 1 addition & 2 deletions build_runner_core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
## 9.0.1-wip

- Don't show stack traces if a generator throws `InvalidGenerationSourceError`
from `source_gen`.
- Don't log stack traces for subclasses of `Exception`.

## 9.0.0

Expand Down
12 changes: 3 additions & 9 deletions build_runner_core/lib/src/logging/build_log.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import 'dart:async';
import 'dart:math';

import 'package:build/build.dart'
show AssetId, SyntaxErrorInAssetException, UnresolvableAssetException;
import 'package:build/build.dart' show AssetId;
// ignore: implementation_imports
import 'package:build_runner/src/internal.dart';
import 'package:logging/logging.dart';
Expand Down Expand Up @@ -414,8 +413,7 @@ class BuildLog {

/// Renders [message] with optional [error] and [stackTrace].
///
/// Drops `build_runner` exceptions that can be caused by normal user input:
/// [SyntaxErrorInAssetException] and [UnresolvableAssetException].
/// Skips rendering [stackTrace] if [error] is an [Exception].
String renderThrowable(
Object? message, [
Object? error,
Expand All @@ -427,11 +425,7 @@ class BuildLog {
result += '$error';
}

if (stackTrace != null &&
error is! SyntaxErrorInAssetException &&
error is! UnresolvableAssetException &&
// From `source_gen`, use the name to avoid a build dependency.
error.runtimeType.toString() != 'InvalidGenerationSource') {
if (stackTrace != null && error is! Exception) {
result += '\n$stackTrace';
}
return result;
Expand Down