schollz/croc · warning · Error
Custom codes must use printable ASCII characters
Error message
Custom codes must use printable ASCII characters
What it means
validateSecret requires the whole code to match /^[\x20-\x7e]+$/ (printable ASCII, space through tilde). Any non-ASCII letter, emoji, tab, or control character makes the test fail before the transfer starts. This mirrors croc's CLI restriction so the code maps cleanly onto the wire protocol.
Source
Thrown at web/src/protocol/client.ts:65
return new DOMException("Transfer cancelled", "AbortError");
}
function checkAbort(signal?: AbortSignal) {
if (signal?.aborted) throw abortError();
}
function requirePakeVersion(version: number | undefined) {
if (version !== PAKE_PROTOCOL_VERSION) {
throw new Error(
`Peer uses unsupported PAKE protocol version ${version ?? 0}; upgrade both croc clients`,
);
}
}
function validateSecret(secret: string) {
if (secret.length < 6) throw new Error("Code must be at least 6 characters");
if (!/^[\x20-\x7e]+$/.test(secret)) {
throw new Error("Custom codes must use printable ASCII characters");
}
}
function controlPort(relayAddress: string) {
try {
const parsed = new URL(
relayAddress.includes("://") ? relayAddress : `tcp://${relayAddress}`,
);
return parsed.port || CONTROL_PORT;
} catch {
return CONTROL_PORT;
}
}
function dataPorts(banner: string) {
const ports = banner
.split(",")
.map((port) => port.trim())View on GitHub (pinned to e25f1bdc04)
Solutions
- Strip or retype non-ASCII characters; use only printable ASCII in the code
- Normalize pasted input before validation: trim whitespace and remove zero-width characters
- Enforce the same pattern in the UI input field so the user gets immediate feedback
Example fix
// before
const secret = pastedText; // contains a zero-width space or accent
await sendFiles({ files, secret, settings });
// after
const secret = pastedText.replace(/[^\x20-\x7e]/g, "").trim();
if (secret.length >= 6) await sendFiles({ files, secret, settings }); Defensive patterns
Strategy: validation
Validate before calling
const PRINTABLE_ASCII = /^[\x20-\x7e]+$/;
function normalizeSecret(s) {
return s.replace(/[^\x20-\x7e]/g, "").trim();
}
const secret = normalizeSecret(raw);
if (!PRINTABLE_ASCII.test(secret)) throw new Error("Code must be printable ASCII"); Try / catch
try { await sendFiles(opts); } catch (e) {
if (/printable ASCII/.test(e.message)) { setCodeError("Use plain letters, numbers and symbols only"); return; }
throw e;
} Prevention
- Sanitize pasted codes (strip zero-width chars, smart quotes, newlines) before storing
- Show a live pattern indicator on the code input
- Beware IME autocorrect when users type codes on mobile
When it happens
Trigger: A code containing accented characters (e.g. 'café-code'), CJK text, emoji, or an embedded tab/newline pasted from a chat message; IME autocorrect altering an ASCII code.
Common situations: Copy-paste from messengers that insert zero-width characters or smart quotes; non-English keyboard layouts producing accents; trailing newline included in a pasted value.
Related errors
- Code must be at least 6 characters
- Choose at least one file
- Duplicate filename: ${outgoingName}
- Received a file chunk outside the advertised file size
- Received more data than the advertised file size
AI-assisted analysis of schollz/croc@e25f1bdc04 (2026-08-15).
Data as JSON: /api/errors/cdb7bfba09c2dbc0.
Report an issue: GitHub.