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

Possible code problem detected by linter #38

Open
VinGarcia opened this issue Dec 20, 2022 · 0 comments
Open

Possible code problem detected by linter #38

VinGarcia opened this issue Dec 20, 2022 · 0 comments

Comments

@VinGarcia
Copy link

VinGarcia commented Dec 20, 2022

Hello, good morning.

I forked your repository for using at my company and I was requested to make some adaptations on it before using, and while on it the linter complained about one problem that actually seems important on the following lines of code:

https://github.com/ssut/nestjs-sqs/blob/master/lib/sqs.service.ts#L39-L53

     if (!metadata) {
        this.logger.warn(`No metadata found for: ${name}`);
      }

      const isBatchHandler = metadata.meta.batch === true;
      const consumer = Consumer.create({
        ...consumerOptions,
        ...(isBatchHandler
          ? {
              handleMessageBatch: metadata.discoveredMethod.handler.bind(
                metadata.discoveredMethod.parentClass.instance,
              ),
            }
          : { handleMessage: metadata.discoveredMethod.handler.bind(metadata.discoveredMethod.parentClass.instance) }),
      });

Here the code checks whether the metadata is present or not, but if it is undefined it will just continue running. And I don't think this is likely to work because we even make function calls on the subattributes like in:

metadata.discoveredMethod.handler.bind(
  metadata.discoveredMethod.parentClass.instance,
)

so even if I replaced all . with .? it would still break on that line.

I was wondering whether we might need to skip the iteration if we detect that the metadata is nil instead of just logging a warning.

@VinGarcia VinGarcia changed the title Small code problem detected by linter Possible code problem detected by linter Dec 20, 2022
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

No branches or pull requests

1 participant