toeverything/AFFiNE · error

Invalid ${label}

Error message

Invalid ${label}

What it means

assertPathComponent rejects empty values, dot segments, path separators, and control characters, throwing 'Invalid <label>' so a single unsanitized path component cannot inject directory traversal into paths.

Source

Thrown at packages/frontend/apps/electron/src/shared/utils.ts:140

  return resolvedTarget;
}

export function assertPathComponent(
  value: string,
  label: string = 'path component'
) {
  const hasControlChar = Array.from(value).some(
    character => character.charCodeAt(0) < 0x20
  );

  if (
    !value ||
    value === '.' ||
    value === '..' ||
    /[/\\]/.test(value) ||
    hasControlChar
  ) {
    throw new Error(`Invalid ${label}`);
  }

  return value;
}

export function normalizeWorkspaceIdForPath(
  value: string,
  options: { windows?: boolean; label?: string } = {}
) {
  const { windows = isWindows(), label = 'workspace id' } = options;
  const safeValue = assertPathComponent(value, label);

  if (!windows) {
    return safeValue;
  }

  const windowsReservedChars = new Set(['<', '>', ':', '"', '|', '?', '*']);
  let normalized = '';

View on GitHub (pinned to b4c8548c09)

Solutions

  1. Pass a valid value for the labeled field named in the error.
  2. Check the IPC payload from the renderer for missing or wrong-typed values.
  3. Validate the input on the caller side before invoking the Electron API.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/frontend/apps/electron/src/shared/utils.ts:140 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of toeverything/AFFiNE@b4c8548c09 (2026-08-18). Data as JSON: /api/errors/f262f6330c7f2ef0. Report an issue: GitHub.