TypeError when using Hono framework
mies opened this issue · comments
Environment information
typescript, hono framework
in index.ts:
import { Hono } from 'hono'
import { prettyJSON } from 'hono/pretty-json'
import { getUsers } from './model'
const app = new Hono()
app.get('/', (c) => c.text('Hello Hono!'))
app.use('*', prettyJSON())
app.notFound((c) => c.json({ message: 'Not Found', ok: false }, 404))
app.get('/users', (c) => {
const users = getUsers()
return c.json({ users })
})
export default app
and model.ts:
import { autometrics } from 'autometrics'
export interface User {
id: string,
name: string,
email: string,
}
export const getUsers = autometrics(async function getUsers(): Promise<User[]> {
const users: User[] = []
return users
})
### What happened?
$ bun run --hot src/index.ts
63 | var _a, b;
64 | const defaultPrepareStackTrace = Error.prepareStackTrace;
65 | Error.prepareStackTrace = (, stack2) => stack2;
66 | const { stack: stackConstructor } = new Error();
67 | Error.prepareStackTrace = defaultPrepareStackTrace;
68 | const stack = stackConstructor.map((callSite) => ({
^
TypeError: stackConstructor.map is not a function. (In 'stackConstructor.map((callSite) => ({
name: callSite.getFunctionName(),
file: callSite.getFileName()
}))', 'stackConstructor.map' is undefined)
at getModulePath (/Users/mies/p/am-samples/hono-autometrics/node_modules/@autometrics/autometrics/dist/index.js:68:16)
at autometrics (/Users/mies/p/am-samples/hono-autometrics/node_modules/@autometrics/autometrics/dist/index.js:309:17)
at /Users/mies/p/am-samples/hono-autometrics/src/model.ts:10:24
63 | var _a, b;
64 | const defaultPrepareStackTrace = Error.prepareStackTrace;
65 | Error.prepareStackTrace = (, stack2) => stack2;
66 | const { stack: stackConstructor } = new Error();
67 | Error.prepareStackTrace = defaultPrepareStackTrace;
68 | const stack = stackConstructor.map((callSite) => ({
^
TypeError: stackConstructor.map is not a function. (In 'stackConstructor.map((callSite) => ({
name: callSite.getFunctionName(),
file: callSite.getFileName()
}))', 'stackConstructor.map' is undefined)
at getModulePath (/Users/mies/p/am-samples/hono-autometrics/node_modules/@autometrics/autometrics/dist/index.js:68:16)
at autometrics (/Users/mies/p/am-samples/hono-autometrics/node_modules/@autometrics/autometrics/dist/index.js:309:17)
at /Users/mies/p/am-samples/hono-autometrics/src/model.ts:10:24
### Expected result
no error
Can you try this in Node.js and/or Deno? That stack trace is horrible, but I wouldn't be surprised if this is more of a Bun issue. It complains about the stackConstructor
, which seemingly comes from the standard Error
object. Unless the framework is doing some dirty prototype pollution, it's most likely Autometrics assumes some features of the runtime that are not there.
did a little further digging on this. The main problem is that the prepareStackTrace
(an interface that we rely on) is V8-only (which is why it works on Node/Deno) meanwhile Bun uses JavaScriptCore. I probably need to revert to using good old manual "stacktrace as string" parsing for these runtimes.