Skip to content

Commit 0acb7ae

Browse files
authored
fix(logging): misleading "settings failed" message aws#7240
## 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.
1 parent 0189564 commit 0acb7ae

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

packages/core/src/shared/settings.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,10 @@ function createSettingsClass<T extends TypeDescriptor>(section: string, descript
389389
public _getOrThrow<K extends keyof Inner>(key: K & string, defaultValue?: Inner[K]) {
390390
const value = this.#config.get(key, defaultValue)
391391

392+
if (defaultValue !== undefined && (value === undefined || value === null)) {
393+
return defaultValue
394+
}
395+
392396
return cast<Inner[K]>(value, descriptor[key])
393397
}
394398

0 commit comments

Comments
 (0)