Skip to content

Commit bd517da

Browse files
committed
fix: handle null/undefined settings in updateModesInFile and loadModesFromFile
- Ensure settings object exists before accessing customModes property - Initialize customModes as empty array if undefined - Prevent 'Cannot read properties of null' error during mode import - Add proper validation in loadModesFromFile before schema check
1 parent bd21f6e commit bd517da

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/core/config/CustomModesManager.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ export class CustomModesManager {
182182
try {
183183
const content = await fs.readFile(filePath, "utf-8")
184184
const settings = this.parseYamlSafely(content, filePath)
185+
186+
// Ensure settings has customModes property
187+
if (!settings || typeof settings !== "object" || !settings.customModes) {
188+
return []
189+
}
190+
185191
const result = customModesSettingsSchema.safeParse(settings)
186192

187193
if (!result.success) {
@@ -460,7 +466,15 @@ export class CustomModesManager {
460466
settings = { customModes: [] }
461467
}
462468

463-
settings.customModes = operation(settings.customModes || [])
469+
// Ensure settings is an object and has customModes property
470+
if (!settings || typeof settings !== "object") {
471+
settings = { customModes: [] }
472+
}
473+
if (!settings.customModes) {
474+
settings.customModes = []
475+
}
476+
477+
settings.customModes = operation(settings.customModes)
464478
await fs.writeFile(filePath, yaml.stringify(settings, { lineWidth: 0 }), "utf-8")
465479
}
466480

0 commit comments

Comments
 (0)