{"record":{"id":"e31bfc05aa151826","repo":"Foundry376/Mailspring","slug":"geticon-only-works-on-linux","errorCode":null,"errorMessage":"getIcon only works on linux","messagePattern":"getIcon only works on linux","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"app/src/linux-theme-utils.ts","lineNumber":284,"sourceCode":"}\n\n/**\n * Return an icon from the current icon theme\n *\n * @param {string} iconName name of the icon you want to search for (i.e. mailspring)\n * @param {number} [size=22] size of the icon, if no exact size is found, the next possible one will be chosen\n * @param {array|string} [context=Context.APPLICATIONS] icon context to search in, defaults to APPLICATIONS\n * @param {number} [scale=2] icon scale, defaults to HiDPI version\n * @returns {string} path to the icon\n */\nfunction getIcon(\n  iconName,\n  size = 22,\n  context: string | string[] = [Context.APPLICATIONS],\n  scale: 1 | 2 = 2\n) {\n  if (process.platform !== 'linux') {\n    throw Error('getIcon only works on linux');\n  }\n\n  return getIconPath(iconName, size, context, scale);\n}\n\n/**\n * Convert any icon to a png using ImageMagick. If ImageMagick is not present the icon cannot be\n * converted.\n *\n * @param {string} iconName to name the tmp file\n * @param {string} iconPath to the original icon to be converted\n * @returns {string} path to the converted tmp file\n */\nfunction convertToPNG(iconName: string, iconPath: string) {\n  try {\n    const version = execSync('convert --version').toString().trim();\n    if (!version) {\n      console.warn('Cannot find ImageMagick');","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/Foundry376/Mailspring/blob/648c685d602ece6bb00c22534b8734de6ac644b3/app/src/linux-theme-utils.ts#L266-L302","documentation":"getIcon in linux-theme-utils.ts resolves an icon via the freedesktop icon theme specification (gtk icon lookup), which only exists on Linux. The function explicitly throws this Error when process.platform !== 'linux' to fail fast instead of calling getIconPath with no backing icon infrastructure.","triggerScenarios":"Calling LinuxThemeUtils.getIcon(iconName, ...) on Windows or macOS, or in unit tests / Electron renderer code paths that run on non-Linux CI agents, or shared code that invokes getIcon unconditionally regardless of platform.","commonSituations":"Cross-platform Mailspring plugins/themes calling getIcon to fetch a themed app icon; tests running on macOS/Windows CI where the linux-only code path is hit; dev machines not running Linux executing packaged mail Rules or theme code that assumed a freedesktop icon theme.","solutions":["Only call getIcon behind a process.platform === 'linux' check (or use a non-linux fallback icon source)","Wrap the call in try/catch and use a default icon when running off-Linux","For cross-platform icon lookup, resolve icons via Node/Electron APIs (e.g. app.getFileIcon on Windows/macOS) instead","Fix test setup so linux-only icon tests are skipped on non-Linux platforms (describe.skipIf / process.platform guard)"],"exampleFix":"// before\nconst icon = LinuxThemeUtils.getIcon('mail-notification', 22);\n// after\nconst icon = process.platform === 'linux'\n  ? LinuxThemeUtils.getIcon('mail-notification', 22)\n  : getDefaultIconFallback();","handlingStrategy":"try-catch","validationCode":"if (process.platform === 'linux') { /* safe to call getIcon */ }","typeGuard":"function canUseLinuxIcons(): boolean {\n  return process.platform === 'linux';\n}","tryCatchPattern":"let iconPath: string | null = null;\ntry {\n  iconPath = LinuxThemeUtils.getIcon(iconName, 22);\n} catch (err) {\n  if (err.message === 'getIcon only works on linux') {\n    iconPath = useFallbackIcon(iconName);\n  } else {\n    throw err;\n  }\n}","preventionTips":["Check process.platform before touching any LinuxThemeUtils API","Gate linux-only features in plugin/window code with platform checks at startup","Run platform-specific unit tests only on matching CI runners","Provide a documented non-linux fallback for icon resolution in shared components"],"tags":["linux","platform-specific","icon-theme","electron"],"backgroundTag":"platform-unsupported-api-call","analyzedSha":"648c685d602ece6bb00c22534b8734de6ac644b3","analyzedAt":"2026-09-03T02:00:24.311Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T07:17:11.731Z"}