dsh-remote-go 0.3.0 → 0.3.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.
- package/README.md +1 -0
- package/dist/client.js +1348 -2095
- package/dist/src/admission.js +3 -28
- package/dist/src/api.js +37 -99
- package/dist/src/atomic-json.js +32 -66
- package/dist/src/bootstrap.js +17 -27
- package/dist/src/connect/attach.js +3 -25
- package/dist/src/connect/bootstrap.js +2 -8
- package/dist/src/connect/failures.js +3 -18
- package/dist/src/connect/guards.js +13 -8
- package/dist/src/connect/launch.js +11 -21
- package/dist/src/connect/links.js +11 -27
- package/dist/src/connect/ownership.js +33 -114
- package/dist/src/connect/pipeline.js +62 -159
- package/dist/src/connect/reattach.js +26 -44
- package/dist/src/connect/registry.js +0 -1
- package/dist/src/connect/repair.js +8 -37
- package/dist/src/connect/restart.js +36 -97
- package/dist/src/connect/stop.js +16 -50
- package/dist/src/connect/transport.js +10 -18
- package/dist/src/connect/verify.js +3 -12
- package/dist/src/connect/watchdog.js +6 -38
- package/dist/src/connect-log.js +16 -41
- package/dist/src/connect-progress.js +13 -45
- package/dist/src/constants.js +18 -43
- package/dist/src/context.js +13 -32
- package/dist/src/diagnostics.js +56 -25
- package/dist/src/download-jobs.js +11 -20
- package/dist/src/errors.js +175 -190
- package/dist/src/events.js +20 -84
- package/dist/src/host-lifecycle.js +69 -177
- package/dist/src/host-registry.js +27 -78
- package/dist/src/host-runtime.js +0 -9
- package/dist/src/host-view.js +6 -29
- package/dist/src/index.js +15 -35
- package/dist/src/kernel-adapter.js +34 -80
- package/dist/src/key-files.js +10 -23
- package/dist/src/known-hosts.js +13 -34
- package/dist/src/layout.js +3 -20
- package/dist/src/local-download.js +94 -163
- package/dist/src/local-ssh.js +12 -19
- package/dist/src/local-version.js +35 -49
- package/dist/src/node/download.js +1 -4
- package/dist/src/node-runtime.js +19 -38
- package/dist/src/probe.js +6 -7
- package/dist/src/prompts.js +56 -128
- package/dist/src/proxy/cookies.js +26 -60
- package/dist/src/proxy/headers.js +30 -125
- package/dist/src/proxy/http.js +33 -41
- package/dist/src/proxy/index.js +20 -34
- package/dist/src/proxy/limits.js +4 -6
- package/dist/src/proxy/routes.js +10 -17
- package/dist/src/proxy/upgrade.js +27 -42
- package/dist/src/redact.js +14 -33
- package/dist/src/remote-files.js +9 -21
- package/dist/src/remote-path.js +21 -62
- package/dist/src/remote-proc.js +35 -103
- package/dist/src/remote-web/registry.js +10 -50
- package/dist/src/remote-web/resolve.js +23 -104
- package/dist/src/remote-web/start.js +27 -64
- package/dist/src/remote-web/stop.js +6 -25
- package/dist/src/request-trust.js +15 -32
- package/dist/src/runtime/dispatch.js +33 -143
- package/dist/src/runtime/effects.js +7 -17
- package/dist/src/runtime/events.js +1 -1
- package/dist/src/runtime/fsm.js +11 -61
- package/dist/src/runtime/rules.js +121 -199
- package/dist/src/secrets.js +15 -38
- package/dist/src/service.js +22 -128
- package/dist/src/settings.js +41 -42
- package/dist/src/ssh-config.js +22 -41
- package/dist/src/ssh-failures.js +23 -74
- package/dist/src/ssh-sftp.js +47 -86
- package/dist/src/ssh.js +99 -179
- package/dist/src/store.js +31 -48
- package/dist/src/tool-shared.js +17 -52
- package/dist/src/tools-exec-policy.js +33 -79
- package/dist/src/tools-exec.js +87 -151
- package/dist/src/tools-report.js +100 -167
- package/dist/src/tools.js +59 -133
- package/dist/src/tunnel.js +9 -27
- package/dist/src/util.js +19 -56
- package/dist/src/version.js +6 -12
- package/dist/src/watchdog-bus.js +0 -8
- package/dist/src/watchdog.js +7 -47
- package/package.json +3 -3
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* the local directory the user chose; nothing is buffered in the Host. Jobs publish
|
|
4
|
-
* progress and expire so a closed browser cannot pin job slots forever.
|
|
5
|
-
*/
|
|
1
|
+
// Host-side download jobs: each job streams one remote file or folder straight to the chosen local
|
|
2
|
+
// directory, publishing progress as it goes, and expires so a closed browser cannot pin a slot.
|
|
6
3
|
import { randomUUID } from 'node:crypto';
|
|
7
4
|
import { errors, toErrorView } from './errors.js';
|
|
8
5
|
import { normalizeRemoteFilePath, remoteFileName } from './remote-path.js';
|
|
@@ -15,15 +12,17 @@ export const MAX_DOWNLOAD_JOBS = 4;
|
|
|
15
12
|
export const MAX_PREPARING_DOWNLOADS = 2;
|
|
16
13
|
/** Minimum interval between progress frames for one job. */
|
|
17
14
|
const PROGRESS_INTERVAL_MS = 120;
|
|
15
|
+
/** A positive safe integer override, or the production default. */
|
|
16
|
+
function positiveInt(value, fallback) {
|
|
17
|
+
return Number.isSafeInteger(value) && value > 0 ? value : fallback;
|
|
18
|
+
}
|
|
18
19
|
export function createDownloadJobs(options) {
|
|
19
20
|
const emit = typeof options.emit === 'function' ? options.emit : () => { };
|
|
20
21
|
const logger = options.logger ?? console;
|
|
21
22
|
const readDownload = typeof options.readDownload === 'function' ? options.readDownload : readHostDownload;
|
|
22
|
-
const ttlMs =
|
|
23
|
-
const maxJobs =
|
|
24
|
-
const maxPreparing =
|
|
25
|
-
? options.maxPreparing
|
|
26
|
-
: MAX_PREPARING_DOWNLOADS;
|
|
23
|
+
const ttlMs = positiveInt(options.ttlMs, DOWNLOAD_JOB_TTL_MS);
|
|
24
|
+
const maxJobs = positiveInt(options.maxJobs, MAX_DOWNLOAD_JOBS);
|
|
25
|
+
const maxPreparing = positiveInt(options.maxPreparing, MAX_PREPARING_DOWNLOADS);
|
|
27
26
|
const now = typeof options.now === 'function' ? options.now : Date.now;
|
|
28
27
|
const jobs = new Map();
|
|
29
28
|
const preparingCount = () => [...jobs.values()].filter((job) => job.phase === 'preparing').length;
|
|
@@ -141,13 +140,7 @@ export function createDownloadJobs(options) {
|
|
|
141
140
|
}
|
|
142
141
|
};
|
|
143
142
|
return {
|
|
144
|
-
/**
|
|
145
|
-
* Create and start a download job.
|
|
146
|
-
* @param runtime - connected host runtime.
|
|
147
|
-
* @param rawPath - absolute remote file or folder path.
|
|
148
|
-
* @param options - local destination for a folder job.
|
|
149
|
-
* @returns the initial job view (phase `preparing`).
|
|
150
|
-
*/
|
|
143
|
+
/** Create and start a download job; returns the initial view (phase `preparing`). */
|
|
151
144
|
start(runtime, rawPath, options = {}) {
|
|
152
145
|
const path = normalizeRemoteFilePath(rawPath);
|
|
153
146
|
if (jobs.size >= maxJobs) {
|
|
@@ -179,12 +172,11 @@ export function createDownloadJobs(options) {
|
|
|
179
172
|
doneBytes: 0,
|
|
180
173
|
totalFiles: 0,
|
|
181
174
|
doneFiles: 0,
|
|
175
|
+
ignoredNames: [],
|
|
182
176
|
destination: typeof options.destination === 'string' && options.destination !== '' ? options.destination : null,
|
|
183
|
-
// The local home root the destination policy must judge against; not part of the view.
|
|
184
177
|
home: typeof options.home === 'string' && options.home !== '' ? options.home : undefined,
|
|
185
178
|
startedAt: new Date(now()).toISOString(),
|
|
186
179
|
error: null,
|
|
187
|
-
ignoredNames: [],
|
|
188
180
|
timer: null,
|
|
189
181
|
lastEmit: 0,
|
|
190
182
|
cancelled: false,
|
|
@@ -215,7 +207,6 @@ export function createDownloadJobs(options) {
|
|
|
215
207
|
jobs.delete(job.id);
|
|
216
208
|
return true;
|
|
217
209
|
},
|
|
218
|
-
/** Number of retained jobs, for tests/diagnostics. */
|
|
219
210
|
get size() {
|
|
220
211
|
return jobs.size;
|
|
221
212
|
},
|
package/dist/src/errors.js
CHANGED
|
@@ -1,89 +1,148 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Coded, bilingual errors; `toErrorView` is the only shape the Client ever sees.
|
|
3
|
-
*/
|
|
1
|
+
/** Coded, bilingual errors; `toErrorView` is the only shape the Client ever sees. */
|
|
4
2
|
import { redactObject, redactText } from './redact.js';
|
|
5
3
|
import { headTail } from './util.js';
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
});
|
|
27
|
-
const CODE_TABLE = {
|
|
28
|
-
[ErrorCode.NETWORK]: { retryable: true, title: { zh: '连不上这台服务器', en: 'Cannot reach this server' } },
|
|
29
|
-
[ErrorCode.AUTH]: { retryable: true, title: { zh: 'SSH 认证没有通过', en: 'SSH authentication failed' } },
|
|
30
|
-
[ErrorCode.HOST_KEY_CHANGED]: { retryable: false, title: { zh: '主机指纹变了', en: 'The host key changed' } },
|
|
31
|
-
[ErrorCode.HOST_KEY_UNKNOWN]: { retryable: true, title: { zh: '确认服务器指纹', en: 'Confirm the host key' } },
|
|
32
|
-
[ErrorCode.REMOTE_DSH_MISSING]: {
|
|
33
|
-
retryable: true,
|
|
34
|
-
title: { zh: '远端没有可用的 DSH', en: 'No usable DSH on the remote host' },
|
|
35
|
-
},
|
|
36
|
-
[ErrorCode.REMOTE_NODE_INSTALL_FAILED]: {
|
|
37
|
-
retryable: true,
|
|
38
|
-
title: { zh: '远端 Node 自动安装失败', en: 'Automatic Node installation failed' },
|
|
39
|
-
},
|
|
40
|
-
[ErrorCode.REMOTE_DSH_START_FAILED]: {
|
|
41
|
-
retryable: true,
|
|
42
|
-
title: { zh: '远端 DSH 启动失败', en: 'The remote DSH failed to start' },
|
|
43
|
-
},
|
|
44
|
-
[ErrorCode.REMOTE_DSH_RUNNING]: {
|
|
45
|
-
retryable: true,
|
|
46
|
-
title: { zh: '远端已有手工启动的 DSH', en: 'A manually started DSH is already running' },
|
|
47
|
-
},
|
|
48
|
-
[ErrorCode.REMOTE_UI_UNREACHABLE]: {
|
|
49
|
-
retryable: true,
|
|
50
|
-
title: { zh: '远端界面打不开', en: 'The remote interface is unreachable' },
|
|
51
|
-
},
|
|
52
|
-
[ErrorCode.REMOTE_UNREACHABLE]: {
|
|
53
|
-
retryable: true,
|
|
54
|
-
title: { zh: '远端 DSH 已不在运行', en: 'The remote DSH is no longer running' },
|
|
55
|
-
},
|
|
56
|
-
[ErrorCode.RESTART_UNAVAILABLE]: {
|
|
57
|
-
retryable: true,
|
|
58
|
-
title: { zh: '现在不能重启远端 DSH', en: 'The remote DSH cannot be restarted now' },
|
|
59
|
-
},
|
|
60
|
-
[ErrorCode.STOP_UNAVAILABLE]: {
|
|
61
|
-
retryable: true,
|
|
62
|
-
title: { zh: '现在不能关闭远端 DSH', en: 'The remote DSH cannot be stopped now' },
|
|
63
|
-
},
|
|
64
|
-
[ErrorCode.REMOTE_FILE_UNAVAILABLE]: {
|
|
65
|
-
retryable: true,
|
|
66
|
-
title: { zh: '无法读取远端文件', en: 'Cannot read the remote file' },
|
|
67
|
-
},
|
|
68
|
-
[ErrorCode.DOWNLOAD_NOT_READY]: {
|
|
69
|
-
retryable: true,
|
|
70
|
-
title: { zh: '下载尚未准备好', en: 'The download is not ready' },
|
|
71
|
-
},
|
|
72
|
-
[ErrorCode.DOWNLOAD_BUSY]: {
|
|
73
|
-
retryable: true,
|
|
74
|
-
title: { zh: '下载任务太多', en: 'Too many downloads are running' },
|
|
75
|
-
},
|
|
76
|
-
[ErrorCode.VERSION_MISMATCH]: {
|
|
77
|
-
retryable: true,
|
|
78
|
-
title: { zh: '远端 DSH 版本与本机不一致', en: 'Remote DSH version differs from this machine' },
|
|
79
|
-
},
|
|
80
|
-
[ErrorCode.UNSUPPORTED_OS]: {
|
|
4
|
+
const say = (zh, en) => ({ zh, en });
|
|
5
|
+
/** Every coded error: the Client's title, the retry default, and the detail and steps a bare call renders. */
|
|
6
|
+
const CATALOGUE = {
|
|
7
|
+
network: {
|
|
8
|
+
title: say('连不上这台服务器', 'Cannot reach this server'),
|
|
9
|
+
detail: say('网络不可达,可能被防火墙拦截或地址写错。', 'The network is unreachable — check the address, port and firewall.'),
|
|
10
|
+
steps: [
|
|
11
|
+
['检查地址、端口与网络连通性', 'Check the address, port and network reachability'],
|
|
12
|
+
['如果有跳板机,先确认跳板机可达', 'If a jump host is configured, verify it first'],
|
|
13
|
+
],
|
|
14
|
+
},
|
|
15
|
+
auth: {
|
|
16
|
+
title: say('SSH 认证没有通过', 'SSH authentication failed'),
|
|
17
|
+
detail: say('远端拒绝了这次 SSH 认证。', 'The remote host rejected this SSH authentication.'),
|
|
18
|
+
steps: [
|
|
19
|
+
['检查用户名与密钥 / SSH Agent', 'Check the user name and key / SSH agent'],
|
|
20
|
+
['确认密钥文件路径与权限(0600)', 'Confirm the key file path and its 0600 permissions'],
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
'host-key-changed': {
|
|
81
24
|
retryable: false,
|
|
82
|
-
title:
|
|
25
|
+
title: say('主机指纹变了', 'The host key changed'),
|
|
26
|
+
},
|
|
27
|
+
'host-key-unknown': {
|
|
28
|
+
title: say('确认服务器指纹', 'Confirm the host key'),
|
|
29
|
+
},
|
|
30
|
+
'remote-dsh-missing': {
|
|
31
|
+
title: say('远端没有可用的 DSH', 'No usable DSH on the remote host'),
|
|
32
|
+
detail: say('远端没有找到可用的 DSH,本机也无法自动准备运行环境。', 'No usable DSH was found and the runtime could not be prepared automatically.'),
|
|
33
|
+
steps: [
|
|
34
|
+
['确认远端可以访问网络,或配置离线包', 'Check remote network access, or configure an offline package'],
|
|
35
|
+
['也可以在远端手动安装 DSH 后重试', 'You can also install DSH manually on the remote host and retry'],
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
'remote-node-install-failed': {
|
|
39
|
+
title: say('远端 Node 自动安装失败', 'Automatic Node installation failed'),
|
|
40
|
+
detail: say('远端没有可用的 Node,自动安装也没有成功。', 'The remote has no usable Node and automatic installation did not succeed.'),
|
|
41
|
+
steps: [
|
|
42
|
+
[
|
|
43
|
+
'让远端可以访问 nodejs.org 或 npmmirror.com 后重试',
|
|
44
|
+
'Allow the remote to reach nodejs.org or npmmirror.com and retry',
|
|
45
|
+
],
|
|
46
|
+
[
|
|
47
|
+
'确认远端磁盘 ≥ 400 MB,且是受支持的 glibc 架构(musl/Alpine 不支持)',
|
|
48
|
+
'Make sure the remote has >= 400 MB free and a supported glibc architecture (musl/Alpine is not supported)',
|
|
49
|
+
],
|
|
50
|
+
],
|
|
51
|
+
},
|
|
52
|
+
'remote-dsh-start-failed': {
|
|
53
|
+
title: say('远端 DSH 启动失败', 'The remote DSH failed to start'),
|
|
54
|
+
},
|
|
55
|
+
'remote-dsh-running': {
|
|
56
|
+
title: say('远端已有手工启动的 DSH', 'A manually started DSH is already running'),
|
|
57
|
+
detail: say('远端检测到不是本插件启动的 DSH 进程,连接已按你的选择取消。', 'The remote has a DSH process this plugin did not start; the connection was cancelled as you chose.'),
|
|
58
|
+
steps: [
|
|
59
|
+
[
|
|
60
|
+
'重新连接,并选择「停止它并启动受管实例」或「保留它,另起一个」',
|
|
61
|
+
'Reconnect and choose "Stop it and start the managed instance" or "Keep it and start alongside"',
|
|
62
|
+
],
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
'remote-ui-unreachable': {
|
|
66
|
+
title: say('远端界面打不开', 'The remote interface is unreachable'),
|
|
67
|
+
detail: say('隧道的本地回环端口无法完成远端界面的鉴权握手。', 'The loopback tunnel could not complete the remote UI authentication handshake.'),
|
|
68
|
+
steps: [
|
|
69
|
+
['点「重连」重试一次', 'Retry with Reconnect'],
|
|
70
|
+
['查看诊断中的隧道与界面可达性检查', 'Check tunnel and UI reachability in diagnostics'],
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
'remote-unreachable': {
|
|
74
|
+
title: say('远端 DSH 已不在运行', 'The remote DSH is no longer running'),
|
|
75
|
+
detail: say('远端 DSH 已经停止响应,而且没有找到可以重新挂载的实例;主机配置保留。', 'The remote DSH stopped responding and no instance could be re-attached to; the host configuration is kept.'),
|
|
76
|
+
steps: [
|
|
77
|
+
[
|
|
78
|
+
'点「重启」用同一份配置重新拉起远端进程',
|
|
79
|
+
'Use "Restart" to start the remote process again with the same settings',
|
|
80
|
+
],
|
|
81
|
+
['点「重连」按存活策略重新连接', 'Use Reconnect to connect again under the keep-alive policy'],
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
'restart-unavailable': {
|
|
85
|
+
title: say('现在不能重启远端 DSH', 'The remote DSH cannot be restarted now'),
|
|
86
|
+
detail: say('只有已连接、或远端不可达但仍保留 SSH 连接的主机才能重启远端 DSH。', 'The remote DSH can only be restarted while this host is connected, or after a remote-unreachable failure that kept the SSH session.'),
|
|
87
|
+
steps: [
|
|
88
|
+
['先连接这台主机,再点「重启」', 'Connect the host first, then use "Restart"'],
|
|
89
|
+
['如果连接已断开,点「重连」重新建立连接', 'If the link dropped, use Reconnect to establish it again'],
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
'stop-unavailable': {
|
|
93
|
+
title: say('现在不能关闭远端 DSH', 'The remote DSH cannot be stopped now'),
|
|
94
|
+
detail: say('只有已连接、或远端不可达但仍保留 SSH 连接的主机才能关闭远端 DSH,而且只能关闭本连接启动或接管的那一个进程。', 'The remote DSH can only be stopped while this host is connected (or after a remote-unreachable failure that kept the SSH session), and only when it is the process this connection launched or took over.'),
|
|
95
|
+
steps: [
|
|
96
|
+
['先连接这台主机,再点「关闭」', 'Connect the host first, then use "Stop"'],
|
|
97
|
+
[
|
|
98
|
+
'如果强烈怀疑远端进程不属于本连接,点「重连」重建连接后再试',
|
|
99
|
+
'If the remote process may not belong to this connection, use Reconnect and try again',
|
|
100
|
+
],
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
'remote-file-unavailable': {
|
|
104
|
+
title: say('无法读取远端文件', 'Cannot read the remote file'),
|
|
105
|
+
detail: say('远端路径不存在、不可读,或无法写入本地保存位置。', 'The remote path does not exist, is not readable, or the local destination cannot be written.'),
|
|
106
|
+
steps: [
|
|
107
|
+
['确认文件仍在远端,且当前 SSH 用户可以读取', 'Confirm the file still exists and the SSH user can read it'],
|
|
108
|
+
[
|
|
109
|
+
'检查文件大小;过大的文件请先在远端压缩或拆分',
|
|
110
|
+
'Check the file size; compress or split large files on the remote first',
|
|
111
|
+
],
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
'download-not-ready': {
|
|
115
|
+
title: say('下载尚未准备好', 'The download is not ready'),
|
|
116
|
+
detail: say('这个下载还在准备中,或已经失效;请重新发起下载。', 'This download is still being prepared or has expired; start it again.'),
|
|
117
|
+
steps: [
|
|
118
|
+
['等待进度条完成后再试', 'Wait for the progress bar to finish and retry'],
|
|
119
|
+
['如果任务已失效,从远端文件树重新下载', 'If it expired, start the download again from the remote file tree'],
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
'download-busy': {
|
|
123
|
+
title: say('下载任务太多', 'Too many downloads are running'),
|
|
124
|
+
detail: say('同时准备的下载任务过多,请等一个完成后再试。', 'Too many downloads are being prepared at once; wait for one to finish and retry.'),
|
|
125
|
+
steps: [['取消不需要的下载,或稍后重试', 'Cancel an unneeded download, or retry later']],
|
|
126
|
+
},
|
|
127
|
+
'version-mismatch': {
|
|
128
|
+
title: say('远端 DSH 版本与本机不一致', 'Remote DSH version differs from this machine'),
|
|
129
|
+
},
|
|
130
|
+
'unsupported-os': {
|
|
131
|
+
retryable: false,
|
|
132
|
+
title: say('远端系统暂不支持', 'This remote system is not supported yet'),
|
|
133
|
+
},
|
|
134
|
+
'invalid-input': {
|
|
135
|
+
retryable: false,
|
|
136
|
+
title: say('填写的信息有误', 'Some fields are invalid'),
|
|
137
|
+
},
|
|
138
|
+
internal: {
|
|
139
|
+
title: say('插件内部错误', 'Internal plugin error'),
|
|
83
140
|
},
|
|
84
|
-
[ErrorCode.INVALID_INPUT]: { retryable: false, title: { zh: '填写的信息有误', en: 'Some fields are invalid' } },
|
|
85
|
-
[ErrorCode.INTERNAL]: { retryable: true, title: { zh: '插件内部错误', en: 'Internal plugin error' } },
|
|
86
141
|
};
|
|
142
|
+
/** One catalogue row by code, or `undefined` for a code this build does not know. */
|
|
143
|
+
function rowOf(code) {
|
|
144
|
+
return code in CATALOGUE ? CATALOGUE[code] : undefined;
|
|
145
|
+
}
|
|
87
146
|
export class RemoteGoError extends Error {
|
|
88
147
|
constructor(code, detail, options = {}) {
|
|
89
148
|
super(`${code}: ${detail.en}`);
|
|
@@ -92,53 +151,31 @@ export class RemoteGoError extends Error {
|
|
|
92
151
|
this.detail = detail;
|
|
93
152
|
this.nextSteps = options.nextSteps ?? [];
|
|
94
153
|
this.technical = options.technical;
|
|
95
|
-
this.retryable = options.retryable ??
|
|
154
|
+
this.retryable = options.retryable ?? rowOf(code)?.retryable ?? true;
|
|
96
155
|
}
|
|
97
156
|
}
|
|
98
|
-
const say = (zh, en) => ({ zh, en });
|
|
99
157
|
function fail(code, detail, steps, options = {}) {
|
|
100
158
|
return new RemoteGoError(code, detail, { nextSteps: steps.map(([zh, en]) => say(zh, en)), ...options });
|
|
101
159
|
}
|
|
160
|
+
/** The entry for one plain catalogue row: a caller-supplied detail wins over the default. */
|
|
161
|
+
function plain(code) {
|
|
162
|
+
const row = CATALOGUE[code];
|
|
163
|
+
return (detail = { ...row.detail }, options) => fail(code, detail, row.steps, options);
|
|
164
|
+
}
|
|
102
165
|
export const errors = {
|
|
103
|
-
network: (
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
], options),
|
|
107
|
-
auth: (detail = say('远端拒绝了这次 SSH 认证。', 'The remote host rejected this SSH authentication.'), options) => fail(ErrorCode.AUTH, detail, [
|
|
108
|
-
['检查用户名与密钥 / SSH Agent', 'Check the user name and key / SSH agent'],
|
|
109
|
-
['确认密钥文件路径与权限(0600)', 'Confirm the key file path and its 0600 permissions'],
|
|
110
|
-
], options),
|
|
111
|
-
hostKeyChanged: (pinned, actual) => fail(ErrorCode.HOST_KEY_CHANGED, say(`主机指纹和已记录的不一致:记录 ${pinned},实际 ${actual}。`, `The host key no longer matches the pinned value: pinned ${pinned}, actual ${actual}.`), [
|
|
166
|
+
network: plain('network'),
|
|
167
|
+
auth: plain('auth'),
|
|
168
|
+
hostKeyChanged: (pinned, actual) => fail('host-key-changed', say(`主机指纹和已记录的不一致:记录 ${pinned},实际 ${actual}。`, `The host key no longer matches the pinned value: pinned ${pinned}, actual ${actual}.`), [
|
|
112
169
|
[
|
|
113
170
|
'确认服务器是否重装或更换了证书;确认后再更新指纹',
|
|
114
171
|
'Confirm the server was not reinstalled or tampered with before updating the pin',
|
|
115
172
|
],
|
|
116
173
|
], { retryable: false, technical: `pinned=${pinned} actual=${actual}` }),
|
|
117
|
-
hostKeyUnknown: (fingerprint) => fail(
|
|
118
|
-
remoteDshMissing: (
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
]),
|
|
123
|
-
nodeInstallFailed: (detail, options) => fail(ErrorCode.REMOTE_NODE_INSTALL_FAILED, detail ??
|
|
124
|
-
say('远端没有可用的 Node,自动安装也没有成功。', 'The remote has no usable Node and automatic installation did not succeed.'), [
|
|
125
|
-
[
|
|
126
|
-
'让远端可以访问 nodejs.org 或 npmmirror.com 后重试',
|
|
127
|
-
'Allow the remote to reach nodejs.org or npmmirror.com and retry',
|
|
128
|
-
],
|
|
129
|
-
[
|
|
130
|
-
'确认远端磁盘 ≥ 400 MB,且是受支持的 glibc 架构(musl/Alpine 不支持)',
|
|
131
|
-
'Make sure the remote has >= 400 MB free and a supported glibc architecture (musl/Alpine is not supported)',
|
|
132
|
-
],
|
|
133
|
-
], options),
|
|
134
|
-
remoteDshRunning: (detail, options) => fail(ErrorCode.REMOTE_DSH_RUNNING, detail ??
|
|
135
|
-
say('远端检测到不是本插件启动的 DSH 进程,连接已按你的选择取消。', 'The remote has a DSH process this plugin did not start; the connection was cancelled as you chose.'), [
|
|
136
|
-
[
|
|
137
|
-
'重新连接,并选择「停止它并启动受管实例」或「保留它,另起一个」',
|
|
138
|
-
'Reconnect and choose "Stop it and start the managed instance" or "Keep it and start alongside"',
|
|
139
|
-
],
|
|
140
|
-
], options),
|
|
141
|
-
remoteDshStartFailed: (tail) => fail(ErrorCode.REMOTE_DSH_START_FAILED, say('远端 DSH 进程没有成功打印 Web 地址,可能启动即失败。', 'The remote DSH process did not print its Web URL; startup likely failed.'), [
|
|
174
|
+
hostKeyUnknown: (fingerprint) => fail('host-key-unknown', say(`首次连接该服务器(指纹 ${fingerprint}),需要你确认。`, `First connection to this host (fingerprint ${fingerprint}); confirmation required.`), [['核对指纹后选择「接受并记住」或取消', 'Verify the fingerprint, then accept and remember it or cancel']]),
|
|
175
|
+
remoteDshMissing: plain('remote-dsh-missing'),
|
|
176
|
+
nodeInstallFailed: plain('remote-node-install-failed'),
|
|
177
|
+
remoteDshRunning: plain('remote-dsh-running'),
|
|
178
|
+
remoteDshStartFailed: (tail) => fail('remote-dsh-start-failed', say('远端 DSH 进程没有成功打印 Web 地址,可能启动即失败。', 'The remote DSH process did not print its Web URL; startup likely failed.'), [
|
|
142
179
|
['查看诊断里的远端日志尾部', 'Inspect the remote log tail in diagnostics'],
|
|
143
180
|
['确认远端磁盘空间与端口可用', 'Check remote disk space and usable ports'],
|
|
144
181
|
[
|
|
@@ -146,88 +183,36 @@ export const errors = {
|
|
|
146
183
|
'Retry, or verify `dsh --profile web --no-open` manually on the remote host',
|
|
147
184
|
],
|
|
148
185
|
], { technical: tail }),
|
|
149
|
-
remoteUiUnreachable: (
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
[
|
|
162
|
-
'点「重启」用同一份配置重新拉起远端进程',
|
|
163
|
-
'Use "Restart" to start the remote process again with the same settings',
|
|
164
|
-
],
|
|
165
|
-
['点「重连」按存活策略重新连接', 'Use Reconnect to connect again under the keep-alive policy'],
|
|
166
|
-
], options),
|
|
167
|
-
/**
|
|
168
|
-
* One-shot restart requested in a state that cannot support it (not connected, no live
|
|
169
|
-
* SSH, or already busy with another action). The HTTP API answers 409 for this.
|
|
170
|
-
*/
|
|
171
|
-
restartUnavailable: (detail, options) => fail(ErrorCode.RESTART_UNAVAILABLE, detail ??
|
|
172
|
-
say('只有已连接、或远端不可达但仍保留 SSH 连接的主机才能重启远端 DSH。', 'The remote DSH can only be restarted while this host is connected, or after a remote-unreachable failure that kept the SSH session.'), [
|
|
173
|
-
['先连接这台主机,再点「重启」', 'Connect the host first, then use "Restart"'],
|
|
174
|
-
['如果连接已断开,点「重连」重新建立连接', 'If the link dropped, use Reconnect to establish it again'],
|
|
175
|
-
], options),
|
|
176
|
-
/**
|
|
177
|
-
* The explicit "stop remote DSH" action was refused: wrong state, another link action in
|
|
178
|
-
* flight, or the bound process could not be proven to be this connection's own. The HTTP
|
|
179
|
-
* API answers 409 for this.
|
|
180
|
-
*/
|
|
181
|
-
stopRemoteUnavailable: (detail, options) => fail(ErrorCode.STOP_UNAVAILABLE, detail ??
|
|
182
|
-
say('只有已连接、或远端不可达但仍保留 SSH 连接的主机才能关闭远端 DSH,而且只能关闭本连接启动或接管的那一个进程。', 'The remote DSH can only be stopped while this host is connected (or after a remote-unreachable failure that kept the SSH session), and only when it is the process this connection launched or took over.'), [
|
|
183
|
-
['先连接这台主机,再点「关闭」', 'Connect the host first, then use "Stop"'],
|
|
184
|
-
[
|
|
185
|
-
'如果强烈怀疑远端进程不属于本连接,点「重连」重建连接后再试',
|
|
186
|
-
'If the remote process may not belong to this connection, use Reconnect and try again',
|
|
187
|
-
],
|
|
188
|
-
], options),
|
|
189
|
-
remoteFileUnavailable: (detail, options) => fail(ErrorCode.REMOTE_FILE_UNAVAILABLE, detail ??
|
|
190
|
-
say('远端路径不存在、不可读,或无法写入本地保存位置。', 'The remote path does not exist, is not readable, or the local destination cannot be written.'), [
|
|
191
|
-
['确认文件仍在远端,且当前 SSH 用户可以读取', 'Confirm the file still exists and the SSH user can read it'],
|
|
192
|
-
[
|
|
193
|
-
'检查文件大小;过大的文件请先在远端压缩或拆分',
|
|
194
|
-
'Check the file size; compress or split large files on the remote first',
|
|
195
|
-
],
|
|
196
|
-
], options),
|
|
197
|
-
downloadNotReady: (detail, options) => fail(ErrorCode.DOWNLOAD_NOT_READY, detail ??
|
|
198
|
-
say('这个下载还在准备中,或已经失效;请重新发起下载。', 'This download is still being prepared or has expired; start it again.'), [
|
|
199
|
-
['等待进度条完成后再试', 'Wait for the progress bar to finish and retry'],
|
|
200
|
-
['如果任务已失效,从远端文件树重新下载', 'If it expired, start the download again from the remote file tree'],
|
|
201
|
-
], options),
|
|
202
|
-
downloadBusy: (detail, options) => fail(ErrorCode.DOWNLOAD_BUSY, detail ??
|
|
203
|
-
say('同时准备的下载任务过多,请等一个完成后再试。', 'Too many downloads are being prepared at once; wait for one to finish and retry.'), [['取消不需要的下载,或稍后重试', 'Cancel an unneeded download, or retry later']], options),
|
|
204
|
-
versionMismatch: (local, remote) => fail(ErrorCode.VERSION_MISMATCH, say(`本机 DSH 是 ${local},远端是 ${remote};界面可能不一致,默认不静默混用。`, `This machine runs DSH ${local} while the remote runs ${remote}; the UI may differ and mixing silently is not allowed.`), [
|
|
186
|
+
remoteUiUnreachable: plain('remote-ui-unreachable'),
|
|
187
|
+
// Kept apart from `remote-ui-unreachable`: here the tunnel may be fine and the process is what is
|
|
188
|
+
// missing, which is what the restart button exists for.
|
|
189
|
+
remoteUnreachable: plain('remote-unreachable'),
|
|
190
|
+
// A restart is only offered while the host is connected or its SSH session survived a failure.
|
|
191
|
+
restartUnavailable: plain('restart-unavailable'),
|
|
192
|
+
// A stop must also prove the remote pid is the process this connection launched or took over.
|
|
193
|
+
stopRemoteUnavailable: plain('stop-unavailable'),
|
|
194
|
+
remoteFileUnavailable: plain('remote-file-unavailable'),
|
|
195
|
+
downloadNotReady: plain('download-not-ready'),
|
|
196
|
+
downloadBusy: plain('download-busy'),
|
|
197
|
+
versionMismatch: (local, remote) => fail('version-mismatch', say(`本机 DSH 是 ${local},远端是 ${remote};界面可能不一致,默认不静默混用。`, `This machine runs DSH ${local} while the remote runs ${remote}; the UI may differ and mixing silently is not allowed.`), [
|
|
205
198
|
['选择「准备同版本运行时」后重试(推荐)', 'Prepare a matching runtime and retry (recommended)'],
|
|
206
199
|
['明确选择「沿用远端版本」继续', 'Explicitly continue with the remote version'],
|
|
207
200
|
]),
|
|
208
|
-
unsupportedOs: (os) => fail(
|
|
209
|
-
invalidInput: (field, detail) => fail(
|
|
210
|
-
internal: (cause) => fail(
|
|
201
|
+
unsupportedOs: (os) => fail('unsupported-os', say(`V1 仅支持 Linux 远端,检测到 ${os}。`, `V1 supports Linux remotes only; detected ${os}.`), [['换一台 Linux 服务器,或等待后续版本', 'Use a Linux server, or wait for a later release']], { retryable: false }),
|
|
202
|
+
invalidInput: (field, detail) => fail('invalid-input', detail ?? say(`字段「${field}」不合法。`, `The field "${field}" is invalid.`), [['修正后重试', 'Fix it and retry']], { retryable: false }),
|
|
203
|
+
internal: (cause) => fail('internal', say('插件内部出现异常,可重试或查看诊断。', 'The plugin hit an internal error; retry or check diagnostics.'), [], { technical: cause instanceof Error ? `${cause.name}: ${cause.message}` : String(cause ?? '') }),
|
|
211
204
|
};
|
|
212
|
-
/**
|
|
213
|
-
* How much of one `ErrorView.technical` string the API will carry. The producers hand over
|
|
214
|
-
* captured process output (a remote `web.log` tail, an SFTP failure); the API response is the
|
|
215
|
-
* one place that must never carry the whole of it.
|
|
216
|
-
*/
|
|
205
|
+
/** How much of one `ErrorView.technical` string the API will carry: producers hand over captured process output. */
|
|
217
206
|
export const TECHNICAL_LIMIT = 1200;
|
|
218
|
-
/**
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
* line of a remote `web.log` is the launch URL with its session token. It is redacted and
|
|
222
|
-
* length-capped, then the whole view goes through `redactObject` so a detail/next-step that
|
|
223
|
-
* quotes one of those lines is covered too (docs/api.md: "已脱敏").
|
|
224
|
-
*/
|
|
207
|
+
/** The only ErrorView a caller may send: redaction is part of the contract, not an opt-in. `technical` is the risky
|
|
208
|
+
* field — the first line of a remote `web.log` is the launch URL with its session token — so it is redacted and
|
|
209
|
+
* length-capped first, then the whole view crosses `redactObject` so a detail quoting such a line is covered too. */
|
|
225
210
|
export function toErrorView(error) {
|
|
226
211
|
if (error instanceof RemoteGoError) {
|
|
227
|
-
const
|
|
212
|
+
const row = rowOf(error.code);
|
|
228
213
|
const view = {
|
|
229
214
|
code: error.code,
|
|
230
|
-
title:
|
|
215
|
+
title: row?.title ?? say('未知错误', 'Unknown error'),
|
|
231
216
|
detail: error.detail,
|
|
232
217
|
nextSteps: error.nextSteps,
|
|
233
218
|
retryable: error.retryable,
|