debug: add comprehensive logging to skills parser
Add detailed console logging to trace how skills are being parsed and categorized. This will help diagnose why skills are ending up in "Uncategorized" instead of their proper categories. Debug logs added: - Log all lines extracted from skills section - Log when category headers are detected - Log when category arrays are created - Log when skills are added to categories vs uncategorized - Log ERROR when skill can't be added due to missing category array - Log final skills data structure with category counts Fallback behavior: - If skill can't be added to its category (category array doesn't exist), fall back to uncategorized with ERROR log To see logs: - Enable Debug Mode in RPG Companion settings - Check browser console during AI response parsing - Look for "[RPG Parser]" prefix Related: Skills categorization issue investigation
This commit is contained in:
@@ -174,14 +174,18 @@ function extractSkills(statsText) {
|
|||||||
// Split into lines and process
|
// Split into lines and process
|
||||||
const lines = skillsSection.split('\n').map(line => line.trim()).filter(line => line);
|
const lines = skillsSection.split('\n').map(line => line.trim()).filter(line => line);
|
||||||
|
|
||||||
|
debugLog('[RPG Parser] Skills section lines:', lines);
|
||||||
|
|
||||||
let currentCategory = null;
|
let currentCategory = null;
|
||||||
|
|
||||||
for (const line of lines) {
|
for (const line of lines) {
|
||||||
// Check if this is a category header (ends with colon, no dash)
|
// Check if this is a category header (ends with colon, no dash)
|
||||||
if (line.endsWith(':') && !line.startsWith('-')) {
|
if (line.endsWith(':') && !line.startsWith('-')) {
|
||||||
currentCategory = line.slice(0, -1).trim();
|
currentCategory = line.slice(0, -1).trim();
|
||||||
|
debugLog(`[RPG Parser] Found category header: "${currentCategory}"`);
|
||||||
if (currentCategory !== 'Uncategorized' && !skillsData.categories[currentCategory]) {
|
if (currentCategory !== 'Uncategorized' && !skillsData.categories[currentCategory]) {
|
||||||
skillsData.categories[currentCategory] = [];
|
skillsData.categories[currentCategory] = [];
|
||||||
|
debugLog(`[RPG Parser] Created category array for: "${currentCategory}"`);
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -201,9 +205,15 @@ function extractSkills(statsText) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (currentCategory === 'Uncategorized' || currentCategory === null) {
|
if (currentCategory === 'Uncategorized' || currentCategory === null) {
|
||||||
|
debugLog(`[RPG Parser] Adding "${skillName}" to uncategorized (currentCategory="${currentCategory}")`);
|
||||||
skillsData.uncategorized.push(skill);
|
skillsData.uncategorized.push(skill);
|
||||||
} else if (currentCategory && skillsData.categories[currentCategory]) {
|
} else if (currentCategory && skillsData.categories[currentCategory]) {
|
||||||
|
debugLog(`[RPG Parser] Adding "${skillName}" to category "${currentCategory}"`);
|
||||||
skillsData.categories[currentCategory].push(skill);
|
skillsData.categories[currentCategory].push(skill);
|
||||||
|
} else {
|
||||||
|
debugLog(`[RPG Parser] ERROR: Could not add "${skillName}" - currentCategory="${currentCategory}", categoryExists=${!!skillsData.categories[currentCategory]}`);
|
||||||
|
// Fallback to uncategorized if category doesn't exist
|
||||||
|
skillsData.uncategorized.push(skill);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Fallback: Try text-based proficiency format: "- Skill Name (Proficient)"
|
// Fallback: Try text-based proficiency format: "- Skill Name (Proficient)"
|
||||||
@@ -239,9 +249,15 @@ function extractSkills(statsText) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (currentCategory === 'Uncategorized' || currentCategory === null) {
|
if (currentCategory === 'Uncategorized' || currentCategory === null) {
|
||||||
|
debugLog(`[RPG Parser] Adding "${skillName}" to uncategorized (currentCategory="${currentCategory}")`);
|
||||||
skillsData.uncategorized.push(skill);
|
skillsData.uncategorized.push(skill);
|
||||||
} else if (currentCategory && skillsData.categories[currentCategory]) {
|
} else if (currentCategory && skillsData.categories[currentCategory]) {
|
||||||
|
debugLog(`[RPG Parser] Adding "${skillName}" to category "${currentCategory}"`);
|
||||||
skillsData.categories[currentCategory].push(skill);
|
skillsData.categories[currentCategory].push(skill);
|
||||||
|
} else {
|
||||||
|
debugLog(`[RPG Parser] ERROR: Could not add "${skillName}" - currentCategory="${currentCategory}", categoryExists=${!!skillsData.categories[currentCategory]}`);
|
||||||
|
// Fallback to uncategorized if category doesn't exist
|
||||||
|
skillsData.uncategorized.push(skill);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -252,6 +268,12 @@ function extractSkills(statsText) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
debugLog('[RPG Parser] Final skills data:', {
|
||||||
|
categories: Object.keys(skillsData.categories),
|
||||||
|
categoryCounts: Object.entries(skillsData.categories).map(([cat, skills]) => `${cat}: ${skills.length}`),
|
||||||
|
uncategorizedCount: skillsData.uncategorized.length
|
||||||
|
});
|
||||||
|
|
||||||
return skillsData;
|
return skillsData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user