FP S4158: array created using await falsely considered empty

The following code generates the error: Review this usage of “deviceList” as it can only be empty here.

    let deviceList
    try {
      deviceList = await navigator.mediaDevices.enumerateDevices()
    } catch (error) {
      deviceList = []
      console.warn('devices access not allowed', error)
    const toDevice = device => ({
      deviceId: device.deviceId,
      label: device.label

    const devices = {
      audio: deviceList.filter(device => device.kind === 'audioinput').map(toDevice),
      video: deviceList.filter(device => device.kind === 'videoinput').map(toDevice),
      audiooutput: deviceList.filter(device => device.kind === 'audiooutput').map(toDevice)

deviceList may be empty, but not always.

1 Like

Hello Maxime,

Welcome to our community, and thank you for your message!

I am not able to reproduce the issue using the code example you provided.

Please could you tell us which version of SonarQube/SonarScanner/SonarJS you are using ?