Skip to content

Commit

Permalink
fix: set correct exit code for the commands
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Nov 30, 2020
1 parent 1ff032c commit 0047d5b
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions commands/DbSeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ export default class DbSeed extends BaseCommand {
public static commandName = 'db:seed'
public static description = 'Execute database seeder files'

/**
* Track if one or more seeders have failed
*/
private hasError: boolean = false

/**
* Choose a custom pre-defined connection. Otherwise, we use the
* default connection
Expand Down Expand Up @@ -149,12 +154,18 @@ export default class DbSeed extends BaseCommand {
status: 'failed',
error: new Error('Invalid file path. Pass relative path from the application root'),
})
this.hasError = true
} else {
const response = await runner.run(sourceFile)
if (response.status === 'failed') {
this.hasError = true
}

this.printLogMessage(response)
}
}

this.exitCode = this.hasError ? 1 : 0
await db.manager.closeAll(true)
}
}
1 change: 1 addition & 0 deletions commands/Migration/Base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export default abstract class MigrationsBase extends BaseCommand {
break
case 'error':
this.logger.fatal(migrator.error!)
this.exitCode = 1
break
}
}
Expand Down
1 change: 1 addition & 0 deletions commands/Migration/Rollback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export default class Migrate extends MigrationsBase {
*/
if (!connection) {
this.printNotAValidConnection(this.connection)
this.exitCode = 1
return
}

Expand Down
1 change: 1 addition & 0 deletions commands/Migration/Run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export default class Migrate extends MigrationsBase {
*/
if (!connection) {
this.printNotAValidConnection(this.connection)
this.exitCode = 1
return
}

Expand Down
1 change: 1 addition & 0 deletions commands/Migration/Status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default class Status extends MigrationsBase {
*/
if (!connection) {
this.printNotAValidConnection(this.connection)
this.exitCode = 1
return
}

Expand Down

0 comments on commit 0047d5b

Please sign in to comment.