Make schema validation errors non-fatal (#15487)

This commit is contained in:
Jacob Richman
2025-12-23 10:26:37 -08:00
committed by GitHub
parent e9a601c1fe
commit b6b0727e28
5 changed files with 191 additions and 13 deletions
+16 -9
View File
@@ -233,6 +233,7 @@ export interface SessionRetentionSettings {
export interface SettingsError {
message: string;
path: string;
severity: 'error' | 'warning';
}
export interface SettingsFile {
@@ -456,6 +457,7 @@ export class LoadedSettings {
workspace: SettingsFile,
isTrusted: boolean,
migratedInMemoryScopes: Set<SettingScope>,
errors: SettingsError[] = [],
) {
this.system = system;
this.systemDefaults = systemDefaults;
@@ -463,6 +465,7 @@ export class LoadedSettings {
this.workspace = workspace;
this.isTrusted = isTrusted;
this.migratedInMemoryScopes = migratedInMemoryScopes;
this.errors = errors;
this._merged = this.computeMergedSettings();
}
@@ -472,6 +475,7 @@ export class LoadedSettings {
readonly workspace: SettingsFile;
readonly isTrusted: boolean;
readonly migratedInMemoryScopes: Set<SettingScope>;
readonly errors: SettingsError[];
private _merged: Settings;
@@ -658,6 +662,7 @@ export function loadSettings(
settingsErrors.push({
message: 'Settings file is not a valid JSON object.',
path: filePath,
severity: 'error',
});
return { settings: {} };
}
@@ -695,19 +700,20 @@ export function loadSettings(
validationResult.error,
filePath,
);
throw new FatalConfigError(errorMessage);
settingsErrors.push({
message: errorMessage,
path: filePath,
severity: 'warning',
});
}
return { settings: settingsObject as Settings, rawJson: content };
}
} catch (error: unknown) {
// Preserve FatalConfigError with formatted validation messages
if (error instanceof FatalConfigError) {
throw error;
}
settingsErrors.push({
message: getErrorMessage(error),
path: filePath,
severity: 'error',
});
}
return { settings: {} };
@@ -779,10 +785,10 @@ export function loadSettings(
// the settings to avoid a cycle
loadEnvironment(tempMergedSettings);
// Create LoadedSettings first
if (settingsErrors.length > 0) {
const errorMessages = settingsErrors.map(
// Check for any fatal errors before proceeding
const fatalErrors = settingsErrors.filter((e) => e.severity === 'error');
if (fatalErrors.length > 0) {
const errorMessages = fatalErrors.map(
(error) => `Error in ${error.path}: ${error.message}`,
);
throw new FatalConfigError(
@@ -817,6 +823,7 @@ export function loadSettings(
},
isTrusted,
migratedInMemoryScopes,
settingsErrors,
);
}