sync from local backup
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
const fs = require('fs');
|
||||
const filePath = 'c:\\Users\\12914\\Desktop\\vscode\\chunyu_prject_react\\src\\locales\\zh.json';
|
||||
const content = fs.readFileSync(filePath, 'utf8');
|
||||
|
||||
// Try to parse and find the exact error location using JSON.parse error info
|
||||
try {
|
||||
JSON.parse(content);
|
||||
console.log('Valid JSON');
|
||||
} catch (e) {
|
||||
const match = e.message.match(/position (\d+)/);
|
||||
if (match) {
|
||||
const pos = parseInt(match[1]);
|
||||
console.log(`Error position: ${pos}`);
|
||||
console.log(`Char at pos: [${content[pos]}] (code ${content.charCodeAt(pos)})`);
|
||||
// Find line number
|
||||
let line = 1, col = 1;
|
||||
for (let i = 0; i < pos; i++) {
|
||||
if (content[i] === '\n') { line++; col = 1; }
|
||||
else col++;
|
||||
}
|
||||
console.log(`Line ${line}, Column ${col}`);
|
||||
// Print context
|
||||
const lines = content.split('\n');
|
||||
for (let j = Math.max(0, line-6); j < Math.min(lines.length, line+3); j++) {
|
||||
console.log((j+1) + ': ' + lines[j]);
|
||||
}
|
||||
} else {
|
||||
console.log(e.message);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user