Skip to content

Commit

Permalink
Raise the severity of unsurfaced deployment issues.
Browse files Browse the repository at this point in the history
Currently if there are certain errors in a deployment profile,
such as unrecognized names or type mismatches, we log them but
they aren't fatal, and aren't shown in a dialog box.

We should raise the severity of these so if we one day allow
users to turn off `console.log` log-level messages, these will persist.

Also report a type mismatch when a user-defined key (like WSL/integrations)
is pointing to a scalar value.

Signed-off-by: Eric Promislow <[email protected]>
  • Loading branch information
ericpromislow committed May 2, 2023
1 parent 8e41503 commit 0f42874
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pkg/rancher-desktop/main/deploymentProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ function readRegistryUsingSchema(schemaObj: Record<string, any>, regKey: nativeR

if (key === '') {
unknownKeys.push(originalKey);
} else if (isUserDefinedObjectIgnoreCase(pathParts.slice(2).map(s => s.toLowerCase()), key.toLowerCase(), true)) {
} else if (isUserDefinedObjectIgnoreCase(pathParts.slice(2).map(s => s.toLowerCase()), key.toLowerCase())) {
specialObjectKeys.push([key, originalKey]);
} else {
commonKeys.push([key, originalKey]);
}
});
if (unknownKeys.length) {
console.log(`Unrecognized keys in registry at \\${ pathParts.join('\\') }: [${ unknownKeys.join(', ') }]`);
console.error(`Unrecognized keys in registry at \\${ pathParts.join('\\') }: [${ unknownKeys.join(', ') }]`);
}

// First process the nested keys, then process any values
Expand All @@ -242,7 +242,7 @@ function readRegistryUsingSchema(schemaObj: Record<string, any>, regKey: nativeR
if (typeof schemaVal !== 'object' || !schemaVal) {
const valueType = schemaVal ? typeof schemaVal : 'null';

console.log(`Registry key ${ registryKey } of path ${ pathParts.join('\\') } should be a value of type ${ valueType }, not a registry hive`);
console.error(`Registry key ${ registryKey } of path ${ pathParts.join('\\') } should be a value of type ${ valueType }, not a registry hive`);
continue;
}
if (!innerKey) {
Expand All @@ -262,12 +262,13 @@ function readRegistryUsingSchema(schemaObj: Record<string, any>, regKey: nativeR
const innerKey = nativeReg.openKey(regKey, registryKey, nativeReg.Access.READ);

if (innerKey === null) {
console.error(`No value for registry object ${ pathParts.join('\\') }\\${ registryKey }`);
continue;
}
try {
regValue = readRegistryObject(innerKey, pathParts.concat([schemaKey]), true);
} catch (err: any) {
console.log(`Error getting registry object for ${ pathParts.join('/') }: `, err);
console.error(`Error getting registry object for ${ pathParts.join('\\') }\\${ registryKey }: `, err);
} finally {
nativeReg.closeKey(innerKey);
}
Expand All @@ -294,7 +295,7 @@ function readRegistryUsingSchema(schemaObj: Record<string, any>, regKey: nativeR
}
});
if (unknownValueNames.length > 0) {
console.log(`Unrecognized value names in registry at ${ pathParts.join('\\') }: [${ unknownValueNames.join(', ') }]`);
console.error(`Unrecognized value names in registry at ${ pathParts.join('\\') }: [${ unknownValueNames.join(', ') }]`);
}

return newObject;
Expand Down Expand Up @@ -351,7 +352,7 @@ function readRegistryValue(schemaVal: any, regKey: nativeReg.HKEY, pathParts: st

if (schemaVal && typeof schemaVal === 'object') {
if (!Array.isArray(schemaVal)) {
console.log(`Ignoring unexpected value field ${ fullPath } found in the registry`);
console.error(`Ignoring unexpected value field ${ fullPath } found in the registry`);

return null;
}
Expand All @@ -367,7 +368,7 @@ function readRegistryValue(schemaVal: any, regKey: nativeReg.HKEY, pathParts: st
if (schemaVal === undefined || typeof schemaVal === 'string') {
parsedValue = nativeReg.parseValue(rawValue) as string;
} else {
console.log(`Expecting registry entry ${ fullPath } to be a string, but it's a ${ valueTypeNames[rawValue.type] }`);
console.error(`Expecting registry entry ${ fullPath } to be a string, but it's a ${ valueTypeNames[rawValue.type] }`);
}
break;
case nativeReg.ValueType.DWORD:
Expand All @@ -377,18 +378,18 @@ function readRegistryValue(schemaVal: any, regKey: nativeReg.HKEY, pathParts: st
if (typeof schemaVal === 'boolean') {
return !!parsedValue;
} else if (schemaVal !== undefined && typeof schemaVal !== 'number') {
console.log(`Expecting registry entry ${ fullPath } to be a number or boolean, but it's a ${ valueTypeNames[rawValue.type] }, value: ${ parsedValue }`);
console.error(`Expecting registry entry ${ fullPath } to be a number or boolean, but it's a ${ valueTypeNames[rawValue.type] }, value: ${ parsedValue }`);
}
break;
case nativeReg.ValueType.MULTI_SZ:
if (schemaVal === undefined || (typeof schemaVal === 'object' && Array.isArray(schemaVal))) {
parsedValue = nativeReg.parseValue(rawValue) as string [];
} else {
console.log(`Expecting registry entry ${ fullPath } to be a multi-valued string, but it's a ${ valueTypeNames[rawValue.type] }`);
console.error(`Expecting registry entry ${ fullPath } to be a multi-valued string, but it's a ${ valueTypeNames[rawValue.type] }`);
}
break;
default:
console.log(`Unexpected registry entry ${ fullPath }: don't know how to process a registry entry of type ${ valueTypeNames[rawValue.type] }`);
console.error(`Unexpected registry entry ${ fullPath }: don't know how to process a registry entry of type ${ valueTypeNames[rawValue.type] }`);
}

return parsedValue;
Expand Down

0 comments on commit 0f42874

Please sign in to comment.