From 44c2ffc34752b0de3ea1af2fc5e9ccf90557a8dd Mon Sep 17 00:00:00 2001 From: Sam Stenvall Date: Tue, 21 Oct 2025 20:16:38 +0300 Subject: [PATCH] Use double-quotes in error messages --- app/modbus.ts | 6 +++--- tests/modbus.test.ts | 8 +++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/modbus.ts b/app/modbus.ts index 55db1aa..9ae87f9 100644 --- a/app/modbus.ts +++ b/app/modbus.ts @@ -288,14 +288,14 @@ const parseSettingValue = (settingConfig: HoldingRegisterSettingConfiguration, v export const setSetting = async (modbusClient: ModbusRTU, setting: string, value: string | boolean) => { const settingConfig = AVAILABLE_SETTINGS[setting] if (settingConfig === undefined) { - throw new Error('Unknown setting') + throw new Error(`Unknown setting "${setting}"`) } switch (settingConfig.registerType) { case 'holding': { // Holding registers expect numeric (string) values if (typeof value !== 'string') { - throw new TypeError(`Setting '${setting}' expects a numeric value, got ${typeof value}`) + throw new TypeError(`Setting "${setting}" expects a numeric value, got ${typeof value}`) } const numericValue = parseSettingValue(settingConfig, value) return setNumericSetting(modbusClient, settingConfig, numericValue) @@ -303,7 +303,7 @@ export const setSetting = async (modbusClient: ModbusRTU, setting: string, value case 'coil': { // Coils expect boolean values if (typeof value !== 'boolean') { - throw new TypeError(`Setting '${setting}' expects a boolean value, got ${typeof value}`) + throw new TypeError(`Setting "${setting}" expects a boolean value, got ${typeof value}`) } return setBooleanSetting(modbusClient, settingConfig, value) } diff --git a/tests/modbus.test.ts b/tests/modbus.test.ts index ae9e29e..e74151a 100644 --- a/tests/modbus.test.ts +++ b/tests/modbus.test.ts @@ -67,7 +67,7 @@ describe('setSetting', () => { test('should reject boolean values for numeric settings', async () => { await expect(setSetting(mockClient, 'temperatureTarget', true)).rejects.toThrow( - "Setting 'temperatureTarget' expects a numeric value, got boolean" + 'Setting "temperatureTarget" expects a numeric value, got boolean' ) }) @@ -116,14 +116,16 @@ describe('setSetting', () => { test('should reject string values for coil settings', async () => { await expect(setSetting(mockClient, 'coolingAllowed', '1')).rejects.toThrow( - "Setting 'coolingAllowed' expects a boolean value, got string" + 'Setting "coolingAllowed" expects a boolean value, got string' ) }) }) describe('unknown settings', () => { test('should reject unknown setting names', async () => { - await expect(setSetting(mockClient, 'nonExistentSetting', '123')).rejects.toThrow('Unknown setting') + await expect(setSetting(mockClient, 'nonExistentSetting', '123')).rejects.toThrow( + 'Unknown setting "nonExistentSetting"' + ) }) }) })