Skip to content

Commit e31c657

Browse files
authored
Merge pull request #272 from AthennaIO/develop
fix(ignite): add option to dont exit on errors
2 parents b0b5b6d + 4c2923d commit e31c657

5 files changed

Lines changed: 59 additions & 12 deletions

File tree

.github/workflows/cd.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
jobs:
99
build:
1010
runs-on: ubuntu-latest
11+
permissions:
12+
contents: write
13+
id-token: write
1114
steps:
1215
- name: Checkout
1316
uses: actions/checkout@v2
@@ -32,8 +35,7 @@ jobs:
3235
id: release
3336

3437
- name: Publish to NPM Registry
35-
run: cd build && npm publish --access public
38+
run: cd build && npm publish --provenance --access public
3639
if: steps.release.outputs.released == 'true'
3740
env:
38-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
3941
name: Deploy

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@athenna/core",
3-
"version": "5.36.0",
3+
"version": "5.37.0",
44
"description": "One foundation for multiple applications.",
55
"license": "MIT",
66
"author": "João Lenon <lenon@athenna.io>",

src/ignite/Ignite.ts

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,10 @@ export class Ignite extends Macroable {
8787
bootLogs: true,
8888
shutdownLogs: true,
8989
environments: [],
90+
exitOnError: true,
9091
loadConfigSafe: true,
9192
athennaRcPath: './.athennarc.json',
92-
uncaughtExceptionHandler: this.handleError
93+
uncaughtExceptionHandler: this.handleUncaughtError
9394
})
9495

9596
this.setUncaughtExceptionHandler()
@@ -528,25 +529,62 @@ export class Ignite extends Macroable {
528529
if (process.versions.bun || (!Is.Error(error) && !Is.Exception(error))) {
529530
console.error(error)
530531

531-
/**
532-
* Return is needed only for testing purposes.
533-
*/
534-
return process.exit(1)
532+
return this.safeExit(1)
535533
}
536534

537535
if (!Is.Exception(error)) {
538536
error = error.toAthennaException()
539537
}
540538

539+
error.details.push({ isUncaughtError: false })
540+
541541
if (Config.is('app.logger.prettifyException', true)) {
542542
await Log.channelOrVanilla('exception').fatal(await error.prettify())
543543

544-
process.exit(1)
544+
return this.safeExit(1)
545545
}
546546

547547
await Log.channelOrVanilla('exception').fatal(error)
548548

549-
process.exit(1)
549+
return this.safeExit(1)
550+
}
551+
552+
/**
553+
* Handle an uncaught error turning it pretty and logging as fatal.
554+
*/
555+
public async handleUncaughtError(error: any) {
556+
if (process.versions.bun || (!Is.Error(error) && !Is.Exception(error))) {
557+
console.error(error)
558+
559+
return this.safeExit(1)
560+
}
561+
562+
if (!Is.Exception(error)) {
563+
error = error.toAthennaException()
564+
}
565+
566+
error.details.push({ isUncaughtError: true })
567+
568+
if (Config.is('app.logger.prettifyException', true)) {
569+
await Log.channelOrVanilla('exception').fatal(await error.prettify())
570+
571+
return this.safeExit(1)
572+
}
573+
574+
await Log.channelOrVanilla('exception').fatal(error)
575+
576+
return this.safeExit(1)
577+
}
578+
579+
/**
580+
* Exit the application only if the exitOnError option is true.
581+
*/
582+
private safeExit(code: number): void {
583+
if (!this.options.exitOnError) {
584+
return
585+
}
586+
587+
process.exit(code)
550588
}
551589

552590
/**

src/types/IgniteOptions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
*/
99

1010
export type IgniteOptions = {
11+
/**
12+
* Exit the application if an error occurs.
13+
*
14+
* @default true
15+
*/
16+
exitOnError?: boolean
17+
1118
/**
1219
* Show boot logs of the application. If this option is true, Athenna
1320
* will log operations that are being executed to boot your application.

0 commit comments

Comments
 (0)