From 0c6cfa9ac228910848194b1936ac077208617483 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 17 Apr 2026 23:43:43 +0200 Subject: [PATCH] refactor(ui-cli): move StationListPayload to shared types, add resolution error context - 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 | 21 +++++++++++++-------- ui/cli/src/output/renderers.ts | 8 +++----- ui/cli/src/types.ts | 6 ++++++ 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/ui/cli/src/commands/action.ts b/ui/cli/src/commands/action.ts index ff812703..0eb1e51f 100644 --- a/ui/cli/src/commands/action.ts +++ b/ui/cli/src/commands/action.ts @@ -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( diff --git a/ui/cli/src/output/renderers.ts b/ui/cli/src/output/renderers.ts index c17447e6..982046b0 100644 --- a/ui/cli/src/output/renderers.ts +++ b/ui/cli/src/output/renderers.ts @@ -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[] } diff --git a/ui/cli/src/types.ts b/ui/cli/src/types.ts index 63ae321d..db1ab6cd 100644 --- a/ui/cli/src/types.ts +++ b/ui/cli/src/types.ts @@ -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[] +} -- 2.43.0