n8n-io/n8n · error · InvalidViewRangeError

Invalid view range: end

Error message

Invalid view range: end (${end}) must be >= start (${start}). File has ${maxLine} lines (valid range: 1-${maxLine}).

What it means

Range-validation error (InvalidViewRangeError) from the text editor's handleView. It fires when view_range's end line is less than its start line — an inverted or empty window. Start passed its own bounds check; the pair is inconsistent.

Solutions

  1. Make the view_range end line greater than or equal to the start line.
  2. Use -1 as the end to view through the last line of the file.
  3. Re-check the intended range; start and end may have been swapped.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/@n8n/ai-utilities/src/utils/text-editor.ts:342 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/fd6f335118c77888. Report an issue: GitHub.

Appendix: source

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

		);
	}

	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.';
	}

	private handleStrReplace(command: StrReplaceCommand): string {

View on GitHub (pinned to 5ac6606e81)