]> Piment Noir Git Repositories - e-mobility-charging-stations-simulator.git/commitdiff
refactor(ui-cli): move StationListPayload to shared types, add resolution error context
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 17 Apr 2026 21:43:43 +0000 (23:43 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 17 Apr 2026 21:43:43 +0000 (23:43 +0200)
- Move StationListPayload from renderers.ts to types.ts to fix
  cross-layer dependency (action.ts no longer imports from output layer)
- Wrap hash prefix resolution errors with contextual message
  ('Failed to resolve hash ID prefixes: ...')

ui/cli/src/commands/action.ts
ui/cli/src/output/renderers.ts
ui/cli/src/types.ts

index ff812703174c494dcb99987b165f085bfd1c8274..0eb1e51fef566f9e61a6e8abe082a8165c5243e4 100644 (file)
@@ -9,8 +9,7 @@ import {
   type UIServerConfigurationSection,
 } from 'ui-common'
 
-import type { StationListPayload } from '../output/renderers.js'
-import type { GlobalOptions } from '../types.js'
+import type { GlobalOptions, StationListPayload } from '../types.js'
 
 import { executeCommand } from '../client/lifecycle.js'
 import { loadConfig } from '../config/loader.js'
@@ -35,12 +34,18 @@ const resolveShortHashIds = async (
   const allFull = hashIds.every(id => id.length >= MIN_FULL_HASH_LENGTH)
   if (allFull) return hashIds
 
-  const response = await executeCommand({
-    config,
-    payload: {},
-    procedureName: ProcedureName.LIST_CHARGING_STATIONS,
-    silent: true,
-  })
+  let response
+  try {
+    response = await executeCommand({
+      config,
+      payload: {},
+      procedureName: ProcedureName.LIST_CHARGING_STATIONS,
+      silent: true,
+    })
+  } catch (error: unknown) {
+    const msg = error instanceof Error ? error.message : String(error)
+    throw new Error(`Failed to resolve hash ID prefixes: ${msg}`)
+  }
 
   if (response.status !== ResponseStatus.SUCCESS || !Array.isArray(response.chargingStations)) {
     throw new Error(
index c17447e6a2c03d2c23805062efd1676b0a9a8319..982046b05f246d3280d5d0f36c830c68d088ec90 100644 (file)
@@ -1,8 +1,10 @@
-import type { ChargingStationData, ResponsePayload } from 'ui-common'
+import type { ResponsePayload } from 'ui-common'
 
 import chalk from 'chalk'
 import process from 'node:process'
 
+import type { StationListPayload } from '../types.js'
+
 import {
   borderlessTable,
   countConnectors,
@@ -12,10 +14,6 @@ import {
   wsIcon,
 } from './format.js'
 
-export type StationListPayload = ResponsePayload & {
-  chargingStations: ChargingStationData[]
-}
-
 type PerformancePayload = ResponsePayload & {
   performanceStatistics: unknown[]
 }
index 63ae321ddb975348b823fbf9c282798966cd144a..db1ab6cd07bf7a8b564c7d36c1d9bf8dbfe6e90c 100644 (file)
@@ -1,5 +1,11 @@
+import type { ChargingStationData, ResponsePayload } from 'ui-common'
+
 export interface GlobalOptions {
   config?: string
   json: boolean
   serverUrl?: string
 }
+
+export type StationListPayload = ResponsePayload & {
+  chargingStations: ChargingStationData[]
+}