fix: handle achievement parse error causing hydra to never search new achievements in real time

This commit is contained in:
Zamitto 2024-12-13 16:48:09 -03:00
parent 58cbf78fb9
commit 6f417d23d1
2 changed files with 127 additions and 133 deletions

View file

@ -236,6 +236,7 @@ export class AchievementWatcherManager {
}; };
public static preSearchAchievements = async () => { public static preSearchAchievements = async () => {
try {
const newAchievementsCount = const newAchievementsCount =
process.platform === "win32" process.platform === "win32"
? await this.preSearchAchievementsWindows() ? await this.preSearchAchievementsWindows()
@ -255,6 +256,9 @@ export class AchievementWatcherManager {
totalNewGamesWithAchievements totalNewGamesWithAchievements
); );
} }
} catch (err) {
achievementsLogger.error("Error on preSearchAchievements", err);
}
this.hasFinishedMergingWithRemote = true; this.hasFinishedMergingWithRemote = true;
}; };

View file

@ -9,6 +9,7 @@ export const parseAchievementFile = (
): UnlockedAchievement[] => { ): UnlockedAchievement[] => {
if (!existsSync(filePath)) return []; if (!existsSync(filePath)) return [];
try {
if (type == Cracker.codex) { if (type == Cracker.codex) {
const parsed = iniParse(filePath); const parsed = iniParse(filePath);
return processDefault(parsed); return processDefault(parsed);
@ -78,10 +79,13 @@ export const parseAchievementFile = (
`Unprocessed ${type} achievements found on ${filePath}` `Unprocessed ${type} achievements found on ${filePath}`
); );
return []; return [];
} catch (err) {
achievementsLogger.error(`Error parsing ${type} - ${filePath}`, err);
return [];
}
}; };
const iniParse = (filePath: string) => { const iniParse = (filePath: string) => {
try {
const fileContent = readFileSync(filePath, "utf-8"); const fileContent = readFileSync(filePath, "utf-8");
const lines = const lines =
@ -105,23 +109,13 @@ const iniParse = (filePath: string) => {
} }
return object; return object;
} catch (err) {
achievementsLogger.error(`Error parsing ${filePath}`, err);
return {};
}
}; };
const jsonParse = (filePath: string) => { const jsonParse = (filePath: string) => {
try {
return JSON.parse(readFileSync(filePath, "utf-8")); return JSON.parse(readFileSync(filePath, "utf-8"));
} catch (err) {
achievementsLogger.error(`Error parsing ${filePath}`, err);
return {};
}
}; };
const processRazor1911 = (filePath: string): UnlockedAchievement[] => { const processRazor1911 = (filePath: string): UnlockedAchievement[] => {
try {
const fileContent = readFileSync(filePath, "utf-8"); const fileContent = readFileSync(filePath, "utf-8");
const lines = const lines =
@ -143,10 +137,6 @@ const processRazor1911 = (filePath: string): UnlockedAchievement[] => {
} }
return achievements; return achievements;
} catch (err) {
achievementsLogger.error(`Error processing ${filePath}`, err);
return [];
}
}; };
const processOnlineFix = (unlockedAchievements: any): UnlockedAchievement[] => { const processOnlineFix = (unlockedAchievements: any): UnlockedAchievement[] => {