Yeachan-Heo/oh-my-codex · error · Error

mode must be a non-empty string

Error message

mode must be a non-empty string

What it means

Thrown when the mode string is empty after trimming. Since mode becomes part of a state filename, an empty segment would produce a malformed filename and is rejected.

Source

Thrown at src/mcp/state-paths.ts:136

export function validateSessionId(sessionId: unknown): string | undefined {
  if (sessionId == null) return undefined;
  if (typeof sessionId !== 'string') {
    throw new Error('session_id must be a string');
  }
  if (!SESSION_ID_PATTERN.test(sessionId)) {
    throw new Error('session_id must match ^[A-Za-z0-9_-]{1,64}$');
  }
  return sessionId;
}


export function validateStateModeSegment(mode: unknown): string {
  if (typeof mode !== 'string') {
    throw new Error('mode must be a string');
  }
  const normalized = mode.trim();
  if (!normalized) {
    throw new Error('mode must be a non-empty string');
  }
  if (normalized.includes('..')) {
    throw new Error('mode must not contain ".."');
  }
  if (normalized.includes('/') || normalized.includes('\\')) {
    throw new Error('mode must not contain path separators');
  }
  if (!STATE_MODE_SEGMENT_PATTERN.test(normalized)) {
    throw new Error('mode must match ^[A-Za-z0-9_-]{1,64}$');
  }
  return normalized;
}

export function getStateFilename(mode: string): string {
  return `${validateStateModeSegment(mode)}${STATE_FILE_SUFFIX}`;
}

export function validateStateFileName(fileName: unknown): string {

View on GitHub (pinned to 3ad79a8a6f)

Solutions

  1. Pass a meaningful mode like "team" or "default"
  2. Treat empty as absent: use (mode || "default") when building the call
  3. Trim and validate config values at load time

Example fix

// before
getStateFilename("   ");
// after
getStateFilename("default");
Defensive patterns

Strategy: validation

Validate before calling

mode = (mode ?? '').toString().trim() || 'default';

Type guard

function isNonEmptyMode(v: string): boolean { return v.trim().length > 0; }

Prevention

When it happens

Trigger: mode: "", mode: " ", or mode: "\t" — anything that trims to zero length.

Common situations: Optional mode field left as empty string instead of undefined; form input submitted blank; whitespace from templated config values.

Related errors


AI-assisted analysis of Yeachan-Heo/oh-my-codex@3ad79a8a6f (2026-08-27). Data as JSON: /api/errors/1259299e67eee07b. Report an issue: GitHub.