From 445cd63577d3afe56acf6b98af326cd26f772192 Mon Sep 17 00:00:00 2001 From: Roo Code Date: Mon, 30 Jun 2025 07:58:05 +0000 Subject: [PATCH] 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 --- src/core/config/CustomModesManager.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/core/config/CustomModesManager.ts b/src/core/config/CustomModesManager.ts index b96293ee49..9d2019b26c 100644 --- a/src/core/config/CustomModesManager.ts +++ b/src/core/config/CustomModesManager.ts @@ -134,8 +134,23 @@ export class CustomModesManager { const errorMsg = yamlError instanceof Error ? yamlError.message : String(yamlError) console.error(`[CustomModesManager] Failed to parse YAML from ${filePath}:`, errorMsg) - const lineMatch = errorMsg.match(/at line (\d+)/) - const line = lineMatch ? lineMatch[1] : "unknown" + // Try multiple patterns to extract line number from YAML error messages + const linePatterns = [ + /at line (\d+)/, // "at line X" + /line (\d+)/, // "line X" + /\((\d+):\d+\)/, // "(line:column)" + /(\d+):\d+/, // "line:column" + ] + + let line = "unknown" + for (const pattern of linePatterns) { + const match = errorMsg.match(pattern) + if (match) { + line = match[1] + break + } + } + vscode.window.showErrorMessage(t("common:customModes.errors.yamlParseError", { line })) // Return empty object to prevent duplicate error handling