n8n-io/n8n · error · InvalidLineNumberError

Invalid line number ${line}. File has ${maxLine} lines (vali

Error message

Invalid line number ${line}. File has ${maxLine} lines (valid range: 0-${maxLine}).

What it means

Error "Invalid line number ${line}. File has ${maxLine} lines (valid range: 0-${maxLine})." thrown in n8n-io/n8n.

Source

Thrown at packages/@n8n/ai-utilities/src/utils/text-editor.ts:339

			path,
			supportedPath,
			this.options.invalidPathMessage?.(path, supportedPath),
		);
	}

	private handleView(command: ViewCommand): string {
		if (this.text === null) {
			throw this.createFileNotFoundError();
		}

		const lines = this.text.split('\n');

		if (command.view_range) {
			const [start, rawEnd] = command.view_range;
			const end = rawEnd === -1 ? lines.length : rawEnd;

			if (start < 1 || start > lines.length) {
				throw new InvalidLineNumberError(start, lines.length);
			}
			if (end < start) {
				throw new InvalidViewRangeError(start, end, lines.length);
			}

			const startIndex = start - 1;
			const endIndex = Math.min(end, lines.length);
			const selectedLines = lines.slice(startIndex, endIndex);

			return selectedLines.map((line, i) => `${startIndex + i + 1}: ${line}`).join('\n');
		}

		return formatTextWithLineNumbers(this.text);
	}

	private handleCreate(command: CreateCommand): string {
		this.text = command.file_text;
		return 'File created successfully.';

View on GitHub (pinned to 5ac6606e81)

When it happens

Trigger: Thrown at packages/@n8n/ai-utilities/src/utils/text-editor.ts:339 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of n8n-io/n8n@5ac6606e81 (2026-08-12). Data as JSON: /api/errors/60bd566068e9b4f7. Report an issue: GitHub.