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

questions must be a non-empty array

Error message

questions must be a non-empty array

What it means

After normalization the questions list must contain at least one question. Thrown when the input provides an explicit questions array that is empty (a legacy single-question object always yields one entry, so this only fires for explicit empty arrays).

Source

Thrown at src/question/types.ts:198

  return normalizeQuestionItem({ ...raw, id: safeString(raw.id).trim() || 'q-1', header }, 0, header);
}

export function normalizeQuestionInput(raw: unknown): QuestionInput {
  if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
    throw new Error('question input must be a JSON object');
  }

  const input = raw as Record<string, unknown>;
  const header = safeString(input.header).trim() || undefined;
  const source = safeString(input.source).trim() || undefined;
  const session_id = safeString(input.session_id).trim() || undefined;
  const rawQuestions = Array.isArray(input.questions) ? input.questions : undefined;

  const questions = rawQuestions
    ? rawQuestions.map((item, index) => normalizeQuestionItem(item, index, header))
    : [normalizeLegacyQuestion(input, header)];

  if (questions.length === 0) throw new Error('questions must be a non-empty array');
  const seenIds = new Set<string>();
  for (const question of questions) {
    if (seenIds.has(question.id)) throw new Error(`questions id must be unique: ${question.id}`);
    seenIds.add(question.id);
  }

  const first = questions[0]!;
  return {
    ...(header ? { header } : {}),
    question: first.question,
    options: first.options,
    allow_other: first.allow_other,
    other_label: first.other_label,
    multi_select: first.multi_select,
    type: first.type,
    questions,
    ...(source ? { source } : {}),
    ...(session_id ? { session_id } : {}),

View on GitHub (pinned to 3ad79a8a6f)

Solutions

  1. Ensure at least one question object is present in the questions array
  2. Guard upstream: skip calling the API when the filtered list is empty instead of passing an empty array

Example fix

// before
normalizeQuestionInput({ questions: [] });
// after
if (questions.length === 0) throw new Error('no questions to ask');
normalizeQuestionInput({ questions });
Defensive patterns

Strategy: validation

Validate before calling

if (Array.isArray(input.questions) && input.questions.length === 0) throw new Error('questions array is empty');

Type guard

const hasQuestions = (i: any) => !Array.isArray(i?.questions) || i.questions.length > 0;

Prevention

When it happens

Trigger: Calling normalizeQuestionInput with { questions: [] }.

Common situations: Programmatically filtering a questions array down to zero items before submission; template rendering that drops all questions conditionally.

Related errors


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