Skip to content

Commit

Permalink
fix(lib): check if the globalConfig is undefined before get its prope…
Browse files Browse the repository at this point in the history
…rty in e-mem and e-net
  • Loading branch information
manushak committed Mar 28, 2024
1 parent 5349545 commit e66cda5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/lib/e-mem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ export const EMem = (globalConfig: ConfigParams): PluginInterface => {
});

//Manually add default value from CCF: https://www.cloudcarbonfootprint.org/docs/methodology/#memory
const energyPerGB = globalConfig['energy-per-gb'] ?? 0.000392;
const energyPerGB =
(globalConfig && globalConfig['energy-per-gb']) ?? 0.000392;

return validate<z.infer<typeof schema>>(schema, {
...globalConfig,
Expand Down
16 changes: 11 additions & 5 deletions src/lib/e-net/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ export const ENet = (globalConfig: ConfigParams): PluginInterface => {
'energy-per-gb': z.number(),
});

// Manually add default value
if (!globalConfig['energy-per-gb'] || globalConfig['energy-per-gb'] === 0) {
globalConfig['energy-per-gb'] = 0.001;
}
// Manually add default value from CCF: https://www.cloudcarbonfootprint.org/docs/methodology/#chosen-coefficient
const energyPerGB =
!globalConfig ||
!globalConfig['energy-per-gb'] ||
globalConfig['energy-per-gb'] === 0
? 0.001
: globalConfig['energy-per-gb'];

return validate<z.infer<typeof schema>>(schema, globalConfig);
return validate<z.infer<typeof schema>>(schema, {
...globalConfig,
'energy-per-gb': energyPerGB,
});
};

/**
Expand Down

0 comments on commit e66cda5

Please sign in to comment.