Skip to content

Commit 445cd63

Browse files
committed
Fixes #5139: Improve YAML error line number extraction for .roomodes files
- Enhanced line number extraction in CustomModesManager to handle multiple YAML error message formats - Added support for patterns: 'at line X', 'line X', '(line:column)', and 'line:column' - Ensures robust error reporting when .roomodes files have YAML syntax errors - Maintains backward compatibility with existing error handling
1 parent 3a8ba27 commit 445cd63

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

src/core/config/CustomModesManager.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,23 @@ export class CustomModesManager {
134134
const errorMsg = yamlError instanceof Error ? yamlError.message : String(yamlError)
135135
console.error(`[CustomModesManager] Failed to parse YAML from ${filePath}:`, errorMsg)
136136

137-
const lineMatch = errorMsg.match(/at line (\d+)/)
138-
const line = lineMatch ? lineMatch[1] : "unknown"
137+
// Try multiple patterns to extract line number from YAML error messages
138+
const linePatterns = [
139+
/at line (\d+)/, // "at line X"
140+
/line (\d+)/, // "line X"
141+
/\((\d+):\d+\)/, // "(line:column)"
142+
/(\d+):\d+/, // "line:column"
143+
]
144+
145+
let line = "unknown"
146+
for (const pattern of linePatterns) {
147+
const match = errorMsg.match(pattern)
148+
if (match) {
149+
line = match[1]
150+
break
151+
}
152+
}
153+
139154
vscode.window.showErrorMessage(t("common:customModes.errors.yamlParseError", { line }))
140155

141156
// Return empty object to prevent duplicate error handling

0 commit comments

Comments
 (0)