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 1, 2023
1 parent 72e6f2e commit bcdfafc
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions pkg/rancher-desktop/main/deploymentProfiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ function readRegistryUsingSchema(schemaObj: Record<string, any>, regKey: nativeR
}
});
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 @@ -244,7 +244,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 @@ -264,12 +264,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 @@ -296,7 +297,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 @@ -353,7 +354,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 @@ -369,7 +370,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 @@ -379,18 +380,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 All @@ -410,7 +411,7 @@ function validateDeploymentProfile(profile: any, schema: any, parentPathParts: s
if (typeof profile[key] === 'object') {
if (Array.isArray(profile[key])) {
if (!Array.isArray(schema[key])) {
console.log(`Deployment Profile ignoring '${ parentPathParts.join('.') }.${ key }': got an array, expecting type ${ typeof schema[key] }.`);
console.error(`Deployment Profile ignoring '${ parentPathParts.join('.') }.${ key }': got an array, expecting type ${ typeof schema[key] }.`);
delete profile[key];
}
} else if (parentPathParts.length <= 2 && isSpecialObject(parentPathParts, key.toLowerCase())) {
Expand All @@ -419,11 +420,11 @@ function validateDeploymentProfile(profile: any, schema: any, parentPathParts: s
validateDeploymentProfile(profile[key], schema[key], parentPathParts.concat(key));
}
} else if (typeof profile[key] !== typeof schema[key]) {
console.log(`Deployment Profile ignoring '${ parentPathParts.join('.') }.${ key }': expecting value of type ${ typeof schema[key] }, got ${ typeof profile[key] }.`);
console.error(`Deployment Profile ignoring '${ parentPathParts.join('.') }.${ key }': expecting value of type ${ typeof schema[key] }, got ${ typeof profile[key] }.`);
delete profile[key];
}
} else {
console.log(`Deployment Profile ignoring '${ parentPathParts.join('.') }.${ key }': not in schema.`);
console.error(`Deployment Profile ignoring '${ parentPathParts.join('.') }.${ key }': not in schema.`);
delete profile[key];
}
}
Expand Down

0 comments on commit bcdfafc

Please sign in to comment.