ruvnet/RuView · error · Error
brain line ${index + 1}: ${error.message}
Error message
brain line ${index + 1}: ${error.message} What it means
Every non-empty line of the brain corpus must parse via JSON.parse; the underlying parse error message is included alongside the 1-based line number. Empty lines are skipped (filter(Boolean)), but whitespace-only lines are not filtered and also fail parsing.
Source
Thrown at harness/ruview/src/brain.js:49
errors.push('source.path must be repository-relative without traversal');
}
if (!Array.isArray(record.tags) || record.tags.some((tag) => typeof tag !== 'string')) errors.push('tags must be strings');
if ((record.content || '').length > 8192) errors.push('content exceeds 8192 characters');
if ((record.title || '').length > 200) errors.push('title exceeds 200 characters');
if (canonical && record.reviewed !== true) errors.push('canonical records must be reviewed');
const combined = `${record.title || ''}\n${record.content || ''}`;
if (SECRET.test(combined)) errors.push('record appears to contain a secret');
if (INJECTION.test(combined)) errors.push('record contains instruction-like prompt injection');
return errors;
}
export function loadBrain(path = CORPUS_PATH) {
const raw = readFileSync(path, 'utf8').replace(/\r\n/g, '\n');
if (Buffer.byteLength(raw) > 1_048_576) throw new Error('brain corpus exceeds 1 MiB');
const records = raw.split('\n').filter(Boolean).map((line, index) => {
if (Buffer.byteLength(line) > 16_384) throw new Error(`brain line ${index + 1}: exceeds 16 KiB`);
let record;
try { record = JSON.parse(line); } catch (error) { throw new Error(`brain line ${index + 1}: ${error.message}`); }
const errors = validateBrainRecord(record, { canonical: true });
if (errors.length) throw new Error(`brain line ${index + 1}: ${errors.join('; ')}`);
return Object.freeze(record);
});
if (records.length > 1000) throw new Error('brain corpus exceeds 1000 records');
const ids = new Set();
for (const record of records) {
if (ids.has(record.id)) throw new Error(`duplicate brain id: ${record.id}`);
ids.add(record.id);
}
return { records, digest: sha256(raw), bytes: Buffer.byteLength(raw) };
}
function terms(value) {
return new Set(String(value).toLowerCase().match(/[a-z0-9][a-z0-9_-]{1,}/g) || []);
}
export function searchBrain(query, { limit = 8, path = CORPUS_PATH } = {}) {View on GitHub (pinned to 4685618388)
Solutions
- Read the line number and parser reason in the message and fix that exact line
- Remove whitespace-only lines and any BOM
- Generate records with 'brain propose' or jq -c instead of editing by hand
Example fix
// before (line 7)
{"id": "lesson", }
// after
{"id": "lesson"} Defensive patterns
Strategy: validation
Validate before calling
import { readFileSync } from 'node:fs';
function invalidJsonLines(path) {
const bad = [];
readFileSync(path, 'utf8').split('\n').forEach((line, i) => {
if (!line.trim()) return;
try { JSON.parse(line); } catch { bad.push(i + 1); }
});
return bad;
} Try / catch
try {
const brain = loadBrain(path);
} catch (error) {
if (error.message.startsWith('brain line')) {
console.error(`corpus parse failure: ${error.message}`);
process.exit(1);
}
throw error;
} Prevention
- Write records programmatically (jq -c or brain propose), never by hand in a formatting editor
- Strip whitespace-only lines and BOMs when editing the corpus
- Run a per-line JSON.parse lint in CI before loadBrain ever executes
When it happens
Trigger: Hand-edited JSONL with trailing commas, single or smart quotes, an object split across two lines, a whitespace-only line, or a UTF-8 BOM at the start of the file.
Common situations: Editor auto-formatting that rewraps JSON, merge conflicts inside the corpus, copy-paste from rendered documentation.
Related errors
- brain line ${index + 1}: exceeds 16 KiB
- brain line ${index + 1}: ${errors.join('; ')}
- duplicate brain id: ${record.id}
- brain corpus exceeds 1 MiB
- brain corpus exceeds 1000 records
AI-assisted analysis of ruvnet/RuView@4685618388 (2026-08-16).
Data as JSON: /api/errors/660fab07e2dcf424.
Report an issue: GitHub.