Skip to content

Commit 2c37bcd

Browse files
committed
assert on both errors and move to unhandled feature
1 parent 5408358 commit 2c37bcd

3 files changed

Lines changed: 41 additions & 32 deletions

File tree

packages/plugin-hono/src/hono.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,12 @@ module.exports = {
3737
})
3838

3939
const errorHandler = createMiddleware(async (c, next) => {
40-
let rethrow = false
41-
4240
try {
4341
// Catch non-errors thrown in routes without causing the route to hang by awaiting the next() call inside a try/catch block.
4442
// The error is then attached to the context and processed in the same way as errors thrown in routes.
4543
await next()
4644
} catch (err) {
4745
c.error = err
48-
rethrow = true
4946
}
5047

5148
if (!c.error) return
@@ -65,8 +62,6 @@ module.exports = {
6562
client._notify(event)
6663
}
6764
}
68-
69-
if (rethrow) throw c.error
7065
})
7166

7267
return { requestHandler, errorHandler }

test/aws-lambda/features/promise-rejection.feature

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -111,30 +111,3 @@ Scenario: promise rejections are reported when using hono
111111
Then the session is valid for the session reporting API version "1" for the "Bugsnag Node" notifier
112112
And the session "id" is not null
113113
And the session "startedAt" is a timestamp
114-
115-
@hono-app
116-
Scenario Outline: thrown non-error exceptions are reported when using hono
117-
Given I setup the environment
118-
When I invoke the "HonoFunction" lambda in "features/fixtures/hono-app" with the "events/throw-non-error.json" event
119-
Then the lambda response "errorMessage" equals "1"
120-
And the lambda response "errorType" equals "number"
121-
And the lambda response "body" is null
122-
And the lambda response "statusCode" is null
123-
And the SAM exit code equals 0
124-
When I wait to receive an error
125-
Then the error is valid for the error reporting API version "4" for the "Bugsnag Node" notifier
126-
And the event "unhandled" is true
127-
And the event "severity" equals "error"
128-
And the event "severityReason.type" equals "unhandledErrorMiddleware"
129-
And the exception "errorClass" equals "InvalidError"
130-
And the exception "message" matches "unhandledErrorMiddleware handler received a non-error\."
131-
And the exception "type" equals "nodejs"
132-
And the event "metaData.AWS Lambda context.functionName" equals "HonoFunction"
133-
And the event "metaData.AWS Lambda context.awsRequestId" is not null
134-
And the event "device.runtimeVersions.node" matches "^18\.\d+\.\d+$"
135-
When I wait to receive a session
136-
Then the session is valid for the session reporting API version "1" for the "Bugsnag Node" notifier
137-
And the session "id" is not null
138-
And the session "startedAt" is a timestamp
139-
And the event "session.events.handled" equals 0
140-
And the event "session.events.unhandled" equals 1

test/aws-lambda/features/unhandled.feature

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,3 +179,44 @@ Scenario Outline: unhandled asynchronous exceptions are reported when using hono
179179
And the event "session.events.handled" equals 0
180180
And the event "session.events.unhandled" equals 1
181181

182+
@hono-app
183+
Scenario Outline: thrown non-error exceptions are reported when using hono
184+
Given I setup the environment
185+
When I invoke the "HonoFunction" lambda in "features/fixtures/hono-app" with the "events/throw-non-error.json" event
186+
Then the lambda response "errorMessage" equals "1"
187+
And the lambda response "errorType" equals "number"
188+
And the lambda response "body" is null
189+
And the lambda response "statusCode" is null
190+
And the SAM exit code equals 0
191+
When I wait to receive 2 errors
192+
193+
Then the error is valid for the error reporting API version "4" for the "Bugsnag Node" notifier
194+
And the event "unhandled" is true
195+
And the event "severity" equals "error"
196+
And the event "severityReason.type" equals "unhandledException"
197+
And the exception "errorClass" equals "Error"
198+
And the exception "message" equals "1"
199+
And the exception "type" equals "nodejs"
200+
And the event "metaData.AWS Lambda context.functionName" equals "HonoFunction"
201+
And the event "metaData.AWS Lambda context.awsRequestId" is not null
202+
And the event "device.runtimeVersions.node" matches "^18\.\d+\.\d+$"
203+
204+
# Error thrown by hono
205+
And I discard the oldest error
206+
Then the error is valid for the error reporting API version "4" for the "Bugsnag Node" notifier
207+
And the event "unhandled" is true
208+
And the event "severity" equals "error"
209+
And the event "severityReason.type" equals "unhandledErrorMiddleware"
210+
And the exception "errorClass" equals "InvalidError"
211+
And the exception "message" matches "hono middleware received a non-error\."
212+
And the exception "type" equals "nodejs"
213+
And the event "metaData.AWS Lambda context.functionName" equals "HonoFunction"
214+
And the event "metaData.AWS Lambda context.awsRequestId" is not null
215+
And the event "device.runtimeVersions.node" matches "^18\.\d+\.\d+$"
216+
217+
When I wait to receive a session
218+
Then the session is valid for the session reporting API version "1" for the "Bugsnag Node" notifier
219+
And the session "id" is not null
220+
And the session "startedAt" is a timestamp
221+
And the event "session.events.handled" equals 0
222+
And the event "session.events.unhandled" equals 1

0 commit comments

Comments
 (0)