Shields: logos: TypeError: Cannot read property '1' of null

Created on 14 Sep 2019  路  4Comments  路  Source: badges/shields

Sentry Issue: SHIELDS-42

TypeError: Cannot read property '1' of null
  File "/home/m/shields/lib/logos.js", line 79, in hexToRgb
    r: parseInt(result[1], 16),
  File "/home/m/shields/lib/logos.js", line 87, in getSimpleIconStyle
    if (style !== 'social' && brightness(hexToRgb(hex)) <= 0.4) {
  File "/home/m/shields/lib/logos.js", line 109, in getSimpleIcon
    const iconStyle = getSimpleIconStyle({ icon: simpleIcons[key], style })
  File "/home/m/shields/lib/logos.js", line 126, in prepareNamedLogo
    getShieldsIcon({ name, color }) || getSimpleIcon({ name, color, style })
  File "/home/m/shields/core/base-service/coalesce-badge.js", line 139, in coalesceBadge
    logoSvgBase64 = prepareNamedLogo({
...
(3 additional frame(s) were not displayed)
bug core

All 4 comments

My findings:
https://github.com/badges/shields/blob/a66e4f9e10c6ac9cea4dc1597cb44d01089b279a/lib/logos.js#L74-L83
in hexToRgb function hex value had to be undefined, null or a string value which didn't mach to hexColorRegex. And I don't know how it could happen. Every simple-icon has a hex property.

@paulmelnikow I don't have an access to Sentry. Can you check how often this issue happens, when was the first time and the last time when it happened?

It seems there are a few different signatures for this error. This particular one occurred once on Sep 11, the one linked from #4262 SHIELDS-4D happened twice on Oct 15, the one from #4263 SHIELDS-4E, also twice on Oct 15.

In other words, not super often.

Kind of an extreme case, though I can reproduce this issue with getSimpleIcon({ name: 'get' }) 馃

I wonder if there are any other keys that will pass x in simpleIcons besides the real icon names.

Great find! Maybe get is the only problematic key.

'use strict'

const simpleIcons = require('./lib/load-simple-icons')()

console.log(
  Object.getOwnPropertyNames(simpleIcons).filter(
    property => !simpleIcons[property].hex
  )
)

prints: [ 'get' ]

I think we can try to fix:
https://github.com/badges/shields/blob/a66e4f9e10c6ac9cea4dc1597cb44d01089b279a/lib/logos.js#L99-L101
with:

  if (!(simpleIcons[key] && simpleIcons[key].hex)) {
    return undefined
  }

Maybe that's the only one! Thanks for looking into that!

We probably should switch over to using .slug at some point, so maybe it's better to exclude get during the pre-processing that's done at load time in load-simple-icons?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

un1versal picture un1versal  路  25Comments

paulmelnikow picture paulmelnikow  路  30Comments

tooomm picture tooomm  路  32Comments

mfix22 picture mfix22  路  28Comments

bsdlp picture bsdlp  路  25Comments