Skip to content

Commit 5832858

Browse files
committed
fix cvm explorer issue when instances are null
1 parent eedef00 commit 5832858

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/import/cvm.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class CvmService implements ITencentCloudAPI {
2727
(result) => {
2828
// console.debug('[DEBUG]--------------------------------result:', result);
2929
if (result.TotalCount === 0) {
30-
throw new Error('[Warn] DescribeInstances result.TotalCount is 0.');
30+
console.warn('[Warn] DescribeInstances result.TotalCount is 0.');
3131
}
3232
return result.InstanceSet;
3333
},

src/views/resources/resExplorer.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ export class CvmResProvider extends tencent.tree.TreeDataProvider {
2121
const service = new CvmService();
2222
const instances = await service.describeInstances();
2323
const config = await service.getConfig();
24+
let items: tencent.tree.TreeItem[] = [];
25+
if (!Array.isArray(instances)) {
26+
return items;// return [] if instances nil
27+
}
2428

25-
const items: tencent.tree.TreeItem[] = Array.isArray(instances)
29+
items = instances.length > 0
2630
? instances.map(instance => ({
2731
label: `${instance.InstanceName}(${instance.InstanceId})`,
2832
id: instance.InstanceId,
@@ -42,12 +46,12 @@ export class CvmResProvider extends tencent.tree.TreeDataProvider {
4246
}],
4347
},
4448
}))
45-
: [];// return [] if instances nil
49+
: [{ label: "No instance." }]; // return none tips if instance is empty
4650

4751
return items;
4852
} catch (error) {
4953
console.error('[Error]#### getChildren got a error:[%s] from CvmService. stack:%s', error.message, error.stack);
50-
return error;
54+
return [];
5155
}
5256

5357
} else {

0 commit comments

Comments
 (0)