Skip to content

Commit

Permalink
fix(protal-web): 文件管理会因为sftp消息过长报500错误 (#957)
Browse files Browse the repository at this point in the history
## 前提:在.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)
  • Loading branch information
OYX-1 authored Nov 9, 2023
1 parent 62c7f32 commit a79aa10
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/khaki-rockets-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@scow/portal-web": patch
"@scow/lib-ssh": patch
---

sshConnect 时,提示语过长会使得连接失败,现在捕获了这个错误并提示用户
2 changes: 1 addition & 1 deletion apps/portal-server/src/utils/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export async function sshConnect<T>(
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),
});
}

Expand Down
2 changes: 2 additions & 0 deletions apps/portal-web/src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!",
},
Expand Down
2 changes: 1 addition & 1 deletion apps/portal-web/src/i18n/zh_cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ export default {
},
},
_app: {
textExceedsLength:"终端登录欢迎提示信息过多,请减少不必要的信息输出!",
sshError:"无法以用户身份连接到登录节点。请确认您的家目录的权限为700、750或者755",

sftpError:"SFTP操作失败,请确认您是否有操作的权限",
otherError:"服务器出错啦!",
},
Expand Down
9 changes: 8 additions & 1 deletion apps/portal-web/src/pages/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
4 changes: 3 additions & 1 deletion apps/portal-web/src/utils/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
});
Expand Down
13 changes: 12 additions & 1 deletion libs/ssh/src/ssh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,18 @@ export async function sshConnect<T>(
) {
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<T>(
Expand Down

0 comments on commit a79aa10

Please sign in to comment.