Skip to content

Commit

Permalink
fix(util): fix errorBuilder to take constuctor's name
Browse files Browse the repository at this point in the history
  • Loading branch information
manushak committed Feb 9, 2024
1 parent 1133d1f commit c695e63
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/lib/azure-importer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {TIME_UNITS_IN_SECONDS} from './config';
const {UnsupportedValueError, InputValidationError} = ERRORS;

export class AzureImporterModel implements ModelPluginInterface {
errorBuilder = buildErrorMessage(this.constructor); // TODO: send name instead of entier class after all models are refactored
errorBuilder = buildErrorMessage(this.constructor.name);
azureAPI = new AzureAPI();

/**
Expand Down
2 changes: 1 addition & 1 deletion src/lib/boavizta/base-output-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export abstract class BoaviztaBaseOutputModel<U>
protected authCredentials?: object;
protected boaviztaAPI: BoaviztaAPI = new BoaviztaAPI();

errorBuilder = buildErrorMessage(this.constructor); //TODO: send name after all models are refactored
errorBuilder = buildErrorMessage(this.constructor.name);

/**
* Authenticates the model with provided authentication parameters.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/ccf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class CloudCarbonFootprint implements ModelPluginInterface {
private expectedLifespan = 4;
private interpolation = Interpolation.LINEAR;

errorBuilder = buildErrorMessage(CloudCarbonFootprint);
errorBuilder = buildErrorMessage(this.constructor.name);

/**
* Constructor initializes and standardizes instance metrics
Expand Down
4 changes: 2 additions & 2 deletions src/lib/co2js/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ This impl is run using `impact-engine` using the following command, run from the
```sh
npm i -g @grnsft/if
npm i -g @grnsft/if-unofficial-models
impact-engine --impl ./examples/impls/test/co2js-test.yml --ompl ./examples/ompls/co2js-test.yml
impact-engine --impl ./examples/impls/test/co2js.yml --ompl ./examples/ompls/co2js.yml
```

This yields a result that looks like the following (saved to `/ompls/co2js-test.yml`):
This yields a result that looks like the following (saved to `/ompls/co2js.yml`):

```yaml
name: co2js-demo
Expand Down
2 changes: 1 addition & 1 deletion src/lib/co2js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class Co2jsModel implements ModelPluginInterface {
staticParams: KeyValuePair = {};
model: any | undefined;

errorBuilder = buildErrorMessage(this.constructor);
errorBuilder = buildErrorMessage(this.constructor.name);

/**
* Configures the model with static parameters.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/teads-aws/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class TeadsAWS implements ModelPluginInterface {
private expectedLifespan = 4 * 365 * 24 * 3600;
private interpolation = Interpolation.LINEAR;

errorBuilder = buildErrorMessage(this.constructor); //TODO: send the name
errorBuilder = buildErrorMessage(this.constructor.name);

constructor() {
this.standardizeInstanceMetrics();
Expand Down
2 changes: 1 addition & 1 deletion src/lib/teads-curve/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class TeadsCurveModel implements ModelPluginInterface {
private tdp = 0;
private interpolation: Interpolation = Interpolation.SPLINE;

errorBuilder = buildErrorMessage(TeadsCurveModel);
errorBuilder = buildErrorMessage(this.constructor.name);

/**
* Configures the TEADS Plugin for IEF.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/watt-time/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {InputValidationError} = ERRORS;

export class WattTimeGridEmissions implements ModelPluginInterface {
private wattTimeAPI = new WattTimeAPI();
errorBuilder = buildErrorMessage(WattTimeGridEmissions);
errorBuilder = buildErrorMessage(this.constructor.name);

/**
* Configures the model with static parameters.
Expand Down
2 changes: 1 addition & 1 deletion src/lib/watt-time/watt-time-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class WattTimeAPI {
private baseUrl = 'https://api2.watttime.org/v2';
private token = '';

errorBuilder = buildErrorMessage(WattTimeAPI);
errorBuilder = buildErrorMessage(this.constructor.name);

/**
* Authenticates the user with the WattTime API using the provided authentication parameters.
Expand Down
4 changes: 2 additions & 2 deletions src/util/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {ErrorFormatParams} from '../types/helpers';
* Formats given error according to class instance, scope and message.
*/
export const buildErrorMessage =
(classInstance: any) => (params: ErrorFormatParams) => {
(classInstanceName: string) => (params: ErrorFormatParams) => {
const {scope, message} = params;

return `${classInstance.name}${scope ? `(${scope})` : ''}: ${message}.`;
return `${classInstanceName}${scope ? `(${scope})` : ''}: ${message}.`;
};

0 comments on commit c695e63

Please sign in to comment.