From 53870857efb6ac574a69262086db9489fa802a01 Mon Sep 17 00:00:00 2001 From: Lucas 'Paperboy' Rose-Winters Date: Thu, 6 Nov 2025 22:57:59 +1100 Subject: [PATCH] debug: add detailed logging to extractSkills function Add verbose debug logging to trace why Skills section extraction is failing. Logs added: - Whether statsText is provided - Text length and if it contains 'Skills:' - Whether main regex matched - If 'On Person:' exists (lookahead target) - 200 chars of text around Skills section - Whether simple format fallback matched - Captured text length when successful This will help diagnose why parser logs show 'Skills extraction failed' even when Skills section clearly exists in the text. Related: Skills categorization issue investigation --- src/systems/generation/parser.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/systems/generation/parser.js b/src/systems/generation/parser.js index 75891d3..f240b9b 100644 --- a/src/systems/generation/parser.js +++ b/src/systems/generation/parser.js @@ -147,23 +147,37 @@ function debugLog(message, data = null) { * @returns {Object|null} Structured skills data or null if not found */ function extractSkills(statsText) { - if (!statsText) return null; + if (!statsText) { + debugLog('[RPG Parser] extractSkills: No stats text provided'); + return null; + } + + debugLog('[RPG Parser] extractSkills: Searching for Skills section in text length:', statsText.length); + debugLog('[RPG Parser] extractSkills: Text contains "Skills:":', statsText.includes('Skills:')); // Find the Skills section const skillsMatch = statsText.match(/Skills:([\s\S]*?)(?=\n\n|On Person:|Stored|Assets:|Main Quest|Optional Quest|$)/i); if (!skillsMatch) { + debugLog('[RPG Parser] extractSkills: Main regex did not match'); + debugLog('[RPG Parser] extractSkills: Checking if "On Person:" exists:', statsText.includes('On Person:')); + debugLog('[RPG Parser] extractSkills: Text around Skills:', statsText.substring(statsText.indexOf('Skills:'), statsText.indexOf('Skills:') + 200)); + // Fallback: try simple format "Skills: skill1, skill2" const simpleMatch = statsText.match(/Skills:\s*(.+)/i); if (simpleMatch) { const skillsText = simpleMatch[1].trim(); + debugLog('[RPG Parser] extractSkills: Simple format matched:', skillsText); if (skillsText && skillsText !== 'None') { // Return as string for backward compatibility return skillsText; } } + debugLog('[RPG Parser] extractSkills: No Skills section found'); return null; } + debugLog('[RPG Parser] extractSkills: Main regex matched, captured length:', skillsMatch[1].length); + const skillsSection = skillsMatch[1]; const skillsData = { version: 1,