-
-
Notifications
You must be signed in to change notification settings - Fork 6
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: Cannot read properties of undefined (reading 'func') #98
Comments
You forgot to Lines 50 to 58 in 17fd926
|
Hell @matthyk , I have reviewed the documentation and observed your note for await, but it does not seem to be the source of the problem. Please examine the snippet of code below, which utilizes the await.
|
I don't get an error with the provided code snippet. Can you provide a minimal reproducible example? |
I don't define me as TS dev so I need something where I can just run these commands to replicate the error:
TBH If that item is undefined, it means that the Line 123 in 17fd926
So, I think the issue relies on how the function returns the source and it is definitely not tested in this setup. fastify-overview/lib/source-code.js Line 5 in 17fd926
|
I have created one test app so you can run and check the issue https://github.com/nasraldin/test-fastify-overview Here the line throws the issue Line 90 in 17fd926
|
I now had the time to take a closer look at the problem and I have found the cause. The cause of this error is the Lines 120 to 126 in c1785f8
The import Fastify from 'fastify'
import fastifyOverview from 'fastify-overview'
import plugin from './plugin.js'
const app = Fastify()
await app.register(fastifyOverview)
app.register(plugin) --> import Fastify from 'fastify'
import fastifyOverview from 'fastify-overview'
const app = Fastify()
await app.register(fastifyOverview)
app.register(import('./plugins.js')) --> import Fastify from 'fastify'
import fastifyOverview from 'fastify-overview'
const app = Fastify()
await app.register(fastifyOverview)
app.register(await import('./plugins.js')) --> So the problem is that the plugin function can also be a Promise or a Module Namespace Object. The Second point could be easily fixed with a simple check, like Avvio does with this function. If the plugin is a Promise we would have to await it before we continue, but I can't tell if we can just make the method async. See here for minimal reproducible example. |
It seems we have an actionable! Great analysis!
This is dangerous because we are no more watching the actual runtime status, but we are doing business logic. In this case I would just try to get all the info we can and check where we could store them since the pluginFn seems not an option |
While I was analysing the issue, I found another problem. If you run {
"id": 0.6509491979399917,
"name": "fastify -> fastify-overview",
"children": [
{
"id": 0.2302123930057709,
"name": "default",
"children": [],
"routes": [],
"decorators": {
"decorate": [
{
"name": "num",
"type": "number",
"source": {
"stackIndex": 0,
"fileName": "file:///Users/.../fastify-overview-issue-98/plugin.js",
"relativeFileName": "file:///plugin.js",
"lineNumber": 2,
"columnNumber": 9,
"functionName": "default",
"typeName": null,
"methodName": null
}
}
],
"decorateRequest": [],
"decorateReply": []
},
"hooks": {
"onRequest": [],
"preParsing": [],
"preValidation": [],
"preHandler": [],
"preSerialization": [],
"onError": [],
"onSend": [],
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
},
"source": {
"stackIndex": 0,
"fileName": "node:internal/process/task_queues",
"relativeFileName": "node:internal/process/task_queues",
"lineNumber": 82,
"columnNumber": 21,
"functionName": "processTicksAndRejections",
"typeName": "process",
"methodName": null
}
}
],
"routes": [],
"decorators": {
"decorate": [],
"decorateRequest": [],
"decorateReply": []
},
"hooks": {
"onRequest": [],
"preParsing": [],
"preValidation": [],
"preHandler": [],
"preSerialization": [],
"onError": [],
"onSend": [],
"onResponse": [],
"onTimeout": [],
"onRequestAbort": [],
"onListen": [],
"onReady": [],
"preClose": [],
"onClose": [],
"onRoute": [],
"onRegister": []
}
} While the source object of the |
Maybe we need to improve this filter: fastify-overview/lib/source-code.js Lines 15 to 18 in c1785f8
|
If [
"/Users/.../fastify-overview-issue-98/node_modules/fastify-overview/index.js",
"/Users/.../fastify-overview-issue-98/node_modules/fastify/lib/pluginOverride.js",
"/Users/.../fastify-overview-issue-98/node_modules/avvio/boot.js",
"node:internal/process/task_queues"
] The array therefore does not contain the correct value at all. |
I can no longer reproduce this output. it seems that I had some strange side effects 😄 |
@Eomm I have opened #105 to discuss a possible solution. But if you look at the failed tests, you can also see another problem. As soon as you use ECMAScript modules, you no longer get the correct |
Thanks for taking care of this issue. TBH I would check how APMs do it |
I've been looking for a solution for some time now, but haven't found one yet. But maybe we should solve the problem with the sources separately from the issues with the registration of ECMAScript modules, since the two things have nothing to do with each other. |
I did not understand: are you suggesting to add a condition to avoid the crash? |
Current situation: The plugin crashes if a Module Namespace Object or a Promise is registered My suggestion:
|
Hello team,
Please apply the fix to avoid the below issue that throw when using with typescript.
Current ver.
To reproduce the issue:
add the plugin
pnpm add fastify-overview
run your app
result
application stoped to start and throw below error
The fix:
I'm just checking in the compiled source code in node modules of your lib to fix but for you you need to fix the root cause in js that fun related to show source
In the manInTheMiddle function, update the check to ensure that _current has a value before assigning it to the source.
old fun is
new code
Thank you for creating such an amazing tool!
The text was updated successfully, but these errors were encountered: