Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
b6dddf934This file is pinned to the selected release. Download the original to open it in your design tool.
/// cli.ts `humanizeLinkError`: a password-link failure code as the sentence to show. Every branch,
/// the fallback included, wraps the code in words — a bare code must never reach the screen.
String humanizeLinkError(String code, String machineId, {DateTime? retryAt}) {
if (code == 'RATE_LIMITED') {
if (retryAt == null) {
return 'Too many wrong attempts on $machineId. Wait a few minutes and try again.';
}
final minutes = (retryAt.difference(DateTime.now()).inSeconds / 60).ceil();
return minutes > 0
? 'Too many wrong attempts on $machineId. Try again in $minutes minute${minutes == 1 ? '' : 's'}.'
: 'Too many wrong attempts on $machineId. Try again now.';
}
const closedPrefix = 'CONNECTION_CLOSED:';
if (code.startsWith(closedPrefix)) {
return 'The connection closed unexpectedly (code ${code.substring(closedPrefix.length)}) '
'before linking finished. Try again.';
}
return switch (code) {
'NO_REMOTE_PASSWORD' =>
'$machineId has no phone password yet. On it, run '
'`harness remote-password set`, then try again.',
'BAD_INTENT' =>
'The connection request was malformed — this usually means a version mismatch. '
'Update harness on both machines and try again.',
'WRONG_PASSWORD' =>
'That password is wrong. It is the one set on $machineId with '
'`harness remote-password set`.',
'BUSY' =>
'Machine $machineId is already handling another link attempt. Wait a moment and try again.',
'TIMEOUT' =>
"Machine $machineId didn't respond in time. Make sure it's running `harness start` "
'and reachable, then try again.',
'SEND_FAILED' =>
'Could not reach the relay to start linking. Check your network connection and try again.',
'DERIVE_FAILED' =>
'Could not process the password locally. Try again; if it persists, restart the app and retry.',
'SELECT_FAILED' =>
"Could not find machine $machineId, or it isn't reachable right now. Check that it has "
'run `harness start`.',
'PAIR_FAILED' =>
"Linking failed on $machineId's side. Try again; if it persists, check its status there "
'with `harness status`.',
'PROTOCOL_ERROR' =>
'Something unexpected happened during the handshake. Try again; if it persists, update '
'harness on the other machine.',
'CONNECTION_ERROR' =>
'Could not reach the relay. Check your network connection and try again.',
_ =>
'Linking failed ($code). Try again; if it persists, check the other machine is on the '
'latest harness version.',
};
}