deepseek-ai/deepseek-harness · error · Error
Invalid `insert_line` parameter
Error message
Invalid `insert_line` parameter: ${insertLine}. It should be within the range of lines of the file: [0, ${lines.length}] What it means
Range guard in insertInFile: insert_line is an integer but falls outside [0, lines.length] for the file's current content. The file was read to count lines before the guard fired; the insertLine input is at fault.
Solutions
- Choose a line number within the range shown in the message
- Re-view the file to confirm its current line count
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at packages/fs/tool-str-replace-editor/src/index.ts:345 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of deepseek-ai/deepseek-harness@b150a551b8 (2026-08-24).
Data as JSON: /api/errors/358a38aac4b4d993.
Report an issue: GitHub.
Appendix: source
Thrown at packages/fs/tool-str-replace-editor/src/index.ts:345
policy: MutationPolicy,
path: string,
insertLine: number | undefined,
newStr: string | undefined,
exec: ToolRunContext,
): Promise<string> {
if (insertLine === undefined) throw new Error('Parameter `insert_line` is required for command: insert')
const value = requiredForCommand(newStr, 'new_str', 'insert')
const sandboxPolicy = policy.resolve(exec)
const target = await resolveTarget(ctx, path, exec.signal)
const intent = await ctx.waterfall('fs/edit-intent', target, exec, () => undefined)
const info = await statExisting(ctx, target, 'insert', exec)
if (info.type !== 'file') {
throw new FsError(`cannot insert into "${target.displayPath}": not a regular file`, 'FS_NOT_REGULAR_FILE')
}
const before = await ctx.fs.readText(target, exec.signal)
const lines = before.split('\n')
if (!Number.isInteger(insertLine) || insertLine < 0 || insertLine > lines.length) {
throw new Error(
`Invalid \`insert_line\` parameter: ${insertLine}. It should be within the range of lines of the file: [0, ${lines.length}]`,
)
}
const after = [
...lines.slice(0, insertLine),
...value.split('\n'),
...lines.slice(insertLine),
].join('\n')
const expected: FsWriteIntent = intent === undefined
? { kind: 'replaceIfVersion', version: info.version }
: { kind: 'replaceIfVersion', version: intent.version }
let outcome
try {
outcome = await ctx.fs.writeText(target, after, expected, exec.signal, sandboxPolicy)
} catch (error: unknown) {
throw policy.mapError(error, sandboxPolicy)
}
ctx.emit('fs/observed', target, { kind: 'present', version: outcome.version }, exec)View on GitHub (pinned to b150a551b8)