Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError when using Hono framework #112

Closed
mies opened this issue Aug 4, 2023 · 2 comments · Fixed by #127
Closed

TypeError when using Hono framework #112

mies opened this issue Aug 4, 2023 · 2 comments · Fixed by #127
Labels
bug Something isn't working

Comments

@mies
Copy link
Member

mies commented Aug 4, 2023

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
@arendjr
Copy link
Collaborator

arendjr commented Aug 7, 2023

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.

@keturiosakys
Copy link
Member

keturiosakys commented Aug 24, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants