From 18863784b17d162f62bb73fc59cd57fdd12c9585 Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Tue, 7 Nov 2023 08:39:08 +0000 Subject: [PATCH 01/12] =?UTF-8?q?fix:=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E4=BC=9A=E5=9B=A0=E4=B8=BAsftp=E6=B6=88=E6=81=AF=E8=BF=87?= =?UTF-8?q?=E9=95=BF=E6=8A=A5500=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/portal-web/src/i18n/en.ts | 3 +++ apps/portal-web/src/i18n/zh_cn.ts | 2 ++ .../src/pageComponents/filemanager/FileManager.tsx | 9 +++++++++ apps/portal-web/src/pages/api/file/list.ts | 2 ++ 4 files changed, 16 insertions(+) diff --git a/apps/portal-web/src/i18n/en.ts b/apps/portal-web/src/i18n/en.ts index e8071d3be7..6f8dbe1504 100644 --- a/apps/portal-web/src/i18n/en.ts +++ b/apps/portal-web/src/i18n/en.ts @@ -195,6 +195,9 @@ export default { fileName: "File Name", }, fileManager: { + sftpError:"sftpError", + textExceedsLength:"There are too many welcome messages for terminal login." + + "Please reduce unnecessary information output!", moveCopy: { copy: "Copy", move: "Move", diff --git a/apps/portal-web/src/i18n/zh_cn.ts b/apps/portal-web/src/i18n/zh_cn.ts index 241e20274b..8aa1592079 100644 --- a/apps/portal-web/src/i18n/zh_cn.ts +++ b/apps/portal-web/src/i18n/zh_cn.ts @@ -195,6 +195,8 @@ export default { fileName: "文件名", }, fileManager: { + sftpError:"sftp错误", + textExceedsLength:"终端登录欢迎提示信息过多,请减少不必要的信息输出!", moveCopy: { copy: "复制", move: "移动", diff --git a/apps/portal-web/src/pageComponents/filemanager/FileManager.tsx b/apps/portal-web/src/pageComponents/filemanager/FileManager.tsx index d916c4756f..a4fa38d855 100644 --- a/apps/portal-web/src/pageComponents/filemanager/FileManager.tsx +++ b/apps/portal-web/src/pageComponents/filemanager/FileManager.tsx @@ -113,6 +113,15 @@ export const FileManager: React.FC = ({ cluster, path, urlPrefix }) => { const reload = async (signal?: AbortSignal) => { setLoading(true); await api.listFile({ query: { cluster: cluster.id, path } }, signal) + .httpError(409, (e) => { + // 如果终端登录欢迎语过长会报错:Packet length xxxx exceeds max length of 262144 + if (e.message.endsWith("exceeds max length of 262144")) { + message.error(t(p("textExceedsLength"))); + } + else { + message.error(t(p("sftpError"))); + } + }) .then((d) => { setFiles(d.items); }) diff --git a/apps/portal-web/src/pages/api/file/list.ts b/apps/portal-web/src/pages/api/file/list.ts index fc4ee0c8d7..63f6019500 100644 --- a/apps/portal-web/src/pages/api/file/list.ts +++ b/apps/portal-web/src/pages/api/file/list.ts @@ -48,6 +48,7 @@ export const ListFileSchema = typeboxRouteSchema({ 200: Type.Object({ items: Type.Array(FileInfo) }), 400: Type.Object({ code: Type.Literal("INVALID_CLUSTER") }), 403: Type.Object({ code: Type.Literal("NOT_ACCESSIBLE") }), + 409:Type.Object({ code: Type.Literal("FATAL_SFTP_ERROR"), message:Type.String() }), 412: Type.Object({ code: Type.Literal("DIRECTORY_NOT_FOUND") }), }, }); @@ -78,6 +79,7 @@ export default route(ListFileSchema, async (req, res) => { })) } }), handlegRPCError({ [status.NOT_FOUND]: () => ({ 400: { code: "INVALID_CLUSTER" as const } }), [status.PERMISSION_DENIED]: () => ({ 403: { code: "NOT_ACCESSIBLE" as const } }), + [status.UNKNOWN]: (e) => ({ 409: { code: "FATAL_SFTP_ERROR" as const, message:e.details } }), [status.INVALID_ARGUMENT]: () => ({ 412: { code: "DIRECTORY_NOT_FOUND" as const } }), })); From 184b75b94ca4ce0ed56ab84ff3f94436e95c888b Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Tue, 7 Nov 2023 08:44:05 +0000 Subject: [PATCH 02/12] changeset --- .changeset/stupid-peas-wait.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/stupid-peas-wait.md diff --git a/.changeset/stupid-peas-wait.md b/.changeset/stupid-peas-wait.md new file mode 100644 index 0000000000..1d1d8b7480 --- /dev/null +++ b/.changeset/stupid-peas-wait.md @@ -0,0 +1,5 @@ +--- +"@scow/portal-web": patch +--- + +文件管理和交互式应用两个功能因为使用 sftp 获取家目录时,欢迎语过多时导致 500 错误,现捕获了这个错误并提示用户。 From d4fcb3a4ac9fcfb58ddcef0c01861eefa2e311c8 Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Wed, 8 Nov 2023 09:26:11 +0000 Subject: [PATCH 03/12] =?UTF-8?q?fix:=E7=BB=9F=E4=B8=80=E5=A4=84=E7=90=86r?= =?UTF-8?q?un=20ssh=E6=97=B6=E5=9B=A0=E6=B6=88=E6=81=AF=E5=A4=AA=E9=95=BF?= =?UTF-8?q?=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/portal-server/src/utils/ssh.ts | 3 ++- apps/portal-web/src/i18n/en.ts | 5 ++--- apps/portal-web/src/i18n/zh_cn.ts | 4 +--- .../src/pageComponents/filemanager/FileManager.tsx | 9 --------- apps/portal-web/src/pages/_app.tsx | 9 ++++++++- apps/portal-web/src/pages/api/file/list.ts | 2 -- apps/portal-web/src/utils/route.ts | 4 +++- libs/ssh/src/ssh.ts | 5 ++++- 8 files changed, 20 insertions(+), 21 deletions(-) diff --git a/apps/portal-server/src/utils/ssh.ts b/apps/portal-server/src/utils/ssh.ts index 648dec3eaf..96bb3ff8c2 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), }); } @@ -100,6 +100,7 @@ export async function sshConnect( metadata: scowErrorMetadata(SFTP_ERROR_CODE), }); } + console.log("e111", e); throw e; }); diff --git a/apps/portal-web/src/i18n/en.ts b/apps/portal-web/src/i18n/en.ts index 6f8dbe1504..527fbc50a4 100644 --- a/apps/portal-web/src/i18n/en.ts +++ b/apps/portal-web/src/i18n/en.ts @@ -195,9 +195,6 @@ export default { fileName: "File Name", }, fileManager: { - sftpError:"sftpError", - textExceedsLength:"There are too many welcome messages for terminal login." - + "Please reduce unnecessary information output!", moveCopy: { copy: "Copy", move: "Move", @@ -461,6 +458,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 8aa1592079..98262abd55 100644 --- a/apps/portal-web/src/i18n/zh_cn.ts +++ b/apps/portal-web/src/i18n/zh_cn.ts @@ -195,8 +195,6 @@ export default { fileName: "文件名", }, fileManager: { - sftpError:"sftp错误", - textExceedsLength:"终端登录欢迎提示信息过多,请减少不必要的信息输出!", moveCopy: { copy: "复制", move: "移动", @@ -458,8 +456,8 @@ export default { }, }, _app: { + textExceedsLength:"终端登录欢迎提示信息过多,请减少不必要的信息输出!", sshError:"无法以用户身份连接到登录节点。请确认您的家目录的权限为700、750或者755", - sftpError:"SFTP操作失败,请确认您是否有操作的权限", otherError:"服务器出错啦!", }, diff --git a/apps/portal-web/src/pageComponents/filemanager/FileManager.tsx b/apps/portal-web/src/pageComponents/filemanager/FileManager.tsx index a4fa38d855..d916c4756f 100644 --- a/apps/portal-web/src/pageComponents/filemanager/FileManager.tsx +++ b/apps/portal-web/src/pageComponents/filemanager/FileManager.tsx @@ -113,15 +113,6 @@ export const FileManager: React.FC = ({ cluster, path, urlPrefix }) => { const reload = async (signal?: AbortSignal) => { setLoading(true); await api.listFile({ query: { cluster: cluster.id, path } }, signal) - .httpError(409, (e) => { - // 如果终端登录欢迎语过长会报错:Packet length xxxx exceeds max length of 262144 - if (e.message.endsWith("exceeds max length of 262144")) { - message.error(t(p("textExceedsLength"))); - } - else { - message.error(t(p("sftpError"))); - } - }) .then((d) => { setFiles(d.items); }) diff --git a/apps/portal-web/src/pages/_app.tsx b/apps/portal-web/src/pages/_app.tsx index e3e7b713d8..492e6856eb 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/pages/api/file/list.ts b/apps/portal-web/src/pages/api/file/list.ts index 63f6019500..fc4ee0c8d7 100644 --- a/apps/portal-web/src/pages/api/file/list.ts +++ b/apps/portal-web/src/pages/api/file/list.ts @@ -48,7 +48,6 @@ export const ListFileSchema = typeboxRouteSchema({ 200: Type.Object({ items: Type.Array(FileInfo) }), 400: Type.Object({ code: Type.Literal("INVALID_CLUSTER") }), 403: Type.Object({ code: Type.Literal("NOT_ACCESSIBLE") }), - 409:Type.Object({ code: Type.Literal("FATAL_SFTP_ERROR"), message:Type.String() }), 412: Type.Object({ code: Type.Literal("DIRECTORY_NOT_FOUND") }), }, }); @@ -79,7 +78,6 @@ export default route(ListFileSchema, async (req, res) => { })) } }), handlegRPCError({ [status.NOT_FOUND]: () => ({ 400: { code: "INVALID_CLUSTER" as const } }), [status.PERMISSION_DENIED]: () => ({ 403: { code: "NOT_ACCESSIBLE" as const } }), - [status.UNKNOWN]: (e) => ({ 409: { code: "FATAL_SFTP_ERROR" as const, message:e.details } }), [status.INVALID_ARGUMENT]: () => ({ 412: { code: "DIRECTORY_NOT_FOUND" as const } }), })); 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..bf56f387c6 100644 --- a/libs/ssh/src/ssh.ts +++ b/libs/ssh/src/ssh.ts @@ -93,7 +93,10 @@ export async function sshConnect( ) { const ssh = await sshRawConnect(address, username, rootKeyPair, logger); - return run(ssh).finally(() => { ssh.dispose(); }); + return run(ssh).catch((e) => { + logger.info("Running ssh failed."); + throw new SshConnectError({ cause: e.message }); + }).finally(() => { ssh.dispose(); }); } export async function sshConnectByPassword( From 43116ecb2b20835a2b87a3e31627d435cc4f0b37 Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Wed, 8 Nov 2023 09:34:17 +0000 Subject: [PATCH 04/12] =?UTF-8?q?fix:=E5=88=A0=E9=99=A4console?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/portal-server/src/utils/ssh.ts | 1 - dev/vagrant/config/auth.yml | 4 ++-- .../config/clusters/{hpc01.yaml => linux.yaml} | 16 +++++++--------- dev/vagrant/config/mis.yaml | 12 ++++++++---- 4 files changed, 17 insertions(+), 16 deletions(-) rename dev/vagrant/config/clusters/{hpc01.yaml => linux.yaml} (63%) diff --git a/apps/portal-server/src/utils/ssh.ts b/apps/portal-server/src/utils/ssh.ts index 96bb3ff8c2..e23eeae3ba 100644 --- a/apps/portal-server/src/utils/ssh.ts +++ b/apps/portal-server/src/utils/ssh.ts @@ -100,7 +100,6 @@ export async function sshConnect( metadata: scowErrorMetadata(SFTP_ERROR_CODE), }); } - console.log("e111", e); throw e; }); diff --git a/dev/vagrant/config/auth.yml b/dev/vagrant/config/auth.yml index a1361e4d9c..441e5adb77 100644 --- a/dev/vagrant/config/auth.yml +++ b/dev/vagrant/config/auth.yml @@ -1,7 +1,7 @@ # 指定使用认证类型为LDAP authType: ldap -redisUrl: 192.168.88.100:6379 +redisUrl: 172.16.20.124:6379 allowedCallbackHostnames: - localhost @@ -63,7 +63,7 @@ otp: # 在此部分输入LDAP的配置 ldap: # LDAP服务器地址。必填 - url: ldap://192.168.88.101 + url: ldap://172.16.20.124 # 进行LDAP操作的用户DN。默认为空 bindDN: cn=Manager,ou=hpc,o=pku diff --git a/dev/vagrant/config/clusters/hpc01.yaml b/dev/vagrant/config/clusters/linux.yaml similarity index 63% rename from dev/vagrant/config/clusters/hpc01.yaml rename to dev/vagrant/config/clusters/linux.yaml index f65f578a29..c997a225d2 100644 --- a/dev/vagrant/config/clusters/hpc01.yaml +++ b/dev/vagrant/config/clusters/linux.yaml @@ -5,18 +5,16 @@ displayName: hpc01 # default: 集群1 # en: Cluster One # zh_cn: 集群1 - -adapterUrl: "192.168.88.101:8972" +adapterUrl: "172.16.20.124:8999" loginNodes: # 登录节点展示名称 - name: login - # - name: - # i18n: - # default: 登录节点1 - # en: loginNode1 - # zh_cn: 登录节点1 + # - name: + # i18n: + # default: 登录节点1 + # en: loginNode1 + # zh_cn: 登录节点1 # 登录节点的IP或者域名 # 如果设置的是域名,请确认此节点的/etc/hosts中包含了域名到IP的解析信息 - address: 192.168.88.102 - + address: 172.16.20.124:2022 diff --git a/dev/vagrant/config/mis.yaml b/dev/vagrant/config/mis.yaml index 483c17650d..5b519ac848 100644 --- a/dev/vagrant/config/mis.yaml +++ b/dev/vagrant/config/mis.yaml @@ -1,8 +1,8 @@ # 管理系统数据库的信息。可以不修改 db: - host: 192.168.88.100 + host: 172.16.20.124 password: must!chang3this - port: 3308 + port: 3306 user: root dbName: scow @@ -27,13 +27,17 @@ accountNamePattern: regex: "(a_)[a-z]+$" # 出错时的消息 - # errorMessage: "" + errorMessage: + i18n: + default: "必须以 'a_' 开头并以小写字母结尾:(a_)[a-z]+$" + en: "must start with 'a_' and end with lowercase letters:(a_)[a-z]+$" + zh_cn: "必须以 'a_' 开头并以小写字母结尾:(a_)[a-z]+$" createUser: # 创建用户时,用户ID的规则。不设置就没有限制 userIdPattern: # 正则表达式 - regex: "^[a-zA-Z0-9_]+$" + regex: "^[a-zA-Z]\\w{2,19}$" # 出错时的消息 errorMessage: "只能由字母、下划线、数字组成" # errorMessage: From 3ecd8d3c6bda7f2d9ce8b66257894c8e4f9a56a6 Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Thu, 9 Nov 2023 01:36:57 +0000 Subject: [PATCH 05/12] =?UTF-8?q?=E5=88=A0=E9=99=A4console?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/portal-server/src/utils/ssh.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/apps/portal-server/src/utils/ssh.ts b/apps/portal-server/src/utils/ssh.ts index 96bb3ff8c2..e23eeae3ba 100644 --- a/apps/portal-server/src/utils/ssh.ts +++ b/apps/portal-server/src/utils/ssh.ts @@ -100,7 +100,6 @@ export async function sshConnect( metadata: scowErrorMetadata(SFTP_ERROR_CODE), }); } - console.log("e111", e); throw e; }); From b3dcf7c9f253a9f25ca4fc47326409328c2bf0de Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Thu, 9 Nov 2023 01:46:40 +0000 Subject: [PATCH 06/12] =?UTF-8?q?fix:=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dev/vagrant/config/auth.yml | 4 ++-- .../config/clusters/{linux.yaml => hpc01.yaml} | 16 +++++++++------- dev/vagrant/config/mis.yaml | 12 ++++-------- 3 files changed, 15 insertions(+), 17 deletions(-) rename dev/vagrant/config/clusters/{linux.yaml => hpc01.yaml} (63%) diff --git a/dev/vagrant/config/auth.yml b/dev/vagrant/config/auth.yml index 441e5adb77..a1361e4d9c 100644 --- a/dev/vagrant/config/auth.yml +++ b/dev/vagrant/config/auth.yml @@ -1,7 +1,7 @@ # 指定使用认证类型为LDAP authType: ldap -redisUrl: 172.16.20.124:6379 +redisUrl: 192.168.88.100:6379 allowedCallbackHostnames: - localhost @@ -63,7 +63,7 @@ otp: # 在此部分输入LDAP的配置 ldap: # LDAP服务器地址。必填 - url: ldap://172.16.20.124 + url: ldap://192.168.88.101 # 进行LDAP操作的用户DN。默认为空 bindDN: cn=Manager,ou=hpc,o=pku diff --git a/dev/vagrant/config/clusters/linux.yaml b/dev/vagrant/config/clusters/hpc01.yaml similarity index 63% rename from dev/vagrant/config/clusters/linux.yaml rename to dev/vagrant/config/clusters/hpc01.yaml index c997a225d2..f65f578a29 100644 --- a/dev/vagrant/config/clusters/linux.yaml +++ b/dev/vagrant/config/clusters/hpc01.yaml @@ -5,16 +5,18 @@ displayName: hpc01 # default: 集群1 # en: Cluster One # zh_cn: 集群1 -adapterUrl: "172.16.20.124:8999" + +adapterUrl: "192.168.88.101:8972" loginNodes: # 登录节点展示名称 - name: login - # - name: - # i18n: - # default: 登录节点1 - # en: loginNode1 - # zh_cn: 登录节点1 + # - name: + # i18n: + # default: 登录节点1 + # en: loginNode1 + # zh_cn: 登录节点1 # 登录节点的IP或者域名 # 如果设置的是域名,请确认此节点的/etc/hosts中包含了域名到IP的解析信息 - address: 172.16.20.124:2022 + address: 192.168.88.102 + diff --git a/dev/vagrant/config/mis.yaml b/dev/vagrant/config/mis.yaml index 5b519ac848..483c17650d 100644 --- a/dev/vagrant/config/mis.yaml +++ b/dev/vagrant/config/mis.yaml @@ -1,8 +1,8 @@ # 管理系统数据库的信息。可以不修改 db: - host: 172.16.20.124 + host: 192.168.88.100 password: must!chang3this - port: 3306 + port: 3308 user: root dbName: scow @@ -27,17 +27,13 @@ accountNamePattern: regex: "(a_)[a-z]+$" # 出错时的消息 - errorMessage: - i18n: - default: "必须以 'a_' 开头并以小写字母结尾:(a_)[a-z]+$" - en: "must start with 'a_' and end with lowercase letters:(a_)[a-z]+$" - zh_cn: "必须以 'a_' 开头并以小写字母结尾:(a_)[a-z]+$" + # errorMessage: "" createUser: # 创建用户时,用户ID的规则。不设置就没有限制 userIdPattern: # 正则表达式 - regex: "^[a-zA-Z]\\w{2,19}$" + regex: "^[a-zA-Z0-9_]+$" # 出错时的消息 errorMessage: "只能由字母、下划线、数字组成" # errorMessage: From 6634995a4f078df80f92bb45a60f63b65674feca Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Thu, 9 Nov 2023 02:56:03 +0000 Subject: [PATCH 07/12] fix --- apps/portal-server/src/utils/ssh.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/portal-server/src/utils/ssh.ts b/apps/portal-server/src/utils/ssh.ts index e23eeae3ba..a04839fd17 100644 --- a/apps/portal-server/src/utils/ssh.ts +++ b/apps/portal-server/src/utils/ssh.ts @@ -88,7 +88,8 @@ export async function sshConnect( code: status.INTERNAL, details: e.message, message: e.message, - metadata: scowErrorMetadata(SSH_ERROR_CODE, typeof e.cause === "string" ? { cause:e.cause } : undefined), + metadata: scowErrorMetadata(SSH_ERROR_CODE, + (e.cause && typeof e.cause === "string") ? { cause:e.cause } : undefined), }); } From d61938dd514b51f709d1006019b58b4b5061aa3e Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Thu, 9 Nov 2023 03:08:32 +0000 Subject: [PATCH 08/12] fix:pass test --- apps/portal-server/src/utils/ssh.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/portal-server/src/utils/ssh.ts b/apps/portal-server/src/utils/ssh.ts index a04839fd17..0ad0120895 100644 --- a/apps/portal-server/src/utils/ssh.ts +++ b/apps/portal-server/src/utils/ssh.ts @@ -88,8 +88,8 @@ export async function sshConnect( code: status.INTERNAL, details: e.message, message: e.message, - metadata: scowErrorMetadata(SSH_ERROR_CODE, - (e.cause && typeof e.cause === "string") ? { cause:e.cause } : undefined), + metadata: (e.cause && typeof e.cause === "string") ? scowErrorMetadata(SSH_ERROR_CODE, { cause:e.cause }) : + scowErrorMetadata(SSH_ERROR_CODE), }); } From 55578cf5c957f6c2971eb7078c383fc7c711eb9c Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Thu, 9 Nov 2023 03:20:07 +0000 Subject: [PATCH 09/12] fix:pass test --- apps/portal-server/src/utils/ssh.ts | 3 +-- libs/ssh/src/ssh.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/apps/portal-server/src/utils/ssh.ts b/apps/portal-server/src/utils/ssh.ts index 0ad0120895..648dec3eaf 100644 --- a/apps/portal-server/src/utils/ssh.ts +++ b/apps/portal-server/src/utils/ssh.ts @@ -88,8 +88,7 @@ export async function sshConnect( code: status.INTERNAL, details: e.message, message: e.message, - metadata: (e.cause && typeof e.cause === "string") ? scowErrorMetadata(SSH_ERROR_CODE, { cause:e.cause }) : - scowErrorMetadata(SSH_ERROR_CODE), + metadata: scowErrorMetadata(SSH_ERROR_CODE), }); } diff --git a/libs/ssh/src/ssh.ts b/libs/ssh/src/ssh.ts index bf56f387c6..a1aae01419 100644 --- a/libs/ssh/src/ssh.ts +++ b/libs/ssh/src/ssh.ts @@ -93,10 +93,12 @@ export async function sshConnect( ) { const ssh = await sshRawConnect(address, username, rootKeyPair, logger); - return run(ssh).catch((e) => { - logger.info("Running ssh failed."); - throw new SshConnectError({ cause: e.message }); - }).finally(() => { ssh.dispose(); }); + return run(ssh) + // .catch((e) => { + // logger.info("Running ssh failed."); + // throw new SshConnectError({ cause: e.message }); + // }) + .finally(() => { ssh.dispose(); }); } export async function sshConnectByPassword( From af6ad304a00a3f77798516618e4a8fc828b95aee Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Thu, 9 Nov 2023 03:23:19 +0000 Subject: [PATCH 10/12] =?UTF-8?q?=E5=A2=9E=E5=8A=A0changeset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .changeset/khaki-rockets-switch.md | 6 ++++++ .changeset/stupid-peas-wait.md | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 .changeset/khaki-rockets-switch.md delete mode 100644 .changeset/stupid-peas-wait.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/.changeset/stupid-peas-wait.md b/.changeset/stupid-peas-wait.md deleted file mode 100644 index 1d1d8b7480..0000000000 --- a/.changeset/stupid-peas-wait.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -"@scow/portal-web": patch ---- - -文件管理和交互式应用两个功能因为使用 sftp 获取家目录时,欢迎语过多时导致 500 错误,现捕获了这个错误并提示用户。 From 4b72ca6c8c785de9606d5c98ed28d1e7197218e5 Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Thu, 9 Nov 2023 03:29:44 +0000 Subject: [PATCH 11/12] fix:pass test --- apps/portal-server/src/utils/ssh.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/portal-server/src/utils/ssh.ts b/apps/portal-server/src/utils/ssh.ts index 648dec3eaf..0ad0120895 100644 --- a/apps/portal-server/src/utils/ssh.ts +++ b/apps/portal-server/src/utils/ssh.ts @@ -88,7 +88,8 @@ export async function sshConnect( code: status.INTERNAL, details: e.message, message: e.message, - metadata: scowErrorMetadata(SSH_ERROR_CODE), + metadata: (e.cause && typeof e.cause === "string") ? scowErrorMetadata(SSH_ERROR_CODE, { cause:e.cause }) : + scowErrorMetadata(SSH_ERROR_CODE), }); } From baaf0681c31bc289d6266add8d6c661773ec96a1 Mon Sep 17 00:00:00 2001 From: OYX-1 <13121812323@163.com> Date: Thu, 9 Nov 2023 07:42:03 +0000 Subject: [PATCH 12/12] =?UTF-8?q?fix:=E8=8B=A5=E5=9C=A8run=E5=9B=9E?= =?UTF-8?q?=E8=B0=83=E5=87=BD=E6=95=B0=E4=B8=AD=E6=9C=89=E5=85=B7=E4=BD=93?= =?UTF-8?q?=E6=8A=9B=E9=94=99=EF=BC=8C=E7=9B=B4=E6=8E=A5=E6=8A=9B=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/portal-server/src/utils/ssh.ts | 3 +-- libs/ssh/src/ssh.ts | 14 ++++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/apps/portal-server/src/utils/ssh.ts b/apps/portal-server/src/utils/ssh.ts index 0ad0120895..e23eeae3ba 100644 --- a/apps/portal-server/src/utils/ssh.ts +++ b/apps/portal-server/src/utils/ssh.ts @@ -88,8 +88,7 @@ export async function sshConnect( code: status.INTERNAL, details: e.message, message: e.message, - metadata: (e.cause && typeof e.cause === "string") ? scowErrorMetadata(SSH_ERROR_CODE, { cause:e.cause }) : - scowErrorMetadata(SSH_ERROR_CODE), + metadata: scowErrorMetadata(SSH_ERROR_CODE, typeof e.cause === "string" ? { cause:e.cause } : undefined), }); } diff --git a/libs/ssh/src/ssh.ts b/libs/ssh/src/ssh.ts index a1aae01419..8969fbbac9 100644 --- a/libs/ssh/src/ssh.ts +++ b/libs/ssh/src/ssh.ts @@ -94,10 +94,16 @@ export async function sshConnect( const ssh = await sshRawConnect(address, username, rootKeyPair, logger); return run(ssh) - // .catch((e) => { - // logger.info("Running ssh failed."); - // throw new SshConnectError({ cause: e.message }); - // }) + .catch((e) => { + // 若在run回调函数中有具体抛错,直接抛出 + if (e.code !== undefined) { + throw e; + } + else { + logger.info("Running ssh failed."); + throw new SshConnectError({ cause: e.message }); + } + }) .finally(() => { ssh.dispose(); }); }