@@ -123,18 +123,29 @@ export class CustomModesManager {
123123
124124 try {
125125 return yaml . parse ( cleanedContent )
126- } catch ( error ) {
127- const errorMsg = error instanceof Error ? error . message : String ( error )
128- console . error ( `[CustomModesManager] Failed to parse YAML from ${ filePath } :` , errorMsg )
129-
130- // Show user-friendly error message for .roomodes files
126+ } catch ( yamlError ) {
127+ // For .roomodes files, try JSON as fallback
131128 if ( filePath . endsWith ( ROOMODES_FILENAME ) ) {
132- const lineMatch = errorMsg . match ( / a t l i n e ( \d + ) / )
133- const line = lineMatch ? lineMatch [ 1 ] : "unknown"
134- vscode . window . showErrorMessage ( t ( "common:customModes.errors.yamlParseError" , { line } ) )
129+ try {
130+ // Try parsing the original content as JSON (not the cleaned content)
131+ return JSON . parse ( content )
132+ } catch ( jsonError ) {
133+ // JSON also failed, show the original YAML error
134+ const errorMsg = yamlError instanceof Error ? yamlError . message : String ( yamlError )
135+ console . error ( `[CustomModesManager] Failed to parse YAML from ${ filePath } :` , errorMsg )
136+
137+ const lineMatch = errorMsg . match ( / a t l i n e ( \d + ) / )
138+ const line = lineMatch ? lineMatch [ 1 ] : "unknown"
139+ vscode . window . showErrorMessage ( t ( "common:customModes.errors.yamlParseError" , { line } ) )
140+
141+ // Return empty object to prevent duplicate error handling
142+ return { }
143+ }
135144 }
136145
137- // Return empty object to prevent duplicate error handling
146+ // For non-.roomodes files, just log and return empty object
147+ const errorMsg = yamlError instanceof Error ? yamlError . message : String ( yamlError )
148+ console . error ( `[CustomModesManager] Failed to parse YAML from ${ filePath } :` , errorMsg )
138149 return { }
139150 }
140151 }
@@ -205,12 +216,7 @@ export class CustomModesManager {
205216 const fileExists = await fileExistsAtPath ( filePath )
206217
207218 if ( ! fileExists ) {
208- await this . queueWrite ( ( ) =>
209- fs . writeFile (
210- filePath ,
211- yaml . stringify ( { customModes : [ ] } , { lineWidth : 0 , defaultStringType : "PLAIN" } ) ,
212- ) ,
213- )
219+ await this . queueWrite ( ( ) => fs . writeFile ( filePath , yaml . stringify ( { customModes : [ ] } , { lineWidth : 0 } ) ) )
214220 }
215221
216222 return filePath
@@ -414,7 +420,7 @@ export class CustomModesManager {
414420 content = await fs . readFile ( filePath , "utf-8" )
415421 } catch ( error ) {
416422 // File might not exist yet.
417- content = yaml . stringify ( { customModes : [ ] } , { lineWidth : 0 , defaultStringType : "PLAIN" } )
423+ content = yaml . stringify ( { customModes : [ ] } , { lineWidth : 0 } )
418424 }
419425
420426 let settings
@@ -427,7 +433,7 @@ export class CustomModesManager {
427433 }
428434
429435 settings . customModes = operation ( settings . customModes || [ ] )
430- await fs . writeFile ( filePath , yaml . stringify ( settings , { lineWidth : 0 , defaultStringType : "PLAIN" } ) , "utf-8" )
436+ await fs . writeFile ( filePath , yaml . stringify ( settings , { lineWidth : 0 } ) , "utf-8" )
431437 }
432438
433439 private async refreshMergedState ( ) : Promise < void > {
@@ -485,10 +491,7 @@ export class CustomModesManager {
485491 public async resetCustomModes ( ) : Promise < void > {
486492 try {
487493 const filePath = await this . getCustomModesFilePath ( )
488- await fs . writeFile (
489- filePath ,
490- yaml . stringify ( { customModes : [ ] } , { lineWidth : 0 , defaultStringType : "PLAIN" } ) ,
491- )
494+ await fs . writeFile ( filePath , yaml . stringify ( { customModes : [ ] } , { lineWidth : 0 } ) )
492495 await this . context . globalState . update ( "customModes" , [ ] )
493496 this . clearCache ( )
494497 await this . onUpdate ( )
0 commit comments