pipe/test/sdk_unreadable_test.dart
trvon d6b6bcb438
Some checks failed
Lint Commits / commitlint (pull_request) Successful in 17s
Tests / Static Analysis (pull_request) Has been cancelled
Tests / Tests (pull_request) Has been cancelled
fix(analysis): report an unreadable SDK cleanly instead of crashing
ae412a7 routed filesystem failures to exit 2, but the analyzer throws its own
FileSystemException (package:analyzer/file_system), which the dart:io catch
in bin/pipe.dart never matched. A project whose package_config still named a
moved Flutter SDK therefore crashed with exit 255 and a stack trace. Found
by dogfooding on word_alive after its SDK moved.

Analyzer.create now turns that into a PipeException naming the SDK path, with
the remedy to re-run flutter pub get or pass --sdk.
2026-09-22 12:22:03 -06:00

37 lines
1.1 KiB
Dart

import 'dart:io';
import 'package:pipe/src/cli.dart';
import 'package:pipe/src/errors.dart';
import 'package:test/test.dart';
void main() {
test(
'an SDK the analyzer cannot read is a clean error, not a crash',
() async {
// A project whose package_config names a Flutter SDK that has since moved
// left the analyzer unable to read the SDK's allowed_experiments.json. The
// analyzer throws its own FileSystemException, which bin/pipe.dart's
// dart:io catch never saw: exit 255 and a stack trace.
final sdk = Directory.systemTemp.createTempSync('pipe-hollow-sdk');
addTearDown(() => sdk.deleteSync(recursive: true));
File('${sdk.path}/version').writeAsStringSync('3.13.0\n');
Directory('${sdk.path}/lib').createSync();
await expectLater(
PipeRunner().run([
'check',
'test/fixtures/stuck_loading',
'--sdk',
sdk.path,
]),
throwsA(
isA<PipeException>().having(
(error) => error.remedy,
'remedy',
contains('flutter pub get'),
),
),
);
},
);
}