Skip to content

Commit ea26a86

Browse files
authored
Merge pull request #273 from AthennaIO/develop
feat(ignite): dont exit by default on uncaught errors
2 parents e31c657 + c7d32eb commit ea26a86

4 files changed

Lines changed: 37 additions & 10 deletions

File tree

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.37.0",
3+
"version": "5.38.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: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export class Ignite extends Macroable {
8888
shutdownLogs: true,
8989
environments: [],
9090
exitOnError: true,
91+
exitOnUncaughtError: false,
9192
loadConfigSafe: true,
9293
athennaRcPath: './.athennarc.json',
9394
uncaughtExceptionHandler: this.handleUncaughtError
@@ -529,24 +530,28 @@ export class Ignite extends Macroable {
529530
if (process.versions.bun || (!Is.Error(error) && !Is.Exception(error))) {
530531
console.error(error)
531532

532-
return this.safeExit(1)
533+
return this.safeExitOnError(1)
533534
}
534535

535536
if (!Is.Exception(error)) {
536537
error = error.toAthennaException()
537538
}
539+
540+
if (!error.details) {
541+
error.details = []
542+
}
538543

539544
error.details.push({ isUncaughtError: false })
540545

541546
if (Config.is('app.logger.prettifyException', true)) {
542547
await Log.channelOrVanilla('exception').fatal(await error.prettify())
543548

544-
return this.safeExit(1)
549+
return this.safeExitOnError(1)
545550
}
546551

547552
await Log.channelOrVanilla('exception').fatal(error)
548553

549-
return this.safeExit(1)
554+
return this.safeExitOnError(1)
550555
}
551556

552557
/**
@@ -556,37 +561,52 @@ export class Ignite extends Macroable {
556561
if (process.versions.bun || (!Is.Error(error) && !Is.Exception(error))) {
557562
console.error(error)
558563

559-
return this.safeExit(1)
564+
return this.safeExitOnUncaughtError(1)
560565
}
561566

562567
if (!Is.Exception(error)) {
563568
error = error.toAthennaException()
564569
}
565570

571+
if (!error.details) {
572+
error.details = []
573+
}
574+
566575
error.details.push({ isUncaughtError: true })
567576

568577
if (Config.is('app.logger.prettifyException', true)) {
569578
await Log.channelOrVanilla('exception').fatal(await error.prettify())
570579

571-
return this.safeExit(1)
580+
return this.safeExitOnUncaughtError(1)
572581
}
573582

574583
await Log.channelOrVanilla('exception').fatal(error)
575584

576-
return this.safeExit(1)
585+
return this.safeExitOnUncaughtError(1)
577586
}
578587

579588
/**
580589
* Exit the application only if the exitOnError option is true.
581590
*/
582-
private safeExit(code: number): void {
591+
private safeExitOnError(code: number): void {
583592
if (!this.options.exitOnError) {
584593
return
585594
}
586595

587596
process.exit(code)
588597
}
589598

599+
/**
600+
* Exit the application only if the exitOnUncaughtError option is true.
601+
*/
602+
private safeExitOnUncaughtError(code: number): void {
603+
if (!this.options.exitOnUncaughtError) {
604+
return
605+
}
606+
607+
process.exit(code)
608+
}
609+
590610
/**
591611
* Parse some version string to the SemverNode type.
592612
*/

src/types/IgniteOptions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ export type IgniteOptions = {
1515
*/
1616
exitOnError?: boolean
1717

18+
/**
19+
* Exit the application if an uncaught error occurs.
20+
*
21+
* @default false
22+
*/
23+
exitOnUncaughtError?: boolean
24+
1825
/**
1926
* Show boot logs of the application. If this option is true, Athenna
2027
* will log operations that are being executed to boot your application.

0 commit comments

Comments
 (0)