Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -32,8 +35,7 @@ jobs:
id: release

- name: Publish to NPM Registry
run: cd build && npm publish --access public
run: cd build && npm publish --provenance --access public
if: steps.release.outputs.released == 'true'
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
name: Deploy
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@athenna/core",
"version": "5.36.0",
"version": "5.37.0",
"description": "One foundation for multiple applications.",
"license": "MIT",
"author": "João Lenon <lenon@athenna.io>",
Expand Down
52 changes: 45 additions & 7 deletions src/ignite/Ignite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ export class Ignite extends Macroable {
bootLogs: true,
shutdownLogs: true,
environments: [],
exitOnError: true,
loadConfigSafe: true,
athennaRcPath: './.athennarc.json',
uncaughtExceptionHandler: this.handleError
uncaughtExceptionHandler: this.handleUncaughtError
})

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

/**
* Return is needed only for testing purposes.
*/
return process.exit(1)
return this.safeExit(1)
}

if (!Is.Exception(error)) {
error = error.toAthennaException()
}

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

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

process.exit(1)
return this.safeExit(1)
}

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

process.exit(1)
return this.safeExit(1)
}

/**
* Handle an uncaught error turning it pretty and logging as fatal.
*/
public async handleUncaughtError(error: any) {
if (process.versions.bun || (!Is.Error(error) && !Is.Exception(error))) {
console.error(error)

return this.safeExit(1)
}

if (!Is.Exception(error)) {
error = error.toAthennaException()
}

error.details.push({ isUncaughtError: true })

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

return this.safeExit(1)
}

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

return this.safeExit(1)
}

/**
* Exit the application only if the exitOnError option is true.
*/
private safeExit(code: number): void {
if (!this.options.exitOnError) {
return
}

process.exit(code)
}

/**
Expand Down
7 changes: 7 additions & 0 deletions src/types/IgniteOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
*/

export type IgniteOptions = {
/**
* Exit the application if an error occurs.
*
* @default true
*/
exitOnError?: boolean

/**
* Show boot logs of the application. If this option is true, Athenna
* will log operations that are being executed to boot your application.
Expand Down
Loading