fix(config): adjusts getUserId to optionally create/fill in the (currently hardcoded) userId to the telemetry object if it is not found. This prevents the telemetry call from landing as null for users who may have a taskmasterconfig but no userId in the globals.

This commit is contained in:
Eyal Toledano
2025-05-16 17:41:48 -04:00
parent bc19bc7927
commit 70fa5b0031

View File

@@ -676,7 +676,25 @@ function isConfigFilePresent(explicitRoot = null) {
*/
function getUserId(explicitRoot = null) {
const config = getConfig(explicitRoot);
return config?.global?.userId || null;
if (!config.global) {
config.global = {}; // Ensure global object exists
}
if (!config.global.userId) {
config.global.userId = '1234567890';
// Attempt to write the updated config.
// It's important that writeConfig correctly resolves the path
// using explicitRoot, similar to how getConfig does.
const success = writeConfig(config, explicitRoot);
if (!success) {
// Log an error or handle the failure to write,
// though for now, we'll proceed with the in-memory default.
log(
'warning',
'Failed to write updated configuration with new userId. Please let the developers know.'
);
}
}
return config.global.userId;
}
/**