Foundry376/Mailspring · error · Error

getIcon only works on linux

Error message

getIcon only works on linux

What it means

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.

Source

Thrown at app/src/linux-theme-utils.ts:284

}

/**
 * Return an icon from the current icon theme
 *
 * @param {string} iconName name of the icon you want to search for (i.e. mailspring)
 * @param {number} [size=22] size of the icon, if no exact size is found, the next possible one will be chosen
 * @param {array|string} [context=Context.APPLICATIONS] icon context to search in, defaults to APPLICATIONS
 * @param {number} [scale=2] icon scale, defaults to HiDPI version
 * @returns {string} path to the icon
 */
function getIcon(
  iconName,
  size = 22,
  context: string | string[] = [Context.APPLICATIONS],
  scale: 1 | 2 = 2
) {
  if (process.platform !== 'linux') {
    throw Error('getIcon only works on linux');
  }

  return getIconPath(iconName, size, context, scale);
}

/**
 * Convert any icon to a png using ImageMagick. If ImageMagick is not present the icon cannot be
 * converted.
 *
 * @param {string} iconName to name the tmp file
 * @param {string} iconPath to the original icon to be converted
 * @returns {string} path to the converted tmp file
 */
function convertToPNG(iconName: string, iconPath: string) {
  try {
    const version = execSync('convert --version').toString().trim();
    if (!version) {
      console.warn('Cannot find ImageMagick');

View on GitHub (pinned to 648c685d60)

Solutions

  1. Only call getIcon behind a process.platform === 'linux' check (or use a non-linux fallback icon source)
  2. Wrap the call in try/catch and use a default icon when running off-Linux
  3. For cross-platform icon lookup, resolve icons via Node/Electron APIs (e.g. app.getFileIcon on Windows/macOS) instead
  4. Fix test setup so linux-only icon tests are skipped on non-Linux platforms (describe.skipIf / process.platform guard)

Example fix

// before
const icon = LinuxThemeUtils.getIcon('mail-notification', 22);
// after
const icon = process.platform === 'linux'
  ? LinuxThemeUtils.getIcon('mail-notification', 22)
  : getDefaultIconFallback();
Defensive patterns

Strategy: try-catch

Validate before calling

if (process.platform === 'linux') { /* safe to call getIcon */ }

Type guard

function canUseLinuxIcons(): boolean {
  return process.platform === 'linux';
}

Try / catch

let iconPath: string | null = null;
try {
  iconPath = LinuxThemeUtils.getIcon(iconName, 22);
} catch (err) {
  if (err.message === 'getIcon only works on linux') {
    iconPath = useFallbackIcon(iconName);
  } else {
    throw err;
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.


AI-assisted analysis of Foundry376/Mailspring@648c685d60 (2026-09-03). Data as JSON: /api/errors/e31bfc05aa151826. Report an issue: GitHub.