Skip to content

Commit

Permalink
Merge pull request #197 from AthennaIO/develop
Browse files Browse the repository at this point in the history
Handle non-object errors
  • Loading branch information
jlenon7 authored Oct 21, 2023
2 parents 71960c4 + 3ae9c1b commit 3e84e61
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
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": "4.12.0",
"version": "4.13.0",
"description": "The plug and play Node.js framework.",
"license": "MIT",
"author": "João Lenon <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion src/ignite/Ignite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ export class Ignite {
* Handle an error turning it pretty and logging as fatal.
*/
public async handleError(error: any) {
if (process.versions.bun) {
if (process.versions.bun || (!Is.Error(error) && !Is.Exception(error))) {
console.error(error)

/**
Expand Down
23 changes: 23 additions & 0 deletions tests/unit/ignite/IgniteTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,29 @@ export default class IgniteTest {
assert.notCalled(fatalMock)
}

@Test()
public async shouldCatchErrorsThatAreNotVanillaErrorsOrExceptions({ assert }: Context) {
process.versions.bun = '1.0.0'
const fatalMock = Mock.fake()
Log.when('channelOrVanilla').return({
fatal: fatalMock
})
Mock.when(process.stderr, 'write').return(undefined)
Mock.when(process, 'exit').return(undefined)

const ignite = new Ignite()

Mock.spy(ignite, 'handleError')
Mock.when(ignite, 'setUncaughtExceptionHandler').throw('error')

await ignite.load(Path.toHref(Path.pwd() + '/'))

assert.calledOnce(process.stderr.write)
assert.calledWith(process.exit, 1)
assert.calledOnce(ignite.handleError)
assert.notCalled(fatalMock)
}

@Test()
public async shouldBeAbleToLoadAnEnvFileWhenFiringAthennaApplication({ assert }: Context) {
const ignite = await new Ignite().load(Path.toHref(Path.pwd() + '/'), {
Expand Down

0 comments on commit 3e84e61

Please sign in to comment.