fix(shorebird_cli): log stack trace only when using --verbose (#1918)

Co-authored-by: Felix Angelov <felix@shorebird.dev>
This commit is contained in:
borjandev
2024-04-17 19:09:17 +02:00
committed by GitHub
parent 1335f28cc0
commit 027e1be2c5
2 changed files with 14 additions and 2 deletions
@@ -135,7 +135,7 @@ class ShorebirdCliCommandRunner extends CompletionCommandRunner<int> {
// exit with an error code
logger
..err(e.message)
..err('$stackTrace')
..detail('$stackTrace')
..info('')
..info(usage);
return ExitCode.usage.code;
@@ -210,7 +210,7 @@ Run ${lightCyan.wrap('shorebird upgrade')} to upgrade.''');
} catch (error, stackTrace) {
logger
..err('$error')
..info('$stackTrace');
..detail('$stackTrace');
exitCode = ExitCode.software.code;
}
}
@@ -272,6 +272,18 @@ Run ${lightCyan.wrap('shorebird upgrade')} to upgrade.'''),
});
group('on command failure', () {
test('logs a stack trace using detail', () async {
// This will fail due to the release android command missing scoped
// dependencies.
// Note: the --verbose flag is here for illustrative purposes only.
// Because logger is a mock, setting the log level in code does
// nothing.
await runWithOverrides(
() => commandRunner.run(['release', 'android', '--verbose']),
);
verify(() => logger.detail(any(that: contains('#0')))).called(1);
});
group('when running with --verbose', () {
setUp(() {
when(() => logger.level).thenReturn(Level.verbose);