ruvnet/RuView · error · TypeError

prompt must be a non-empty string

Error message

prompt must be a non-empty string

What it means

runClaudeCode (harness/ruview/src/hosts/claude-code.js) is the host adapter that spawns `claude -p` for delegated analysis. It destructures { prompt, ... } and immediately requires a string with non-whitespace content; empty, null, numeric, or undefined prompts throw before the repo-trust check or process spawn.

Source

Thrown at harness/ruview/src/hosts/claude-code.js:12

// SPDX-License-Identifier: MIT
import { runProcess } from '../process-runner.js';
import { assertTrustedRuViewRepo } from '../repo-trust.js';
export function buildClaudeCodeArgs({ write = false } = {}) {
  return ['-p', '--safe-mode', '--output-format', 'json', '--no-session-persistence', '--permission-mode', write ? 'acceptEdits' : 'plan',
    '--allowedTools', write ? 'Read,Grep,Glob,Edit,Write' : 'Read,Grep,Glob'];
}
export async function runClaudeCode({
  prompt, repoRoot, trustedRoot = repoRoot, allowWrite = false, confirm = false,
  command = 'claude', commandArgs = [], ...runOptions
}) {
  if (typeof prompt !== 'string' || !prompt.trim()) throw new TypeError('prompt must be a non-empty string');
  const root = assertTrustedRuViewRepo(repoRoot, { trustedRoot });
  const write = allowWrite === true && confirm === true;
  return runProcess(command, [...commandArgs, ...buildClaudeCodeArgs({ write })], { ...runOptions, cwd: root, input: prompt });
}
export default Object.freeze({ name: 'claude-code', run: runClaudeCode, buildArgs: buildClaudeCodeArgs });

View on GitHub (pinned to 4685618388)

Solutions

  1. Build and check the prompt first: const prompt = buildPrompt(args).trim(); if (!prompt) fail with your own clearer error.
  2. Pass a concrete string: runClaudeCode({ prompt: 'Find the nearest tests and cite files', repoRoot }).
  3. Log the prompt when delegation fails so empty-template bugs are visible.

Example fix

// before
runClaudeCode({ prompt: buildPrompt(ctx), repoRoot }) // buildPrompt returned ''
// after
const prompt = buildPrompt(ctx).trim();
if (!prompt) throw new Error('empty prompt: provide a task for the claude-code host');
runClaudeCode({ prompt, repoRoot });
Defensive patterns

Strategy: validation

Validate before calling

const prompt = typeof rawPrompt === 'string' ? rawPrompt.trim() : '';
if (!prompt) throw new Error('claude-code host requires a non-empty prompt');
runClaudeCode({ prompt, repoRoot });

Type guard

function isNonEmptyPrompt(v) {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  await runClaudeCode({ prompt, repoRoot });
} catch (e) {
  if (e instanceof TypeError && e.message === 'prompt must be a non-empty string') {
    // your prompt builder produced nothing; fix the builder, do not retry blindly
    throw new Error('prompt construction failed: task description was empty');
  }
  throw e;
}

Prevention

When it happens

Trigger: runClaudeCode({}) (prompt undefined), runClaudeCode({ prompt: '' }), runClaudeCode({ prompt: ' ' }) (whitespace-only fails .trim()), prompt built from a template that yields '' when a variable is missing.

Common situations: Piping an empty stdin/file into the prompt builder; conditionally concatenating prompt parts where every branch was skipped; passing a prompt object { text } instead of the string.

Related errors


AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16). Data as JSON: /api/errors/6a24c5755d6a10a5. Report an issue: GitHub.