Skip to content

Commit

Permalink
feat(mason_cli): improve error when running add in an uninitialized w…
Browse files Browse the repository at this point in the history
…orkspace (#677)
  • Loading branch information
felangel committed Dec 23, 2022
1 parent a355896 commit 05baddb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/mason_cli/lib/src/install_brick.dart
Expand Up @@ -9,7 +9,11 @@ mixin InstallBrickMixin on MasonCommand {
/// Installs a specific brick and returns the [CachedBrick] reference.
Future<CachedBrick> addBrick(Brick brick, {bool global = false}) async {
final bricksJson = global ? globalBricksJson : localBricksJson;
if (bricksJson == null) usageException('bricks.json not found');
if (bricksJson == null) {
usageException(
'Mason has not been initialized.\nDid you forget to run mason init?',
);
}

final masonLockJsonFile =
global ? globalMasonLockJsonFile : localMasonLockJsonFile;
Expand Down
6 changes: 5 additions & 1 deletion packages/mason_cli/test/commands/add_test.dart
Expand Up @@ -52,7 +52,11 @@ void main() {
Directory.current = Directory.systemTemp.createTempSync();
final result = await commandRunner.run(['add', 'example', '--path', '.']);
expect(result, equals(ExitCode.usage.code));
verify(() => logger.err('bricks.json not found')).called(1);
verify(
() => logger.err(
'Mason has not been initialized.\nDid you forget to run mason init?',
),
).called(1);
});

test('exits with code 64 when exception occurs', () async {
Expand Down

0 comments on commit 05baddb

Please sign in to comment.