-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
perf: Proposal for Improved Error Handling while token might be undefined #12914
Comments
I don't think that stating 'undefined' would help those errors are likely due to circular imports (as clarified here). I believe that a better approach would be rewording the error message or just improve the docs (the FAQ page) |
Thank you for your insightful response. Your explanation about potential circular imports is enlightening. I agree that rewording the error message or enhancing the FAQ documentation could be beneficial. To further this idea, I suggest to use this descriptive error: if(!type) throw new Error(`Token is undefined. This often occurs due to circular dependencies.
Ensure there are no circular dependencies in your files or barrel files.
For more details, refer to https://trilon.io/blog/avoiding-circular-dependencies-in-nestjs.`); This could potentially make the error more clear for developer. |
Would you like to create a PR for this issue? |
Kamil, I'm truly honored by your response and the opportunity to contribute to Nest.js. Your work and dedication to this framework have been a great inspiration to me. YES, I am excited to take on this task! I'll approach this pull request with great passion and care, aiming to make a valuable contribution to the community. Looking forward to working on this! |
This broke some libraries.
@Injectable()
export class EventService {
constructor(
@Inject('EVENT_SERVICE') private client: ClientProxy,
private eventEmitter2: EventEmitter2,
@Optional() @Inject() private logger: Logger = new Logger(EventService.name),
) {
}
let EventService = EventService_1 = class EventService {
constructor(client, eventEmitter2, logger = new common_1.Logger(EventService_1.name)) {
this.client = client;
this.eventEmitter2 = eventEmitter2;
this.logger = logger;
}
// ....
exports.EventService = EventService = EventService_1 = tslib_1.__decorate([
(0, common_1.Injectable)(),
tslib_1.__param(0, (0, common_1.Inject)('EVENT_SERVICE')),
tslib_1.__param(2, (0, common_1.Optional)()),
tslib_1.__param(2, (0, common_1.Inject)()),
tslib_1.__metadata("design:paramtypes", [microservices_1.ClientProxy,
event_emitter_1.EventEmitter2,
common_1.Logger])
], EventService); Stacktrace:
From the stack trace the error appears at the |
This also breaks |
Reverted #13370 |
Published as v10.3.7 |
Is there an existing issue that is already proposing this?
NestJS version
10.2.7
Is your performance suggestion related to a problem? Please describe it
We encountered a problem in our barrel file where a constant was undefined. After some effort, we identified and resolved the issue. However, I believe enhancing the injector to raise an error would significantly aid developers in understanding such issues more efficiently.
Describe the performance enhancement you are proposing and how we can try it out
The enhancement I propose is not directly code-related but pertains to debugging efficiency. If an error were thrown when a token is undefined, it would expedite problem-solving. Here is a suggested implementation:
reference file
Benchmarks result or another proof (eg: POC)
As previously mentioned, this enhancement can significantly reduce debugging time. While I do not have specific benchmarks, the time saved during the debugging process serves as practical proof of its effectiveness.
The text was updated successfully, but these errors were encountered: