Skip to content

Commit 16dca7a

Browse files
authored
fix(firehose): keep dart_apitool crash details in logs and sanitize breaking table row (#461)
When `dart_apitool` fails to produce `report.json` (for example, when analyzing packages that use Dart 3.13 shorthand factory constructors under `analyzer 10.2.0`), `Health.breakingChangeCheck` previously interpolated the entire raw `stderr` output (including multi-line `ExecutableDeclaration.toString()` dumps and stack traces) directly into `BreakingChange.explanation` alongside `neededVersion: Version(0, 0, 0)`. Because `BreakingChange.toMarkdownRow()` did not sanitize newlines or pipe characters, the multi-line stack trace shattered the PR Health comment's Markdown table. - Keep full `stderr` diagnostics in the GitHub Actions workflow logs (via `runDashProcess` and `log(...)`). - Set `neededVersion: null`, preserve `package.version` for `newVersion`, and emit a concise single-line message (`Unable to calculate breaking changes (see workflow logs for details).`) in the PR comment table when `report.json` is not created. - Sanitize newlines (`\r?\n`) and pipe characters (`|`) in `BreakingChange.toMarkdownRow()` so multi-line explanations can never break the Markdown table structure. - Add unit test coverage for `BreakingChange.toMarkdownRow()`. Fixes #460 Related: bmw-tech/dart_apitool#266
1 parent 1bdafd8 commit 16dca7a

3 files changed

Lines changed: 34 additions & 5 deletions

File tree

‎pkgs/firehose/CHANGELOG.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## 0.13.2-wip
22

3+
- Log full `dart_apitool` failure output to the workflow log instead of dumping
4+
multi-line stack traces into the PR health comment Markdown table.
35
- Document Zizmor compatibility and ignore syntax for `post_summaries.yaml`.
46
- Update `post_summaries.yaml` to resolve PR numbers for fork workflow runs via
57
commit SHA, and verify comment authorship when checking `commentId`.

‎pkgs/firehose/lib/src/health/health.dart‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,14 +329,15 @@ For details on how to fix these, see [dependency_validator](https://pub.dev/pack
329329
explanation: versionMap['explanation'].toString(),
330330
);
331331
} else {
332-
log('Report was not created for $package at $reportPath');
332+
log('Report was not created for $package at $reportPath: $err');
333333
changeForPackage[package] = BreakingChange(
334334
level: BreakingLevel.breaking,
335335
oldVersion: Version(0, 0, 0),
336-
newVersion: Version(0, 0, 0),
337-
neededVersion: Version(0, 0, 0),
336+
newVersion: package.version ?? Version(0, 0, 0),
337+
neededVersion: null,
338338
versionIsFine: false,
339-
explanation: 'Report was not created for $package. Error: $err',
339+
explanation: 'Unable to calculate breaking changes '
340+
'(see workflow logs for details).',
340341
);
341342
}
342343
}
@@ -797,6 +798,11 @@ class BreakingChange {
797798
newVersion.toString(),
798799
needed,
799800
versionIsFine ? ':heavy_check_mark:' : ':warning:'
800-
].map((e) => e.toString()).join('|');
801+
]
802+
.map((e) => e
803+
.toString()
804+
.replaceAll(RegExp(r'\r?\n'), ' ')
805+
.replaceAll('|', r'\|'))
806+
.join('|');
801807
}
802808
}

‎pkgs/firehose/test/health_test.dart‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'package:firehose/src/health/health.dart';
99
import 'package:firehose/src/local_github_api.dart';
1010
import 'package:firehose/src/repo.dart';
1111
import 'package:path/path.dart' as p;
12+
import 'package:pub_semver/pub_semver.dart';
1213
import 'package:test/test.dart';
1314

1415
Future<void> main() async {
@@ -115,6 +116,26 @@ Future<void> main() async {
115116
},
116117
timeout: const Timeout(Duration(minutes: 2)),
117118
);
119+
120+
test('BreakingChange.toMarkdownRow sanitizes newlines and pipes', () {
121+
final change = BreakingChange(
122+
level: BreakingLevel.breaking,
123+
oldVersion: Version(0, 0, 0),
124+
newVersion: Version.parse('0.3.2-wip'),
125+
neededVersion: null,
126+
versionIsFine: false,
127+
explanation: 'Error line 1\nError line 2 | with pipe\r\nError line 3',
128+
);
129+
final row = change.toMarkdownRow();
130+
expect(row, isNot(contains('\n')));
131+
expect(row, isNot(contains('\r')));
132+
expect(
133+
row,
134+
'Breaking|0.0.0|0.3.2-wip|'
135+
r'Error line 1 Error line 2 \| with pipe Error line 3|'
136+
':warning:',
137+
);
138+
});
118139
}
119140

120141
Future<void> checkGolden(

0 commit comments

Comments
 (0)