@camunda8/cli 4.3.0-alpha.1 → 4.3.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -106,6 +106,14 @@ c8ctl), `cluster stop` terminates it directly using the recorded PID.
|
|
|
106
106
|
|
|
107
107
|
Set `C8RUN_CACHE_DIR` environment variable to override.
|
|
108
108
|
|
|
109
|
+
### Download interruptions
|
|
110
|
+
|
|
111
|
+
The c8run archive is several hundred MB. If the connection drops, `c8ctl cluster start` and `c8ctl cluster install` retry up to three times and resume from where the download stopped when the server supports it. An attempt that receives no data for 60 seconds is aborted and retried. If the download still fails, the error names the cause and suggests what to try:
|
|
112
|
+
|
|
113
|
+
- Behind a proxy, set `HTTPS_PROXY` together with `NODE_USE_ENV_PROXY=1` (Node.js 22.21+ or 24.5+).
|
|
114
|
+
- Set `C8CTL_C8RUN_DOWNLOAD_URL` to download from a mirror with the same layout as the Camunda Download Center.
|
|
115
|
+
- Add `--verbose` to print HTTP details for each download attempt: request and response headers, timing, throughput, and the full error cause chain.
|
|
116
|
+
|
|
109
117
|
## Supported platforms
|
|
110
118
|
|
|
111
119
|
- macOS (x86_64, aarch64)
|
|
@@ -18,10 +18,13 @@ import {
|
|
|
18
18
|
rmSync,
|
|
19
19
|
readdirSync,
|
|
20
20
|
readFileSync,
|
|
21
|
+
statSync,
|
|
21
22
|
} from 'node:fs';
|
|
23
|
+
import { once } from 'node:events';
|
|
22
24
|
import { chmod } from 'node:fs/promises';
|
|
23
25
|
import { homedir, platform as osPlatform, arch as osArch } from 'node:os';
|
|
24
26
|
import { join, dirname, isAbsolute, resolve } from 'node:path';
|
|
27
|
+
import { finished } from 'node:stream/promises';
|
|
25
28
|
import { fileURLToPath } from 'node:url';
|
|
26
29
|
|
|
27
30
|
// ---------------------------------------------------------------------------
|
|
@@ -486,98 +489,746 @@ function formatLocalVersionsHint(cacheDir) {
|
|
|
486
489
|
return `Locally available versions:\n${versions.map(v => ` ${v}`).join('\n')}`;
|
|
487
490
|
}
|
|
488
491
|
|
|
489
|
-
function
|
|
492
|
+
function getArchiveName(version) {
|
|
490
493
|
const platformInfo = getPlatformIdentifier();
|
|
491
|
-
return
|
|
494
|
+
return `camunda8-run-${version}-${platformInfo.platform}-${platformInfo.arch}.${platformInfo.extension}`;
|
|
492
495
|
}
|
|
493
496
|
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
+
function getDownloadUrl(version) {
|
|
498
|
+
return `${DOWNLOAD_BASE_URL}${version}/${getArchiveName(version)}`;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// A c8run archive is several hundred MB, so a single dropped connection (a
|
|
502
|
+
// proxy or load balancer closing the socket, a Wi-Fi hiccup) must not fail
|
|
503
|
+
// the whole `cluster start`. downloadWithRetry() makes one initial attempt
|
|
504
|
+
// plus up to DOWNLOAD_MAX_RETRIES retries, resuming with an HTTP Range request
|
|
505
|
+
// where the server allows it, and aborts an attempt that receives no data for
|
|
506
|
+
// DOWNLOAD_STALL_TIMEOUT_MS (undici's own body timeout is 300s).
|
|
507
|
+
const DOWNLOAD_MAX_RETRIES = 3;
|
|
508
|
+
const DOWNLOAD_RETRY_BASE_DELAY_MS = 2_000;
|
|
509
|
+
const DOWNLOAD_STALL_TIMEOUT_MS = 60_000;
|
|
510
|
+
const MB = 1024 * 1024;
|
|
511
|
+
const PROGRESS_STEP_PERCENT = 5;
|
|
512
|
+
const PROGRESS_INTERVAL_MS = 5_000;
|
|
513
|
+
|
|
514
|
+
// TLS certificate errors, which a retry cannot fix (Node's X509 verification
|
|
515
|
+
// codes, see https://nodejs.org/api/tls.html#x509-certificate-error-codes,
|
|
516
|
+
// except OUT_OF_MEM). File-system failures are tagged by fileSystemError().
|
|
517
|
+
const TLS_ERROR_CODES = new Set([
|
|
518
|
+
'UNABLE_TO_GET_ISSUER_CERT',
|
|
519
|
+
'UNABLE_TO_GET_CRL',
|
|
520
|
+
'UNABLE_TO_DECRYPT_CERT_SIGNATURE',
|
|
521
|
+
'UNABLE_TO_DECRYPT_CRL_SIGNATURE',
|
|
522
|
+
'UNABLE_TO_DECODE_ISSUER_PUBLIC_KEY',
|
|
523
|
+
'CERT_SIGNATURE_FAILURE',
|
|
524
|
+
'CRL_SIGNATURE_FAILURE',
|
|
525
|
+
'CERT_NOT_YET_VALID',
|
|
526
|
+
'CERT_HAS_EXPIRED',
|
|
527
|
+
'CRL_NOT_YET_VALID',
|
|
528
|
+
'CRL_HAS_EXPIRED',
|
|
529
|
+
'ERROR_IN_CERT_NOT_BEFORE_FIELD',
|
|
530
|
+
'ERROR_IN_CERT_NOT_AFTER_FIELD',
|
|
531
|
+
'ERROR_IN_CRL_LAST_UPDATE_FIELD',
|
|
532
|
+
'ERROR_IN_CRL_NEXT_UPDATE_FIELD',
|
|
533
|
+
'DEPTH_ZERO_SELF_SIGNED_CERT',
|
|
534
|
+
'SELF_SIGNED_CERT_IN_CHAIN',
|
|
535
|
+
'UNABLE_TO_GET_ISSUER_CERT_LOCALLY',
|
|
536
|
+
'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
|
|
537
|
+
'CERT_CHAIN_TOO_LONG',
|
|
538
|
+
'CERT_REVOKED',
|
|
539
|
+
'INVALID_CA',
|
|
540
|
+
'PATH_LENGTH_EXCEEDED',
|
|
541
|
+
'INVALID_PURPOSE',
|
|
542
|
+
'CERT_UNTRUSTED',
|
|
543
|
+
'CERT_REJECTED',
|
|
544
|
+
'HOSTNAME_MISMATCH',
|
|
545
|
+
'ERR_TLS_CERT_ALTNAME_INVALID',
|
|
546
|
+
]);
|
|
497
547
|
|
|
498
|
-
|
|
548
|
+
/**
|
|
549
|
+
* Read a millisecond override from the environment. These are internal knobs
|
|
550
|
+
* (like C8CTL_STOP_WAIT_TIMEOUT_MS) so tests can keep backoff and stall
|
|
551
|
+
* detection fast; unset, empty or invalid values fall back to the default.
|
|
552
|
+
*/
|
|
553
|
+
function msFromEnv(name, fallback, { allowZero = true } = {}) {
|
|
554
|
+
const raw = process.env[name];
|
|
555
|
+
if (raw === undefined || raw.trim() === '') return fallback;
|
|
556
|
+
const value = Number(raw);
|
|
557
|
+
if (!Number.isFinite(value) || value < 0 || (!allowZero && value === 0)) return fallback;
|
|
558
|
+
return value;
|
|
559
|
+
}
|
|
499
560
|
|
|
500
|
-
|
|
561
|
+
function formatMB(bytes) {
|
|
562
|
+
return `${Math.floor(bytes / MB)} MB`;
|
|
563
|
+
}
|
|
501
564
|
|
|
502
|
-
|
|
503
|
-
|
|
565
|
+
/** Like formatMB, but shows KB below 1 MB so small amounts don't read as "0 MB". */
|
|
566
|
+
function formatSize(bytes) {
|
|
567
|
+
return bytes > 0 && bytes < MB ? `${Math.max(1, Math.floor(bytes / 1024))} KB` : formatMB(bytes);
|
|
568
|
+
}
|
|
504
569
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
`c8run-${version}-${platformInfo.platform}-${platformInfo.arch}.${platformInfo.extension}`,
|
|
509
|
-
);
|
|
570
|
+
function formatMBPrecise(bytes) {
|
|
571
|
+
return `${(bytes / MB).toFixed(1)} MB`;
|
|
572
|
+
}
|
|
510
573
|
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
574
|
+
function formatDuration(ms) {
|
|
575
|
+
return ms >= 1000 ? `${Math.round(ms / 100) / 10}s` : `${Math.round(ms)}ms`;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
function formatThroughput(bytes, ms) {
|
|
579
|
+
return ms > 0 ? `${((bytes / MB) / (ms / 1000)).toFixed(1)} MB/s` : 'n/a';
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
function formatEta(ms) {
|
|
583
|
+
const s = Math.ceil(ms / 1000);
|
|
584
|
+
return s < 60 ? `${s}s` : `${Math.floor(s / 60)}m ${String(s % 60).padStart(2, '0')}s`;
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function downloadError(message, props = {}) {
|
|
588
|
+
const { cause, ...rest } = props;
|
|
589
|
+
return Object.assign(new Error(message, cause === undefined ? undefined : { cause }), rest);
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
/**
|
|
593
|
+
* Flatten an error and its `cause` chain into `{ name, code, message }`
|
|
594
|
+
* entries, outermost first. Undici reports a dropped download as
|
|
595
|
+
* `TypeError: terminated` whose cause carries the useful part (e.g.
|
|
596
|
+
* `UND_ERR_SOCKET: other side closed`).
|
|
597
|
+
*/
|
|
598
|
+
export function errorChain(error) {
|
|
599
|
+
const chain = [];
|
|
600
|
+
const seen = new Set();
|
|
601
|
+
let current = error;
|
|
602
|
+
while (current !== undefined && current !== null && !seen.has(current) && chain.length < 10) {
|
|
603
|
+
seen.add(current);
|
|
604
|
+
if (typeof current === 'object') {
|
|
605
|
+
chain.push({
|
|
606
|
+
name: typeof current.name === 'string' ? current.name : 'Error',
|
|
607
|
+
code: typeof current.code === 'string' ? current.code : undefined,
|
|
608
|
+
message: typeof current.message === 'string' ? current.message : String(current),
|
|
609
|
+
});
|
|
610
|
+
current = current.cause;
|
|
611
|
+
} else {
|
|
612
|
+
chain.push({ name: typeof current, code: undefined, message: String(current) });
|
|
613
|
+
break;
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
return chain;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
function formatChainEntry({ name, code, message }) {
|
|
620
|
+
return `${name}${code ? ` [${code}]` : ''}: ${message}`;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
/** Root cause as "CODE: message" (or just the message when there is no code). */
|
|
624
|
+
function rootCauseDetail(error) {
|
|
625
|
+
const root = errorChain(error).at(-1);
|
|
626
|
+
if (!root) return String(error);
|
|
627
|
+
return root.code ? `${root.code}: ${root.message}` : root.message;
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
/** Map a network failure to plain words a user can act on. */
|
|
631
|
+
export function describeDownloadFailure(error) {
|
|
632
|
+
if (typeof error?.reason === 'string') return error.reason;
|
|
633
|
+
const chain = errorChain(error);
|
|
634
|
+
const codes = new Set(chain.map((entry) => entry.code).filter(Boolean));
|
|
635
|
+
const has = (...candidates) => candidates.some((code) => codes.has(code));
|
|
636
|
+
if (has('UND_ERR_SOCKET', 'ECONNRESET', 'EPIPE', 'UND_ERR_CLOSED', 'ECONNABORTED')) {
|
|
637
|
+
return 'the connection was closed by the server or a proxy';
|
|
638
|
+
}
|
|
639
|
+
if (has('UND_ERR_BODY_TIMEOUT', 'UND_ERR_HEADERS_TIMEOUT', 'UND_ERR_CONNECT_TIMEOUT', 'ETIMEDOUT')) {
|
|
640
|
+
return 'the connection timed out';
|
|
641
|
+
}
|
|
642
|
+
if (has('ENETUNREACH', 'EHOSTUNREACH', 'ENETDOWN', 'EHOSTDOWN')) return 'the network is unreachable';
|
|
643
|
+
if (has('ENOTFOUND', 'EAI_AGAIN')) return 'the server name could not be resolved (DNS lookup failed)';
|
|
644
|
+
if (has('ECONNREFUSED')) return 'the connection was refused';
|
|
645
|
+
if ([...codes].some((code) => TLS_ERROR_CODES.has(code))) {
|
|
646
|
+
return 'the server certificate could not be verified';
|
|
647
|
+
}
|
|
648
|
+
if (chain.some((entry) => entry.message === 'terminated')) return 'the connection was closed unexpectedly';
|
|
649
|
+
return chain.at(-1)?.message ?? String(error);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
/** Wrap a failure of fetch() or of reading the body as a classified download error. */
|
|
653
|
+
function networkError(error) {
|
|
654
|
+
const codes = errorChain(error).map((entry) => entry.code);
|
|
655
|
+
return downloadError(describeDownloadFailure(error), {
|
|
656
|
+
cause: error,
|
|
657
|
+
reason: describeDownloadFailure(error),
|
|
658
|
+
retryable: !codes.some((code) => code && TLS_ERROR_CODES.has(code)),
|
|
519
659
|
});
|
|
660
|
+
}
|
|
520
661
|
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
662
|
+
/** Wrap a failure of the file stream: local, so neither retried nor a network problem. */
|
|
663
|
+
function fileSystemError(error) {
|
|
664
|
+
return downloadError(error.message, { cause: error, reason: error.message, retryable: false, fileSystem: true });
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
function isRetryableDownloadError(error) {
|
|
668
|
+
return error?.retryable === true;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
function parseContentRange(header) {
|
|
672
|
+
const match = /^bytes (\d+)-(\d+)\/(\d+|\*)$/i.exec((header || '').trim());
|
|
673
|
+
if (!match) return null;
|
|
674
|
+
return {
|
|
675
|
+
start: Number(match[1]),
|
|
676
|
+
end: Number(match[2]),
|
|
677
|
+
total: match[3] === '*' ? 0 : Number(match[3]),
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
function fileSizeOrZero(file) {
|
|
682
|
+
try {
|
|
683
|
+
return statSync(file).size;
|
|
684
|
+
} catch {
|
|
685
|
+
return 0;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Show a URL without credentials: userinfo becomes `***`, and the query
|
|
691
|
+
* (e.g. a signed CDN redirect) and fragment are replaced by `?<redacted>`.
|
|
692
|
+
*/
|
|
693
|
+
function redactUrl(value, fallback = '(invalid URL)') {
|
|
694
|
+
try {
|
|
695
|
+
const url = new URL(value);
|
|
696
|
+
if (url.username || url.password) {
|
|
697
|
+
url.username = '***';
|
|
698
|
+
url.password = '';
|
|
699
|
+
}
|
|
700
|
+
const query = url.search || url.hash ? '?<redacted>' : '';
|
|
701
|
+
url.search = '';
|
|
702
|
+
url.hash = '';
|
|
703
|
+
return `${url.toString()}${query}`;
|
|
704
|
+
} catch {
|
|
705
|
+
return fallback;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
const PROXY_ENV_VARS = ['HTTPS_PROXY', 'https_proxy', 'HTTP_PROXY', 'http_proxy', 'NO_PROXY', 'no_proxy'];
|
|
710
|
+
|
|
711
|
+
function isHttpsProxyConfigured() {
|
|
712
|
+
return Boolean(process.env.HTTPS_PROXY || process.env.https_proxy);
|
|
713
|
+
}
|
|
714
|
+
|
|
715
|
+
function isEnvProxyEnabled() {
|
|
716
|
+
return process.env.NODE_USE_ENV_PROXY === '1';
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
function proxyHint() {
|
|
720
|
+
if (isHttpsProxyConfigured() && !isEnvProxyEnabled()) {
|
|
721
|
+
return (
|
|
722
|
+
'HTTPS_PROXY is set, but Node.js only uses it when NODE_USE_ENV_PROXY=1 is set as well ' +
|
|
723
|
+
'(Node.js 22.21+ or 24.5+). Set NODE_USE_ENV_PROXY=1 and try again.'
|
|
527
724
|
);
|
|
528
725
|
}
|
|
726
|
+
return 'Behind a proxy? Set HTTPS_PROXY together with NODE_USE_ENV_PROXY=1 (Node.js 22.21+ or 24.5+).';
|
|
727
|
+
}
|
|
529
728
|
|
|
530
|
-
|
|
729
|
+
function mirrorHint() {
|
|
730
|
+
const override = process.env.C8CTL_C8RUN_DOWNLOAD_URL;
|
|
731
|
+
if (override) {
|
|
732
|
+
return (
|
|
733
|
+
`C8CTL_C8RUN_DOWNLOAD_URL points the download at ${redactUrl(override)}. ` +
|
|
734
|
+
'Make sure that server is reachable, or unset it to use the Camunda Download Center.'
|
|
735
|
+
);
|
|
736
|
+
}
|
|
737
|
+
return 'Use a mirror: set C8CTL_C8RUN_DOWNLOAD_URL to a base URL with the same layout as the Camunda Download Center.';
|
|
738
|
+
}
|
|
739
|
+
|
|
740
|
+
function buildDownloadFailureMessage({
|
|
741
|
+
error,
|
|
742
|
+
url,
|
|
743
|
+
attempts,
|
|
744
|
+
connected,
|
|
745
|
+
maxBytesReceived,
|
|
746
|
+
total,
|
|
747
|
+
targetFile,
|
|
748
|
+
keptFileNote,
|
|
749
|
+
extraHints,
|
|
750
|
+
}) {
|
|
751
|
+
const codes = errorChain(error).map((entry) => entry.code).filter(Boolean);
|
|
752
|
+
|
|
753
|
+
// A local file-system failure has nothing to do with the network.
|
|
754
|
+
if (error?.fileSystem === true) {
|
|
755
|
+
return (
|
|
756
|
+
`Could not save the download to ${targetFile}: ${rootCauseDetail(error)}\n` +
|
|
757
|
+
(keptFileNote ? `${keptFileNote}\n` : '') +
|
|
758
|
+
`URL: ${redactUrl(url)}\n` +
|
|
759
|
+
'What you can try:\n' +
|
|
760
|
+
' - Check that there is enough free disk space and that you can write to that directory.\n' +
|
|
761
|
+
' - Set C8RUN_CACHE_DIR to a different directory to download there instead.'
|
|
762
|
+
);
|
|
763
|
+
}
|
|
531
764
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
765
|
+
const reason = describeDownloadFailure(error);
|
|
766
|
+
const detail = rootCauseDetail(error);
|
|
767
|
+
const attemptsText = `${attempts} attempt${attempts === 1 ? '' : 's'}`;
|
|
768
|
+
const lines = [
|
|
769
|
+
connected
|
|
770
|
+
? `Download failed after ${attemptsText}: ${reason}.`
|
|
771
|
+
: `Cannot reach the Camunda Download Center (${attemptsText}): ${reason}.`,
|
|
772
|
+
];
|
|
773
|
+
// Our own errors (stall, HTTP status, size mismatch) are fully described by `reason`.
|
|
774
|
+
if (errorChain(error).length > 1 && detail !== reason) lines.push(`Cause: ${detail}`);
|
|
775
|
+
lines.push(`URL: ${redactUrl(url)}`);
|
|
776
|
+
if (maxBytesReceived > 0) {
|
|
777
|
+
lines.push(
|
|
778
|
+
`Received ${formatSize(maxBytesReceived)}${total > 0 ? ` of ${formatSize(total)}` : ''} before giving up` +
|
|
779
|
+
(keptFileNote ? '.' : '; the incomplete download was removed.'),
|
|
537
780
|
);
|
|
538
781
|
}
|
|
782
|
+
if (keptFileNote) lines.push(keptFileNote);
|
|
783
|
+
const hints = [
|
|
784
|
+
'Please check your network connection and VPN, then try again.',
|
|
785
|
+
proxyHint(),
|
|
786
|
+
...(codes.some((code) => TLS_ERROR_CODES.has(code))
|
|
787
|
+
? ['If your network inspects HTTPS traffic, point NODE_EXTRA_CA_CERTS at your organization\'s CA certificate file.']
|
|
788
|
+
: []),
|
|
789
|
+
mirrorHint(),
|
|
790
|
+
...extraHints,
|
|
791
|
+
];
|
|
792
|
+
lines.push('What you can try:', ...hints.map((hint) => ` - ${hint}`));
|
|
793
|
+
return lines.join('\n');
|
|
794
|
+
}
|
|
539
795
|
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
796
|
+
/**
|
|
797
|
+
* Download `url` to `targetFile`, surviving dropped connections.
|
|
798
|
+
*
|
|
799
|
+
* - One initial attempt plus up to `maxRetries` retries, with exponential
|
|
800
|
+
* backoff (`retryDelayMs`, doubled per retry), for transient failures only:
|
|
801
|
+
* network errors, dropped or stalled connections, HTTP 5xx and 429, and an
|
|
802
|
+
* archive whose final size does not match what the server announced.
|
|
803
|
+
* - Resumes with `Range: bytes=<written>-` and `If-Range: <validator>` when
|
|
804
|
+
* the first response carried a strong ETag or a Last-Modified date. A 206
|
|
805
|
+
* answer is appended to the partial file; a 200 answer restarts from zero.
|
|
806
|
+
* - An attempt fails when no bytes arrive for `stallTimeoutMs`.
|
|
807
|
+
* - Other HTTP errors (e.g. 404) are not retried: the thrown error carries
|
|
808
|
+
* `status` so the caller can explain it.
|
|
809
|
+
* - The partial file is kept between retries and deleted when giving up.
|
|
810
|
+
* - With `verbose`, logs request/response details, per-attempt timing,
|
|
811
|
+
* and full error cause chains.
|
|
812
|
+
*
|
|
813
|
+
* Resolves to `{ bytes, etag }`, where `etag` is the ETag (or Last-Modified)
|
|
814
|
+
* of the downloaded content, or null.
|
|
815
|
+
*/
|
|
816
|
+
export async function downloadWithRetry({
|
|
817
|
+
url,
|
|
818
|
+
targetFile,
|
|
819
|
+
logger = getLogger(),
|
|
820
|
+
verbose = false,
|
|
821
|
+
maxRetries = DOWNLOAD_MAX_RETRIES,
|
|
822
|
+
retryDelayMs = DOWNLOAD_RETRY_BASE_DELAY_MS,
|
|
823
|
+
stallTimeoutMs = DOWNLOAD_STALL_TIMEOUT_MS,
|
|
824
|
+
progressIntervalMs = PROGRESS_INTERVAL_MS,
|
|
825
|
+
extraHints = [],
|
|
826
|
+
}) {
|
|
827
|
+
const vlog = verbose ? (message) => logger.info(`[verbose] ${message}`, { stream: 'stderr' }) : () => {};
|
|
828
|
+
const invalid = invalidDownloadUrlReason(url);
|
|
829
|
+
if (invalid) {
|
|
830
|
+
throw downloadError(
|
|
831
|
+
`Cannot download from ${redactUrl(url)}: ${invalid}.` +
|
|
832
|
+
(process.env.C8CTL_C8RUN_DOWNLOAD_URL ? ' Check C8CTL_C8RUN_DOWNLOAD_URL.' : ''),
|
|
833
|
+
{ reason: invalid, retryable: false },
|
|
834
|
+
);
|
|
835
|
+
}
|
|
836
|
+
const totalAttempts = maxRetries + 1;
|
|
837
|
+
const state = {
|
|
838
|
+
written: 0,
|
|
839
|
+
total: 0,
|
|
840
|
+
validator: null,
|
|
841
|
+
etag: null,
|
|
842
|
+
reportedPercent: 0,
|
|
843
|
+
reportedBytes: 0,
|
|
844
|
+
reportedAt: Date.now(),
|
|
845
|
+
connected: false,
|
|
846
|
+
maxBytesReceived: 0,
|
|
847
|
+
attemptBytes: 0,
|
|
848
|
+
};
|
|
544
849
|
|
|
545
|
-
|
|
850
|
+
if (verbose) {
|
|
851
|
+
const proxyVars = PROXY_ENV_VARS.filter((name) => process.env[name]).map((name) =>
|
|
852
|
+
name.toLowerCase() === 'no_proxy' ? `${name}=${process.env[name]}` : `${name}=${redactUrl(process.env[name], '(set)')}`,
|
|
853
|
+
);
|
|
854
|
+
vlog(`Download URL: ${redactUrl(url)}`);
|
|
855
|
+
vlog(`Target file: ${targetFile}`);
|
|
856
|
+
vlog(`Node.js ${process.version}; NODE_USE_ENV_PROXY=${process.env.NODE_USE_ENV_PROXY ?? '(not set)'}`);
|
|
857
|
+
vlog(`Proxy environment: ${proxyVars.length > 0 ? proxyVars.join(', ') : '(none set)'}`);
|
|
858
|
+
vlog(
|
|
859
|
+
`Retry policy: up to ${maxRetries} retries (backoff starting at ${formatDuration(retryDelayMs)}), ` +
|
|
860
|
+
`stall timeout ${formatDuration(stallTimeoutMs)}`,
|
|
861
|
+
);
|
|
862
|
+
}
|
|
546
863
|
|
|
547
|
-
let
|
|
548
|
-
let
|
|
864
|
+
let lastError;
|
|
865
|
+
let attempt = 0;
|
|
866
|
+
while (attempt < totalAttempts) {
|
|
867
|
+
attempt += 1;
|
|
868
|
+
const startedAt = Date.now();
|
|
869
|
+
state.attemptBytes = 0;
|
|
870
|
+
vlog(`Attempt ${attempt}/${totalAttempts} started`);
|
|
871
|
+
try {
|
|
872
|
+
await downloadAttempt({ url, targetFile, state, stallTimeoutMs, progressIntervalMs, logger, vlog, startedAt });
|
|
873
|
+
const elapsed = Date.now() - startedAt;
|
|
874
|
+
vlog(
|
|
875
|
+
`Attempt ${attempt}/${totalAttempts} completed after ${formatDuration(elapsed)}: ` +
|
|
876
|
+
`${formatMBPrecise(state.attemptBytes)} received (${formatThroughput(state.attemptBytes, elapsed)}), ` +
|
|
877
|
+
`${formatMBPrecise(state.written)} total`,
|
|
878
|
+
);
|
|
879
|
+
return { bytes: state.written, etag: state.etag };
|
|
880
|
+
} catch (error) {
|
|
881
|
+
lastError = error;
|
|
882
|
+
const elapsed = Date.now() - startedAt;
|
|
883
|
+
vlog(
|
|
884
|
+
`Attempt ${attempt}/${totalAttempts} failed after ${formatDuration(elapsed)}: ` +
|
|
885
|
+
`${formatMBPrecise(state.attemptBytes)} received in this attempt, ${formatMBPrecise(state.written)} on disk`,
|
|
886
|
+
);
|
|
887
|
+
const chain = errorChain(error);
|
|
888
|
+
chain.forEach((entry, index) => vlog(`${index === 0 ? 'Error details' : ' caused by'}: ${formatChainEntry(entry)}`));
|
|
889
|
+
|
|
890
|
+
if (!isRetryableDownloadError(error) || attempt >= totalAttempts) break;
|
|
891
|
+
|
|
892
|
+
const retry = attempt;
|
|
893
|
+
const delay = retryDelayMs * 2 ** (retry - 1);
|
|
894
|
+
const reason = describeDownloadFailure(error);
|
|
895
|
+
const resumable = state.written > 0 && state.validator !== null;
|
|
896
|
+
const next = resumable
|
|
897
|
+
? `, resuming from ${formatSize(state.written)}...`
|
|
898
|
+
: state.written > 0
|
|
899
|
+
? ', restarting from the beginning (the server did not send an ETag or Last-Modified header, so the download cannot be resumed safely)...'
|
|
900
|
+
: '...';
|
|
901
|
+
logger.warn(
|
|
902
|
+
state.written > 0
|
|
903
|
+
? `Download interrupted at ${formatSize(state.written)}${state.total > 0 ? ` / ${formatSize(state.total)}` : ''} (${reason}). ` +
|
|
904
|
+
`Retrying (${retry}/${maxRetries}) in ${formatDuration(delay)}${next}`
|
|
905
|
+
: `Download failed (${reason}). Retrying (${retry}/${maxRetries}) in ${formatDuration(delay)}...`,
|
|
906
|
+
);
|
|
907
|
+
if (!resumable) state.written = 0;
|
|
908
|
+
await sleep(delay);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
549
911
|
|
|
550
|
-
|
|
912
|
+
// An unremovable file must not hide why the download failed; the message says
|
|
913
|
+
// it was kept (only if it is really there, e.g. not for ENAMETOOLONG).
|
|
914
|
+
let cleanupError;
|
|
915
|
+
try {
|
|
916
|
+
rmSync(targetFile, { force: true });
|
|
917
|
+
} catch (error) {
|
|
918
|
+
if (existsSync(targetFile)) cleanupError = error;
|
|
919
|
+
}
|
|
920
|
+
const keptFileNote = cleanupError
|
|
921
|
+
? `The incomplete download could not be removed (${cleanupError.code ?? cleanupError.message}); delete it yourself: ${targetFile}`
|
|
922
|
+
: undefined;
|
|
923
|
+
|
|
924
|
+
if (lastError?.status !== undefined && !isRetryableDownloadError(lastError)) {
|
|
925
|
+
throw Object.assign(lastError, { keptFileNote });
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
throw downloadError(
|
|
929
|
+
buildDownloadFailureMessage({
|
|
930
|
+
error: lastError,
|
|
931
|
+
url,
|
|
932
|
+
attempts: attempt,
|
|
933
|
+
connected: state.connected,
|
|
934
|
+
maxBytesReceived: state.maxBytesReceived,
|
|
935
|
+
total: state.total,
|
|
936
|
+
targetFile,
|
|
937
|
+
keptFileNote,
|
|
938
|
+
extraHints,
|
|
939
|
+
}),
|
|
940
|
+
{ cause: lastError, attempts: attempt },
|
|
941
|
+
);
|
|
942
|
+
}
|
|
551
943
|
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
944
|
+
/** Why fetch() would reject `url` before sending anything, or null if it would not. */
|
|
945
|
+
function invalidDownloadUrlReason(url) {
|
|
946
|
+
let parsed;
|
|
947
|
+
try {
|
|
948
|
+
parsed = new URL(url);
|
|
949
|
+
} catch {
|
|
950
|
+
return 'not a valid URL';
|
|
951
|
+
}
|
|
952
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
953
|
+
return `unsupported protocol ${parsed.protocol} (use http or https)`;
|
|
954
|
+
}
|
|
955
|
+
if (parsed.username || parsed.password) return 'the URL contains credentials, which fetch() does not send';
|
|
956
|
+
return null;
|
|
957
|
+
}
|
|
555
958
|
|
|
556
|
-
|
|
557
|
-
|
|
959
|
+
/** One HTTP request; updates `state` and throws a classified error on failure. */
|
|
960
|
+
async function downloadAttempt({ url, targetFile, state, stallTimeoutMs, progressIntervalMs, logger, vlog, startedAt }) {
|
|
961
|
+
const controller = new AbortController();
|
|
962
|
+
let stallTimer;
|
|
963
|
+
let stalled = false;
|
|
964
|
+
const armStallTimer = () => {
|
|
965
|
+
clearTimeout(stallTimer);
|
|
966
|
+
stallTimer = setTimeout(() => {
|
|
967
|
+
stalled = true;
|
|
968
|
+
controller.abort();
|
|
969
|
+
}, stallTimeoutMs);
|
|
970
|
+
};
|
|
971
|
+
const disarmStallTimer = () => clearTimeout(stallTimer);
|
|
972
|
+
const classify = (error) => {
|
|
973
|
+
if (stalled) {
|
|
974
|
+
const reason = `no data received for ${formatDuration(stallTimeoutMs)}`;
|
|
975
|
+
return downloadError(reason, { reason, retryable: true });
|
|
976
|
+
}
|
|
977
|
+
return networkError(error);
|
|
978
|
+
};
|
|
558
979
|
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
980
|
+
const resume = state.written > 0 && state.validator !== null;
|
|
981
|
+
// fetch() decodes a Content-Encoding transparently, while Content-Length and
|
|
982
|
+
// byte ranges count encoded bytes; ask for the raw bytes so both match the file.
|
|
983
|
+
const headers = {
|
|
984
|
+
'Accept-Encoding': 'identity',
|
|
985
|
+
...(resume ? { Range: `bytes=${state.written}-`, 'If-Range': state.validator } : {}),
|
|
986
|
+
};
|
|
987
|
+
vlog(`GET ${redactUrl(url)}`);
|
|
988
|
+
vlog(`Request headers: ${Object.entries(headers).map(([name, value]) => `${name}: ${value}`).join(', ')}`);
|
|
989
|
+
|
|
990
|
+
let response;
|
|
991
|
+
armStallTimer();
|
|
992
|
+
try {
|
|
993
|
+
response = await fetch(url, { headers, signal: controller.signal });
|
|
994
|
+
} catch (error) {
|
|
995
|
+
throw classify(error);
|
|
996
|
+
} finally {
|
|
997
|
+
disarmStallTimer();
|
|
998
|
+
}
|
|
999
|
+
state.connected = true;
|
|
1000
|
+
|
|
1001
|
+
const header = (name) => response.headers.get(name);
|
|
1002
|
+
vlog(
|
|
1003
|
+
`Response: HTTP ${response.status}${response.statusText ? ` ${response.statusText}` : ''} from ${redactUrl(response.url || url)}` +
|
|
1004
|
+
`${response.redirected ? ' (after redirect)' : ''}`,
|
|
1005
|
+
);
|
|
1006
|
+
vlog(
|
|
1007
|
+
`Response headers: ${['content-length', 'content-range', 'content-encoding', 'etag', 'last-modified', 'accept-ranges']
|
|
1008
|
+
.map((name) => `${name}: ${header(name) ?? '(none)'}`)
|
|
1009
|
+
.join(', ')}`,
|
|
1010
|
+
);
|
|
1011
|
+
|
|
1012
|
+
const discardBody = () => response.body?.cancel().catch(() => {});
|
|
1013
|
+
let append = false;
|
|
1014
|
+
// Where a 206 body must end; the only size check when the total is `*`.
|
|
1015
|
+
let rangeEnd = 0;
|
|
1016
|
+
// A server may encode the body anyway; its sizes and ranges then don't apply.
|
|
1017
|
+
const encoded = !['', 'identity'].includes((header('content-encoding') ?? '').trim().toLowerCase());
|
|
1018
|
+
|
|
1019
|
+
if (response.status === 206) {
|
|
1020
|
+
const range = parseContentRange(header('content-range'));
|
|
1021
|
+
if (!resume || !range || range.start !== state.written || encoded) {
|
|
1022
|
+
await discardBody();
|
|
1023
|
+
state.written = 0;
|
|
1024
|
+
const reason = `the server sent an unexpected byte range (${header('content-range') ?? 'no Content-Range header'})`;
|
|
1025
|
+
throw downloadError(reason, { reason, retryable: true });
|
|
1026
|
+
}
|
|
1027
|
+
if (range.total > 0) state.total = range.total;
|
|
1028
|
+
rangeEnd = range.end + 1;
|
|
1029
|
+
append = true;
|
|
1030
|
+
} else if (response.ok) {
|
|
1031
|
+
if (resume) {
|
|
1032
|
+
logger.info('The server did not resume the download; restarting from the beginning.');
|
|
1033
|
+
}
|
|
1034
|
+
state.written = 0;
|
|
1035
|
+
state.reportedPercent = 0;
|
|
1036
|
+
state.reportedBytes = 0;
|
|
1037
|
+
state.total = encoded ? 0 : Number.parseInt(header('content-length') || '0', 10) || 0;
|
|
1038
|
+
// Note: 'etag' values are quoted strings (e.g. '"abc123"') while 'last-modified'
|
|
1039
|
+
// values are date strings. Both are used as opaque version tokens for equality
|
|
1040
|
+
// comparison — the format difference does not affect correctness.
|
|
1041
|
+
state.etag = header('etag') || header('last-modified') || null;
|
|
1042
|
+
// If-Range needs a strong validator; a weak ETag (W/"...") must not be used.
|
|
1043
|
+
const strongEtag = header('etag') && !header('etag').startsWith('W/') ? header('etag') : null;
|
|
1044
|
+
state.validator = encoded ? null : strongEtag || header('last-modified') || null;
|
|
1045
|
+
} else {
|
|
1046
|
+
await discardBody();
|
|
1047
|
+
if (response.status === 416 && resume) {
|
|
1048
|
+
state.written = 0;
|
|
1049
|
+
const reason = 'the server rejected the request to resume the download (HTTP 416)';
|
|
1050
|
+
throw downloadError(reason, { status: 416, reason, retryable: true });
|
|
567
1051
|
}
|
|
1052
|
+
const reason = `the server responded with HTTP ${response.status}${response.statusText ? ` ${response.statusText}` : ''}`;
|
|
1053
|
+
throw downloadError(reason, {
|
|
1054
|
+
status: response.status,
|
|
1055
|
+
reason,
|
|
1056
|
+
retryable: response.status >= 500 || response.status === 429,
|
|
1057
|
+
});
|
|
568
1058
|
}
|
|
569
1059
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
1060
|
+
if (!response.body) {
|
|
1061
|
+
const reason = 'the server sent an empty response';
|
|
1062
|
+
throw downloadError(reason, { reason, retryable: true });
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
const fileStream = createWriteStream(targetFile, { flags: append ? 'a' : 'w' });
|
|
1066
|
+
let fileError;
|
|
1067
|
+
fileStream.on('error', (error) => {
|
|
1068
|
+
fileError = error;
|
|
1069
|
+
});
|
|
1070
|
+
const reader = response.body.getReader();
|
|
1071
|
+
|
|
1072
|
+
try {
|
|
1073
|
+
while (true) {
|
|
1074
|
+
let chunk;
|
|
1075
|
+
armStallTimer();
|
|
1076
|
+
try {
|
|
1077
|
+
chunk = await reader.read();
|
|
1078
|
+
} catch (error) {
|
|
1079
|
+
throw classify(error);
|
|
1080
|
+
} finally {
|
|
1081
|
+
disarmStallTimer();
|
|
1082
|
+
}
|
|
1083
|
+
if (chunk.done) break;
|
|
1084
|
+
|
|
1085
|
+
// The stream may have failed while we awaited the read; writing to it then
|
|
1086
|
+
// returns false and 'drain' never comes.
|
|
1087
|
+
if (fileError) throw fileError;
|
|
1088
|
+
if (!fileStream.write(chunk.value)) {
|
|
1089
|
+
await once(fileStream, 'drain');
|
|
1090
|
+
}
|
|
1091
|
+
if (fileError) throw fileError;
|
|
1092
|
+
state.written += chunk.value.length;
|
|
1093
|
+
state.attemptBytes += chunk.value.length;
|
|
1094
|
+
state.maxBytesReceived = Math.max(state.maxBytesReceived, state.written);
|
|
1095
|
+
reportDownloadProgress({ state, logger, startedAt, progressIntervalMs });
|
|
1096
|
+
}
|
|
573
1097
|
fileStream.end();
|
|
1098
|
+
await finished(fileStream);
|
|
1099
|
+
} catch (error) {
|
|
1100
|
+
disarmStallTimer();
|
|
1101
|
+
await reader.cancel().catch(() => {});
|
|
1102
|
+
if (!fileStream.destroyed) fileStream.end();
|
|
1103
|
+
await finished(fileStream).catch(() => {});
|
|
1104
|
+
// What actually reached the disk is what a resume continues from.
|
|
1105
|
+
state.written = fileSizeOrZero(targetFile);
|
|
1106
|
+
throw fileError ? fileSystemError(fileError) : error;
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
state.written = fileSizeOrZero(targetFile);
|
|
1110
|
+
const expected = state.total > 0 ? state.total : rangeEnd;
|
|
1111
|
+
if (expected > 0 && state.written !== expected) {
|
|
1112
|
+
const reason =
|
|
1113
|
+
state.written < expected
|
|
1114
|
+
? `the download ended early (received ${formatSize(state.written)} of ${formatSize(expected)})`
|
|
1115
|
+
: `the download is larger than announced (${formatSize(state.written)} instead of ${formatSize(expected)})`;
|
|
1116
|
+
// An oversized file cannot be repaired by resuming; start over.
|
|
1117
|
+
if (state.written > expected) state.written = 0;
|
|
1118
|
+
throw downloadError(reason, { reason, retryable: true });
|
|
1119
|
+
}
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
function reportDownloadProgress({ state, logger, startedAt, progressIntervalMs }) {
|
|
1123
|
+
const now = Date.now();
|
|
1124
|
+
const percentage = state.total > 0 ? Math.floor((state.written / state.total) * 100) : 0;
|
|
1125
|
+
const stepReached = state.total > 0 && percentage >= state.reportedPercent + PROGRESS_STEP_PERCENT;
|
|
1126
|
+
const intervalPassed = now - state.reportedAt >= progressIntervalMs && state.written > state.reportedBytes;
|
|
1127
|
+
if (!stepReached && !intervalPassed) return;
|
|
1128
|
+
|
|
1129
|
+
const elapsed = now - startedAt;
|
|
1130
|
+
const rate = formatThroughput(state.attemptBytes, elapsed);
|
|
1131
|
+
const remaining = state.total - state.written;
|
|
1132
|
+
const eta =
|
|
1133
|
+
state.total > 0 && remaining > 0 && state.attemptBytes > 0 && elapsed > 0
|
|
1134
|
+
? `, ETA ${formatEta((remaining * elapsed) / state.attemptBytes)}`
|
|
1135
|
+
: '';
|
|
1136
|
+
logger.info(
|
|
1137
|
+
state.total > 0
|
|
1138
|
+
? `//> ${percentage}% (${formatMBPrecise(state.written)} / ${formatMBPrecise(state.total)}) at ${rate}${eta}`
|
|
1139
|
+
: `//> ${formatMBPrecise(state.written)} (total size unknown) at ${rate}`,
|
|
1140
|
+
);
|
|
1141
|
+
state.reportedPercent = percentage;
|
|
1142
|
+
state.reportedBytes = state.written;
|
|
1143
|
+
state.reportedAt = now;
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
/**
|
|
1147
|
+
* Render an error for a "Failed to ...:" line without losing its cause.
|
|
1148
|
+
* `${error}` alone hides `error.cause`, which is where undici puts the useful
|
|
1149
|
+
* part of a network failure (e.g. "TypeError: terminated" is caused by
|
|
1150
|
+
* "UND_ERR_SOCKET: other side closed").
|
|
1151
|
+
*/
|
|
1152
|
+
export function formatErrorWithCause(error) {
|
|
1153
|
+
const base = `${error}`;
|
|
1154
|
+
if (error?.cause === undefined || error?.cause === null) return base;
|
|
1155
|
+
const detail = rootCauseDetail(error);
|
|
1156
|
+
return base.includes(detail) ? base : `${base} (cause: ${detail})`;
|
|
1157
|
+
}
|
|
1158
|
+
|
|
1159
|
+
/** Shell-quote a path for display in a hint when it contains spaces. */
|
|
1160
|
+
/** Quote a path for a copy-paste command: single quotes for POSIX shells, double quotes on Windows. */
|
|
1161
|
+
export function quoteForHint(path, platform = osPlatform()) {
|
|
1162
|
+
if (platform === 'win32') {
|
|
1163
|
+
// Windows paths cannot contain `"`; cmd and PowerShell both accept double quotes.
|
|
1164
|
+
return /^[\w.:\\/-]+$/.test(path) ? path : `"${path}"`;
|
|
1165
|
+
}
|
|
1166
|
+
return /^[\w@%+=:,./-]+$/.test(path) ? path : `'${path.replaceAll("'", "'\\''")}'`;
|
|
1167
|
+
}
|
|
1168
|
+
|
|
1169
|
+
async function downloadC8Run(config) {
|
|
1170
|
+
const logger = getLogger();
|
|
1171
|
+
const version = config.version;
|
|
1172
|
+
|
|
1173
|
+
const downloadUrl = getDownloadUrl(version);
|
|
1174
|
+
|
|
1175
|
+
logger.info(`Downloading Camunda ${version} for ${getPlatformIdentifier().platform}...`);
|
|
1176
|
+
|
|
1177
|
+
const cacheDir = config.cacheDir;
|
|
1178
|
+
mkdirSync(cacheDir, { recursive: true });
|
|
1179
|
+
|
|
1180
|
+
const platformInfo = getPlatformIdentifier();
|
|
1181
|
+
const targetFile = join(
|
|
1182
|
+
cacheDir,
|
|
1183
|
+
`c8run-${version}-${platformInfo.platform}-${platformInfo.arch}.${platformInfo.extension}`,
|
|
1184
|
+
);
|
|
1185
|
+
|
|
1186
|
+
// A manually downloaded and extracted archive in the install dir is picked
|
|
1187
|
+
// up by isC8RunInstalled(), exactly like one c8ctl extracted itself.
|
|
1188
|
+
const installDir = join(cacheDir, `c8run-${version}`);
|
|
1189
|
+
// Not parsed from downloadUrl: a malformed C8CTL_C8RUN_DOWNLOAD_URL must reach
|
|
1190
|
+
// downloadWithRetry()'s validation instead of throwing a bare TypeError here.
|
|
1191
|
+
const archiveName = getArchiveName(version);
|
|
1192
|
+
const extract = resolveExtractCommand({
|
|
1193
|
+
archivePath: archiveName,
|
|
1194
|
+
targetDir: quoteForHint(installDir),
|
|
1195
|
+
platform: osPlatform(),
|
|
574
1196
|
});
|
|
1197
|
+
const manualHint =
|
|
1198
|
+
`Or download ${archiveName} yourself (e.g. with a browser or a download manager), create ${quoteForHint(installDir)} ` +
|
|
1199
|
+
`and extract it there: ${extract.command} ${extract.args.join(' ')}`;
|
|
1200
|
+
|
|
1201
|
+
let result;
|
|
1202
|
+
try {
|
|
1203
|
+
result = await downloadWithRetry({
|
|
1204
|
+
url: downloadUrl,
|
|
1205
|
+
targetFile,
|
|
1206
|
+
logger,
|
|
1207
|
+
verbose: config.verbose === true,
|
|
1208
|
+
retryDelayMs: msFromEnv('C8CTL_C8RUN_DOWNLOAD_RETRY_DELAY_MS', DOWNLOAD_RETRY_BASE_DELAY_MS),
|
|
1209
|
+
stallTimeoutMs: msFromEnv('C8CTL_C8RUN_DOWNLOAD_STALL_TIMEOUT_MS', DOWNLOAD_STALL_TIMEOUT_MS, {
|
|
1210
|
+
allowZero: false,
|
|
1211
|
+
}),
|
|
1212
|
+
extraHints: [manualHint],
|
|
1213
|
+
});
|
|
1214
|
+
} catch (error) {
|
|
1215
|
+
if (error.status !== undefined && !isRetryableDownloadError(error)) {
|
|
1216
|
+
throw new Error(
|
|
1217
|
+
`Failed to download c8run ${version}: HTTP ${error.status}\n` +
|
|
1218
|
+
`URL: ${redactUrl(downloadUrl)}\n` +
|
|
1219
|
+
(error.keptFileNote ? `${error.keptFileNote}\n` : '') +
|
|
1220
|
+
`Please check the version exists or try a different version.\n\n` +
|
|
1221
|
+
formatLocalVersionsHint(cacheDir),
|
|
1222
|
+
);
|
|
1223
|
+
}
|
|
1224
|
+
throw new Error(`${error.message}\n\n${formatLocalVersionsHint(cacheDir)}`, { cause: error.cause ?? error });
|
|
1225
|
+
}
|
|
575
1226
|
|
|
576
1227
|
logger.info(
|
|
577
|
-
`Downloaded and saved to ${targetFile} (${
|
|
1228
|
+
`Downloaded and saved to ${targetFile} (${formatMB(result.bytes)})`,
|
|
578
1229
|
);
|
|
579
1230
|
|
|
580
|
-
return { archivePath: targetFile, etag };
|
|
1231
|
+
return { archivePath: targetFile, etag: result.etag };
|
|
581
1232
|
}
|
|
582
1233
|
|
|
583
1234
|
async function extractArchive(archivePath, targetDir) {
|
|
@@ -758,7 +1409,13 @@ export async function hasNewerVersionAvailable(config) {
|
|
|
758
1409
|
const controller = new AbortController();
|
|
759
1410
|
const timeout = setTimeout(() => controller.abort(), 5_000);
|
|
760
1411
|
try {
|
|
761
|
-
|
|
1412
|
+
// Same representation as the download, whose ETag was stored: with
|
|
1413
|
+
// Vary: Accept-Encoding a gzip variant can carry a different ETag.
|
|
1414
|
+
const response = await fetch(downloadUrl, {
|
|
1415
|
+
method: 'HEAD',
|
|
1416
|
+
headers: { 'Accept-Encoding': 'identity' },
|
|
1417
|
+
signal: controller.signal,
|
|
1418
|
+
});
|
|
762
1419
|
if (!response.ok) {
|
|
763
1420
|
// Can't determine — keep the current installation
|
|
764
1421
|
return false;
|
|
@@ -2788,6 +3445,8 @@ export const commands = {
|
|
|
2788
3445
|
checkForUpdates: parsed.subcommand === 'install' && rolling,
|
|
2789
3446
|
// start: soft hint about available updates for rolling versions (non-blocking)
|
|
2790
3447
|
checkForUpdateHint: parsed.subcommand === 'start' && rolling,
|
|
3448
|
+
// --verbose: detailed HTTP diagnostics for the c8run download
|
|
3449
|
+
verbose: ctx?.verbose === true,
|
|
2791
3450
|
};
|
|
2792
3451
|
|
|
2793
3452
|
if (parsed.subcommand === 'start') {
|
|
@@ -2795,7 +3454,7 @@ export const commands = {
|
|
|
2795
3454
|
await ensureC8RunInstalled(config);
|
|
2796
3455
|
await startC8Run(config, parsed.debug);
|
|
2797
3456
|
} catch (error) {
|
|
2798
|
-
logger.error(`Failed to start cluster: ${error}`);
|
|
3457
|
+
logger.error(`Failed to start cluster: ${formatErrorWithCause(error)}`);
|
|
2799
3458
|
process.exit(1);
|
|
2800
3459
|
}
|
|
2801
3460
|
} else if (parsed.subcommand === 'stop') {
|
|
@@ -2838,7 +3497,7 @@ export const commands = {
|
|
|
2838
3497
|
await ensureC8RunInstalled(config);
|
|
2839
3498
|
logger.info(`Version ${version} is ready. Start it with: c8ctl cluster start ${parsed.version || ''}`);
|
|
2840
3499
|
} catch (error) {
|
|
2841
|
-
logger.error(`Failed to install version: ${error}`);
|
|
3500
|
+
logger.error(`Failed to install version: ${formatErrorWithCause(error)}`);
|
|
2842
3501
|
process.exit(1);
|
|
2843
3502
|
}
|
|
2844
3503
|
}
|