Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secretId 给错时不能正确给出错误信息。 #16

Open
TeCHiScy opened this issue Dec 27, 2020 · 3 comments
Open

secretId 给错时不能正确给出错误信息。 #16

TeCHiScy opened this issue Dec 27, 2020 · 3 comments

Comments

@TeCHiScy
Copy link

TeCHiScy commented Dec 27, 2020

代码:

`
const { hosting, storage } = CloudBase.init({
secretId: "xxx",
secretKey: "xxx",
envId: "dev-xxx"
});

// 上传文件到 cos
await storage.uploadDirectory({
localPath: path.resolve("./content"),
cloudPath: "content",
onProgress: (data) => {
console.log(data);
},
});
`

这段代码中的 secretId 给错时报错为:
(node:10516) UnhandledPromiseRejectionWarning: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
at Object.stat (fs.js:1057:10)
at C:\Users\daren\Desktop\guanyuedesign.com\node_modules\cos-nodejs-sdk-v5\sdk\advance.js:828:12
at Object.each (C:\Users\daren\Desktop\guanyuedesign.com\node_modules\cos-nodejs-sdk-v5\sdk\util.js:248:13)
at COS.uploadFiles (C:\Users\daren\Desktop\guanyuedesign.com\node_modules\cos-nodejs-sdk-v5\sdk\advance.js:827:10)
at COS.uploadFiles (C:\Users\daren\Desktop\guanyuedesign.com\node_modules\cos-nodejs-sdk-v5\sdk\util.js:461:29)
at internal/util.js:297:30
at new Promise ()
at COS. (internal/util.js:296:12)
...

实际的错误是:
CloudBaseError: SIGN_PARAM_INVALID: secret key not exist

也就是 sdk 在用错误的 secretId 请求云 API 时返回的错误。
这层错误被 sdk 掩盖掉了,导致实际报出来的错误完全看不出和鉴权有关。

希望修复。

@chhpt
Copy link
Contributor

chhpt commented Dec 29, 2020

无法复现你说的问题,参考:https://repl.it/@WuYiqing/Manager-Node 请提供一个可以复现问题的 Demo。
image

@TeCHiScy
Copy link
Author

我试了下,复现方式需要改为:用正确的 secretId,但是后面多一个空格,而不是给完全错误的 id。

image

secretKey 和 envId 都给正确的。

@chhpt
Copy link
Contributor

chhpt commented Jan 15, 2021

@TeCHiScy 我的代码写错了,切换为上传文件的接口后,还是会报秘钥不存在,可以在新的 Demo 中查看:
https://repl.it/@WuYiqing/Manager-Node-1
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants