earendil-works/pi · error · CborError

CBOR text strings must contain valid Unicode scalar values

Error message

CBOR text strings must contain valid Unicode scalar values

What it means

Error "CBOR text strings must contain valid Unicode scalar values" thrown in earendil-works/pi.

Source

Thrown at packages/protocol/src/cbor/encoder.ts:114

	} else {
		writer.writeByte(prefix | 27);
		writer.writeUint64(value);
	}
}

function isPlainObject(value: unknown): value is Record<string, unknown> {
	if (typeof value !== "object" || value === null) return false;
	const prototype = Object.getPrototypeOf(value);
	return prototype === Object.prototype || prototype === null;
}

function encodeText(writer: CborWriter, value: string, options: ResolvedCborOptions): void {
	const bytes = textEncoder.encode(value);
	if (bytes.byteLength > options.maxByteLength) {
		throw new CborError(`CBOR text string length exceeds configured limit of ${options.maxByteLength}`);
	}
	if (textDecoder.decode(bytes) !== value)
		throw new CborError("CBOR text strings must contain valid Unicode scalar values");
	writeArgument(writer, 3, bytes.byteLength);
	writer.writeBytes(bytes);
}

function encodeValue(
	writer: CborWriter,
	value: unknown,
	options: ResolvedCborOptions,
	depth: number,
	ancestors: Set<object>,
): void {
	if (depth > options.maxDepth)
		throw new CborError(`CBOR nesting depth exceeds configured limit of ${options.maxDepth}`);

	if (value === null) {
		writer.writeByte(0xf6);
		return;
	}

View on GitHub (pinned to 4af9d21d3b)

Solutions

  1. Remove lone surrogates and invalid Unicode scalar values from the string before encoding.

When it happens

Trigger: Thrown at packages/protocol/src/cbor/encoder.ts:114 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of earendil-works/pi@4af9d21d3b (2026-08-24). Data as JSON: /api/errors/fe8318db95a03d3e. Report an issue: GitHub.