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

Fastify's _patchConstructor causing errorCodes to be inaccessible #2027

Closed
paskahlisanjas opened this issue Mar 20, 2024 · 0 comments · Fixed by #2633
Closed

Fastify's _patchConstructor causing errorCodes to be inaccessible #2027

paskahlisanjas opened this issue Mar 20, 2024 · 0 comments · Fixed by #2633

Comments

@paskahlisanjas
Copy link

private _patchConstructor(moduleExports: {
fastify: () => FastifyInstance;
}): () => FastifyInstance {
const instrumentation = this;
this._diag.debug('Patching fastify constructor function');
function fastify(this: FastifyInstance, ...args: any) {
const app: FastifyInstance = moduleExports.fastify.apply(this, args);
app.addHook('onRequest', instrumentation._hookOnRequest());
app.addHook('preHandler', instrumentation._hookPreHandler());
instrumentation._wrap(app, 'addHook', instrumentation._wrapAddHook());
return app;
}
fastify.fastify = fastify;
fastify.default = fastify;
return fastify;
}

This overrides the originally exported fastify while it should contain errorCodes as assigned here. This breaks whenever I try to do this:

import { errorCodes } from 'fastify';

The errorCodes is always undefined.

Is there any workaround for this?

tsmithhisler added a commit to tsmithhisler/opentelemetry-js-contrib that referenced this issue Jan 8, 2025
fastify v4.x+ exports an object named `errorCodes` as both a property of the default export and as a named export.

The export is documented at https://github.com/fastify/fastify/blob/4.x/docs/Reference/Errors.md?plain=1#L236.

This closes open-telemetry#2027.
tsmithhisler added a commit to tsmithhisler/opentelemetry-js-contrib that referenced this issue Jan 8, 2025
fastify v4.x+ exports an object named `errorCodes` as both a property of the default export and as a named export.

The export is documented at https://github.com/fastify/fastify/blob/4.x/docs/Reference/Errors.md?plain=1#L236.

This closes open-telemetry#2027.
tsmithhisler added a commit to tsmithhisler/opentelemetry-js-contrib that referenced this issue Jan 8, 2025
fastify v4.x+ exports an object named `errorCodes` as both a property of the default export and as a named export.

The export is documented at https://github.com/fastify/fastify/blob/4.x/docs/Reference/Errors.md?plain=1#L236.

This closes open-telemetry#2027.
tsmithhisler added a commit to tsmithhisler/opentelemetry-js-contrib that referenced this issue Jan 9, 2025
fastify v4.x+ exports an object named `errorCodes` as both a property of the default export and as a named export.

The export is documented at https://github.com/fastify/fastify/blob/4.x/docs/Reference/Errors.md?plain=1#L236.

This closes open-telemetry#2027.
tsmithhisler added a commit to tsmithhisler/opentelemetry-js-contrib that referenced this issue Jan 9, 2025
fastify v4.8+ exports an object named `errorCodes` as both a property of the default export and as a named export.

The export is documented at https://github.com/fastify/fastify/blob/4.x/docs/Reference/Errors.md?plain=1#L236.

This closes open-telemetry#2027.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant