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
This commit is contained in:
Lucas 'Paperboy' Rose-Winters
2025-11-06 22:57:59 +11:00
parent cf993b2eaa
commit 53870857ef
+15 -1
View File
@@ -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,