Skip to content

Commit

Permalink
refactor(cli): return errors
Browse files Browse the repository at this point in the history
  • Loading branch information
juanrgm committed Sep 25, 2023
1 parent d87e1c4 commit 4db934c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/cli/src/Action/BackupAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export class BackupAction<TRequired extends boolean = true> {

async exec(session: BackupSessionManager) {
const [snapshot, packages] = await this.init(session);
let errors = 0;
const errors: Error[] = [];

for (const pkg of packages) {
const id = session.findId({
Expand Down Expand Up @@ -363,7 +363,7 @@ export class BackupAction<TRequired extends boolean = true> {

const error = this.getError(pkg);

if (error) errors++;
if (error) errors.push(error);
await session.end({
id: id,
error: error?.message,
Expand All @@ -376,7 +376,7 @@ export class BackupAction<TRequired extends boolean = true> {

return {
total: packages.length,
errors: errors,
errors,
};
}
}
6 changes: 3 additions & 3 deletions packages/cli/src/Action/RestoreAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ export class RestoreAction<TRequired extends boolean = true> {

await this.init(session, this.options.snapshotId, snapshotAndConfigs);

let sessionErrors = 0;
const errors: Error[] = [];

for (const [snapshot, pkg] of snapshotAndConfigs) {
ok(pkg);
Expand Down Expand Up @@ -363,10 +363,10 @@ export class RestoreAction<TRequired extends boolean = true> {
id,
error: error?.message,
});
if (error) sessionErrors++;
if (error) errors.push(error);
}

await session.endDrivers();
return !sessionErrors;
return { errors };
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/Command/BackupCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export class BackupCommand extends CommandAbstract<
});

const result = await backup.exec(sessionManager);
if (result.errors) {
if (result.errors.length) {
return 1;
} else if (!result.total) {
throw new AppError("None package config found");
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/Command/RestoreCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,6 @@ export class RestoreCommand extends CommandAbstract<

const result = await restore.exec(sessionManager);

return result ? 0 : 1;
return result.errors.length ? 0 : 1;
}
}

0 comments on commit 4db934c

Please sign in to comment.