From a79aa109bb342ff749bb4f42c18eea1315ae67bf Mon Sep 17 00:00:00 2001 From: OYX-1 <74037789+OYX-1@users.noreply.github.com> Date: Thu, 9 Nov 2023 21:44:35 +0800 Subject: [PATCH] =?UTF-8?q?fix(protal-web):=20=E6=96=87=E4=BB=B6=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E4=BC=9A=E5=9B=A0=E4=B8=BAsftp=E6=B6=88=E6=81=AF?= =?UTF-8?q?=E8=BF=87=E9=95=BF=E6=8A=A5500=E9=94=99=E8=AF=AF=20(#957)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 前提:在.bashrc文件中输入较长的欢迎语 ![image](https://github.com/PKUHPC/SCOW/assets/74037789/c32f1d1c-e7ca-4954-b26b-c1caa51c0706) ## 之前:文件管理和交互式应用(只要涉及ssh连接的地方都有这个问题)因为使用sftp获取家目录,如果欢迎语过多,会导致sftp消息过长报500错误。 ![image](https://github.com/PKUHPC/SCOW/assets/74037789/1fc54f28-bd54-476e-8dbb-a85b4d2aeea1) ## 现在:捕获了这个错误,并提示用户缩减欢迎语。 ![image](https://github.com/PKUHPC/SCOW/assets/74037789/0ca3f6e3-f4ed-4c52-97ee-95c936431f52) --- .changeset/khaki-rockets-switch.md | 6 ++++++ apps/portal-server/src/utils/ssh.ts | 2 +- apps/portal-web/src/i18n/en.ts | 2 ++ apps/portal-web/src/i18n/zh_cn.ts | 2 +- apps/portal-web/src/pages/_app.tsx | 9 ++++++++- apps/portal-web/src/utils/route.ts | 4 +++- libs/ssh/src/ssh.ts | 13 ++++++++++++- 7 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 .changeset/khaki-rockets-switch.md diff --git a/.changeset/khaki-rockets-switch.md b/.changeset/khaki-rockets-switch.md new file mode 100644 index 0000000000..de54f16036 --- /dev/null +++ b/.changeset/khaki-rockets-switch.md @@ -0,0 +1,6 @@ +--- +"@scow/portal-web": patch +"@scow/lib-ssh": patch +--- + +sshConnect 时,提示语过长会使得连接失败,现在捕获了这个错误并提示用户 diff --git a/apps/portal-server/src/utils/ssh.ts b/apps/portal-server/src/utils/ssh.ts index 648dec3eaf..e23eeae3ba 100644 --- a/apps/portal-server/src/utils/ssh.ts +++ b/apps/portal-server/src/utils/ssh.ts @@ -88,7 +88,7 @@ export async function sshConnect( code: status.INTERNAL, details: e.message, message: e.message, - metadata: scowErrorMetadata(SSH_ERROR_CODE), + metadata: scowErrorMetadata(SSH_ERROR_CODE, typeof e.cause === "string" ? { cause:e.cause } : undefined), }); } diff --git a/apps/portal-web/src/i18n/en.ts b/apps/portal-web/src/i18n/en.ts index 2e836482e7..0626bd6bac 100644 --- a/apps/portal-web/src/i18n/en.ts +++ b/apps/portal-web/src/i18n/en.ts @@ -457,6 +457,8 @@ export default { _app: { sshError: "Unable to connect as a user to the login node. Please make sure the permissions " + "of your home directory are 700, 750, or 755.", + textExceedsLength:"There are too many welcome messages for terminal login." + + "Please reduce unnecessary information output!", sftpError: "SFTP operation failed. Please confirm if you have the necessary permissions.", otherError: "Server encountered an error!", }, diff --git a/apps/portal-web/src/i18n/zh_cn.ts b/apps/portal-web/src/i18n/zh_cn.ts index db1a0c3b51..48bc10d0be 100644 --- a/apps/portal-web/src/i18n/zh_cn.ts +++ b/apps/portal-web/src/i18n/zh_cn.ts @@ -455,8 +455,8 @@ export default { }, }, _app: { + textExceedsLength:"终端登录欢迎提示信息过多,请减少不必要的信息输出!", sshError:"无法以用户身份连接到登录节点。请确认您的家目录的权限为700、750或者755", - sftpError:"SFTP操作失败,请确认您是否有操作的权限", otherError:"服务器出错啦!", }, diff --git a/apps/portal-web/src/pages/_app.tsx b/apps/portal-web/src/pages/_app.tsx index 08cc685b0b..cdaef4ea39 100644 --- a/apps/portal-web/src/pages/_app.tsx +++ b/apps/portal-web/src/pages/_app.tsx @@ -59,11 +59,18 @@ const FailEventHandler: React.FC = () => { return; } + const regex = /exceeds max length/; + // 如果终端登录欢迎语过长会报错:Packet length xxxx exceeds max length of 262144 + if (regex.test(e.data?.message)) { + message.error(t("pages._app.textExceedsLength")); + return; + } + if (e.data?.code === "SSH_ERROR") { message.error(t("pages._app.sshError")); return; } - + if (e.data?.code === "SFTP_ERROR") { message.error(e.data?.details.length > 150 ? e.data?.details.substring(0, 150) + "..." : e.data?.details || t("pages._app.sftpError")); diff --git a/apps/portal-web/src/utils/route.ts b/apps/portal-web/src/utils/route.ts index 96ac23e479..2a515904e0 100644 --- a/apps/portal-web/src/utils/route.ts +++ b/apps/portal-web/src/utils/route.ts @@ -21,11 +21,13 @@ export const route: typeof typeboxRoute = (schema, handler) => { if (!(e.metadata instanceof Metadata)) { throw e; } const SCOW_ERROR = (e.metadata as Metadata).get("IS_SCOW_ERROR"); + const SCOW_CAUSE = (e.metadata as Metadata).get("cause"); if (SCOW_ERROR.length === 0) { throw e; } const code = e.metadata.get("SCOW_ERROR_CODE")[0].toString(); const details = e.details; - return { 500: { code, details } } as any; + const message = SCOW_CAUSE[0]; + return { 500: { code, details, message } } as any; }); } }); diff --git a/libs/ssh/src/ssh.ts b/libs/ssh/src/ssh.ts index 1164c618ef..8969fbbac9 100644 --- a/libs/ssh/src/ssh.ts +++ b/libs/ssh/src/ssh.ts @@ -93,7 +93,18 @@ export async function sshConnect( ) { const ssh = await sshRawConnect(address, username, rootKeyPair, logger); - return run(ssh).finally(() => { ssh.dispose(); }); + return run(ssh) + .catch((e) => { + // 若在run回调函数中有具体抛错,直接抛出 + if (e.code !== undefined) { + throw e; + } + else { + logger.info("Running ssh failed."); + throw new SshConnectError({ cause: e.message }); + } + }) + .finally(() => { ssh.dispose(); }); } export async function sshConnectByPassword(