]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
fix(ocpp): replace this.constructor.name with moduleName in base class logs
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 18 Mar 2026 19:53:19 +0000 (20:53 +0100)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 18 Mar 2026 19:53:19 +0000 (20:53 +0100)
Minification mangles class names, causing logs like 'ln.responseHandler'
instead of 'OCPP20ResponseService.responseHandler' in production builds.

Add abstract moduleName property to OCPPResponseService and
OCPPIncomingRequestService base classes, implemented by all four
subclasses using their file-level moduleName constant.

src/charging-station/ocpp/1.6/OCPP16IncomingRequestService.ts
src/charging-station/ocpp/1.6/OCPP16ResponseService.ts
src/charging-station/ocpp/2.0/OCPP20IncomingRequestService.ts
src/charging-station/ocpp/2.0/OCPP20ResponseService.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts
src/charging-station/ocpp/OCPPResponseService.ts

index 541351f4bf466bb713c6e7e73f5cd6027c6a34d1..18cf59b7fc9f791eccb1ba1d9e00e78806a10998 100644 (file)
@@ -158,9 +158,10 @@ const moduleName = 'OCPP16IncomingRequestService'
 
 export class OCPP16IncomingRequestService extends OCPPIncomingRequestService {
   protected readonly csmsName = 'central system'
-
   protected readonly incomingRequestHandlers: Map<IncomingRequestCommand, IncomingRequestHandler>
 
+  protected readonly moduleName = moduleName
+
   protected payloadValidatorFunctions: Map<OCPP16IncomingRequestCommand, ValidateFunction<JsonType>>
 
   protected readonly pendingStateBlockedCommands: IncomingRequestCommand[] = [
index d88a33e0f2e0883106693a97ad354f8398a40091..933d1916ba743527b0ca4ef5ca5d7b7d2f21b7a4 100644 (file)
@@ -82,6 +82,7 @@ export class OCPP16ResponseService extends OCPPResponseService {
 
   protected readonly bootNotificationRequestCommand = OCPP16RequestCommand.BOOT_NOTIFICATION
   protected readonly csmsName = 'central system'
+  protected readonly moduleName = moduleName
 
   protected payloadValidatorFunctions: Map<OCPP16RequestCommand, ValidateFunction<JsonType>>
 
index eb30b2f21b5cd81d464884f3da76424711de1d9e..2604396bfc0fefdb64f16790aff41d73974856be 100644 (file)
@@ -209,9 +209,10 @@ interface OCPP20StationState {
 
 export class OCPP20IncomingRequestService extends OCPPIncomingRequestService {
   protected readonly csmsName = 'CSMS'
-
   protected readonly incomingRequestHandlers: Map<IncomingRequestCommand, IncomingRequestHandler>
 
+  protected readonly moduleName = moduleName
+
   protected payloadValidatorFunctions: Map<OCPP20IncomingRequestCommand, ValidateFunction<JsonType>>
 
   protected readonly pendingStateBlockedCommands: IncomingRequestCommand[] = [
index 2b86919c31b3ebfb4fec214a72d4900122272b9d..67436a98ef07d7ddb5edab31cec5fe7ecd4b1a81 100644 (file)
@@ -82,6 +82,7 @@ export class OCPP20ResponseService extends OCPPResponseService {
 
   protected readonly bootNotificationRequestCommand = OCPP20RequestCommand.BOOT_NOTIFICATION
   protected readonly csmsName = 'CSMS'
+  protected readonly moduleName = moduleName
 
   protected payloadValidatorFunctions: Map<OCPP20RequestCommand, ValidateFunction<JsonType>>
 
index 40449ef7f87345a140bd02fa53f165b344961946..0e7dd7ba8f4e4297e9736ea3493901d1584bbaed 100644 (file)
@@ -34,6 +34,8 @@ export abstract class OCPPIncomingRequestService extends EventEmitter {
     IncomingRequestHandler
   >
 
+  protected abstract readonly moduleName: string
+
   protected abstract payloadValidatorFunctions: Map<
     IncomingRequestCommand,
     ValidateFunction<JsonType>
@@ -107,7 +109,7 @@ export abstract class OCPPIncomingRequestService extends EventEmitter {
         } catch (error) {
           // Log
           logger.error(
-            `${chargingStation.logPrefix()} ${this.constructor.name}.incomingRequestHandler: Handle incoming request error:`,
+            `${chargingStation.logPrefix()} ${this.moduleName}.incomingRequestHandler: Handle incoming request error:`,
             error
           )
           throw error
index 5e6966c449d059d731ed10888878cee02d2cdee4..af87bdb9f9cb7aac49209708cede79726d09a547 100644 (file)
@@ -34,6 +34,7 @@ export abstract class OCPPResponseService {
   protected abstract readonly bootNotificationRequestCommand: RequestCommand
   protected abstract readonly csmsName: string
   protected emptyResponseHandler = Constants.EMPTY_FUNCTION
+  protected abstract readonly moduleName: string
   protected abstract payloadValidatorFunctions: Map<RequestCommand, ValidateFunction<JsonType>>
   protected abstract readonly responseHandlers: Map<RequestCommand, ResponseHandler>
   private readonly version: OCPPVersion
@@ -82,7 +83,7 @@ export abstract class OCPPResponseService {
         try {
           this.validateResponsePayload(chargingStation, commandName, payload)
           logger.debug(
-            `${chargingStation.logPrefix()} ${this.constructor.name}.responseHandler: Handling '${commandName}' response`
+            `${chargingStation.logPrefix()} ${this.moduleName}.responseHandler: Handling '${commandName}' response`
           )
           // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
           const responseHandler = this.responseHandlers.get(commandName)!
@@ -98,11 +99,11 @@ export abstract class OCPPResponseService {
             )(chargingStation, payload, requestPayload)
           }
           logger.debug(
-            `${chargingStation.logPrefix()} ${this.constructor.name}.responseHandler: '${commandName}' response processed successfully`
+            `${chargingStation.logPrefix()} ${this.moduleName}.responseHandler: '${commandName}' response processed successfully`
           )
         } catch (error) {
           logger.error(
-            `${chargingStation.logPrefix()} ${this.constructor.name}.responseHandler: Handle '${commandName}' response error:`,
+            `${chargingStation.logPrefix()} ${this.moduleName}.responseHandler: Handle '${commandName}' response error:`,
             error
           )
           throw error