FP on S4123 "await" should only be used with promises

SonarLint 6.0.0.37696 returns “await” should only be used with promises (
javascript:S4123) for the case when I add await for a call of an async function for the following code:

const result = await _handleQueryException(targetItem.queryName, err.message);

SonarLint claims:

It is possible to use await on values which are not Promises, but it’s useless and misleading. The point of await is to pause execution until the Promise’s asynchronous code has run to completion. With anything other than a Promise, there’s nothing to wait for.
This rule raises an issue when an awaited value is guaranteed not to be a Promise.

At the same time, on MDN I can find:

Async functions always return a promise. If the return value of an async function is not explicitly a promise, it will be implicitly wrapped in a promise.

Since _handleQueryException() is an async funtion:

const _handleQueryException = async function _handleQueryException(queryName, messageError) {…}

then I assume, that the MDN statement is valid here, while SonarLint raises a false-positive.

Please, check this case.

P.S. It’s my first report here, so please, let me know if something could be improved. BTW, should I post reports here or on Issues · SonarSource/SonarJS · GitHub ?

Hi,

Do you have tsconfig files in your project?

Hi,
no, I don’t have tsconfig files in my project.

And do you use connected mode of SonarLint? If yes, which version of SonarQube are you using?

Also could you post verbose logs of analysis in SonarLint?

Thank you!

And do you use connected mode of SonarLint?

I don’t know what is the connected mode of SonarLint. I’ve just activated SonarLint (standalone) in IDEA and scanned the project.

If yes, which version of SonarQube are you using?

This problem is reproducible with the latest version SonarQube Community (9.1) as well.

Also could you post verbose logs of analysis in SonarLint?

I’ll try to gather them.

@pubmikeb thanks for quick responses!
This problem is reported by several users already but I fail to reproduce it, seems like some context matters here.

Could you provide a precise full reproducer?

Also you can try updating the SonarLint. Theoretically in the latest version we should not report for this rule in SonarLint context.

we should not report for this rule in SonarLint context

Right. I’ve tested on 6.1.0.38326, now no such warning anymore.

And in SonarQube? If you have FP there, it would be great if you provide full reproducer.

I had this issue on SonarQube 9.1, released on September 2021, since that time SonarQube has not been updated, so I believe, FP on S4123 still occurs on SonarQube 9.1

Unfortunately I can’t help here without the reproducer

I’ve completely reinstalled SonarQube 9.1, ran the scan and of course I got this FP, since no change in SonarQube 9.1 has been performed since 9th Oct.

Should I gather logs? If yes, how can I do it?

Hi,

I don’t think logs will help me a lot in this situation.

To create a reproducer you can check this doc How to create a Minimal, Reproducible Example - Help Center - Stack Overflow. I need a self-contained project (with dependencies, configurations), which produces this FP.