From ef87e203bc9f0445de73b5d7d9762754a5faf5a9 Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Tue, 6 May 2025 15:51:57 -0400 Subject: [PATCH] fix(logging): misleading "settings failed" message Problem: Misleading log message when a setting returns `null`, even if the caller specified `defaultValue`: [error] Settings (amazonQ): failed to read "workspaceIndexCacheDirPath": Unexpected type cast: got object, expected primitive String `cast()` considers `null` to be "object" type, which is misleading. If the caller passed a `defaultValue`, they have intentionally opted-in to ignoring this situation, and *don't* want this kind of log message. Solution: If a setting returns `null|undefined`, skip `cast()` and return `defaultValue` immediately. Don't log an error message. --- packages/core/src/shared/settings.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/core/src/shared/settings.ts b/packages/core/src/shared/settings.ts index 71a2f83a77c..4e3e99f8207 100644 --- a/packages/core/src/shared/settings.ts +++ b/packages/core/src/shared/settings.ts @@ -389,6 +389,10 @@ function createSettingsClass(section: string, descript public _getOrThrow(key: K & string, defaultValue?: Inner[K]) { const value = this.#config.get(key, defaultValue) + if (defaultValue !== undefined && (value === undefined || value === null)) { + return defaultValue + } + return cast(value, descriptor[key]) }