n8n-io/n8n · error · InvalidLineNumberError

Invalid line number . File has lines (valid range: 0- ).

Error message

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

What it means

Range-validation error (InvalidLineNumberError) from the text editor's handleView. It fires when a view command's view_range start line is below 1 or beyond the file's current line count. Pure bounds check on the requested window against the in-memory text.

Solutions

  1. Pass a view_range start line between 1 and the file's line count.
  2. Run a view without view_range first to see how many lines the file has.
  3. Remember lines are 1-indexed; use end = -1 to read to the end of the file.
Defensive patterns

Strategy: validation

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.

Appendix: 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)