From c695e63eb5307b3ebf3381f656795b7057645baa Mon Sep 17 00:00:00 2001 From: manushak Date: Fri, 9 Feb 2024 12:28:52 +0400 Subject: [PATCH] fix(util): fix errorBuilder to take constuctor's name --- src/lib/azure-importer/index.ts | 2 +- src/lib/boavizta/base-output-model.ts | 2 +- src/lib/ccf/index.ts | 2 +- src/lib/co2js/README.md | 4 ++-- src/lib/co2js/index.ts | 2 +- src/lib/teads-aws/index.ts | 2 +- src/lib/teads-curve/index.ts | 2 +- src/lib/watt-time/index.ts | 2 +- src/lib/watt-time/watt-time-api.ts | 2 +- src/util/helpers.ts | 4 ++-- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lib/azure-importer/index.ts b/src/lib/azure-importer/index.ts index 1aabbf4..f51c769 100644 --- a/src/lib/azure-importer/index.ts +++ b/src/lib/azure-importer/index.ts @@ -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(); /** diff --git a/src/lib/boavizta/base-output-model.ts b/src/lib/boavizta/base-output-model.ts index 1c13b2b..be1354a 100644 --- a/src/lib/boavizta/base-output-model.ts +++ b/src/lib/boavizta/base-output-model.ts @@ -20,7 +20,7 @@ export abstract class BoaviztaBaseOutputModel 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. diff --git a/src/lib/ccf/index.ts b/src/lib/ccf/index.ts index 8b373bc..b7101f4 100644 --- a/src/lib/ccf/index.ts +++ b/src/lib/ccf/index.ts @@ -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 diff --git a/src/lib/co2js/README.md b/src/lib/co2js/README.md index c27b888..64ffc2d 100644 --- a/src/lib/co2js/README.md +++ b/src/lib/co2js/README.md @@ -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 diff --git a/src/lib/co2js/index.ts b/src/lib/co2js/index.ts index c19898c..ccd9825 100644 --- a/src/lib/co2js/index.ts +++ b/src/lib/co2js/index.ts @@ -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. diff --git a/src/lib/teads-aws/index.ts b/src/lib/teads-aws/index.ts index b0c5348..1d9fea1 100644 --- a/src/lib/teads-aws/index.ts +++ b/src/lib/teads-aws/index.ts @@ -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(); diff --git a/src/lib/teads-curve/index.ts b/src/lib/teads-curve/index.ts index 4fb146f..06d51ba 100644 --- a/src/lib/teads-curve/index.ts +++ b/src/lib/teads-curve/index.ts @@ -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. diff --git a/src/lib/watt-time/index.ts b/src/lib/watt-time/index.ts index abee26d..744adb6 100644 --- a/src/lib/watt-time/index.ts +++ b/src/lib/watt-time/index.ts @@ -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. diff --git a/src/lib/watt-time/watt-time-api.ts b/src/lib/watt-time/watt-time-api.ts index b3b84f8..faf3f8b 100644 --- a/src/lib/watt-time/watt-time-api.ts +++ b/src/lib/watt-time/watt-time-api.ts @@ -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. diff --git a/src/util/helpers.ts b/src/util/helpers.ts index 42b444b..efcd27f 100644 --- a/src/util/helpers.ts +++ b/src/util/helpers.ts @@ -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}.`; };