Skip to content

Commit

Permalink
refactor(src#TypedConfig): improve texts and error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
xayanide committed May 27, 2022
1 parent 6cee558 commit e559ba2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/TypedConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ export function loadEnvConfigWithTypeHint(category: string, hints: ConfigTypeHin
} else if (bool === 'false') {
r[hint.key] = false;
} else {
throw new Error(`env:${envKey} type mismatched. ${hint.key} must be true/false but "${envVar}"`);
throw new Error(`Environment key ${envKey}'s type mismatched. ${hint.key} must be a boolean but received "${envVar}"`);
}
break;
case 'number':
const num = parseFloat(envVar);
if (!Number.isNaN(num)) {
r[hint.key] = num;
} else {
throw new Error(`env:${envKey} type mismatched. ${hint.key} must be number but "${envVar}"`);
throw new Error(`Environment key ${envKey}'s type mismatched. ${hint.key} must be a number but received "${envVar}"`);
}
break;
case 'string':
Expand All @@ -118,17 +118,17 @@ export function loadEnvConfigWithTypeHint(category: string, hints: ConfigTypeHin
if (isStringArray(arr)) {
r[hint.key] = arr;
} else {
throw new Error(`env:${envKey} type mismatched. ${hint.key} must be str array(e.g. ["aaa", "bbb", "ccc"] ) but "${envVar}"`);
throw new Error(`Environment key ${envKey}'s type mismatched. ${hint.key} must be a string array, e.g., ["aaa", "bbb", "ccc"] but received "${envVar}"`);
}
break;
default:
throw new Error(`env:${envKey} unsupported type. can't set ${hint.type} via env. ${envVar}`);
throw new Error(`Environment key ${envKey} has an unsupported type. Cannot set ${hint.type} via environment. Received ${envVar}`);
}
}
}
if (CONFIG_OPTION.PRINT_LOADED_ENV_CONFIG) {
for (const key in r) {
configLogger.info(`loaded env:${genEnvKey(category, key)} : ${r[key]}`);
configLogger.info(`Loaded environment key: ${genEnvKey(category, key)}=${r[key]}`);
}
}
return r;
Expand Down

0 comments on commit e559ba2

Please sign in to comment.