Skip to content

Commit

Permalink
fixed (rare) SE error potentially directing user to wrong SE log file
Browse files Browse the repository at this point in the history
Would only happen for FO3, FNV and Oblivion if the games and creation
kit were run in quick succession.

fixes Nexus-Mods/Vortex#9234
  • Loading branch information
IDCs committed May 4, 2021
1 parent 2c8cf92 commit c5d4781
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "script-extender-error-check",
"version": "0.1.0",
"version": "0.1.1",
"description": "Warn if the script extender log contains error message",
"main": "./out/index.js",
"repository": "",
Expand Down
60 changes: 41 additions & 19 deletions src/index.ts
Expand Up @@ -47,6 +47,12 @@ const compatibleGames = {
let errorState: { [modId: string]: IErrorLine } = util.makeReactive({});
let errorStateChange: () => void;

interface IErrorLog {
errLogFile: string;
errLogTime: number;
errors: IErrorLine[];
}

interface IErrorLine {
dllName: string;
modId?: string;
Expand Down Expand Up @@ -84,11 +90,13 @@ async function checkForErrors(api: types.IExtensionApi) {
return false;
}

const errors: IErrorLine[] = [];
let errLogFile: string;
let errLogTime: number = 0;
const errorInstances: IErrorLog[] = [];

await Promise.all(logPaths.map(async (filePath) => {
const errors: IErrorLine[] = [];
let errLogFile: string;
let errLogTime: number = 0;

// Replace {GamePath} if it's not a full path.
filePath = filePath.replace('{GamePath}', gamePath);

Expand All @@ -103,6 +111,10 @@ async function checkForErrors(api: types.IExtensionApi) {
errLogTime = Math.max(errLogTime, logTime);
errLogFile = filePath;
}

if (errors.length > 0) {
errorInstances.push({ errLogFile, errLogTime, errors });
}
} else {
log('debug', 'Script extender log file was not updated this session.');
}
Expand All @@ -112,7 +124,7 @@ async function checkForErrors(api: types.IExtensionApi) {
}
}));

if (errors.length > 0) {
if (errorInstances.length > 0) {
let manifest;
try {
manifest = await util.getManifest(api);
Expand All @@ -126,6 +138,12 @@ async function checkForErrors(api: types.IExtensionApi) {
'Failed to retrieve manifest information', err.message);
return false;
}

const errors = errorInstances.reduce((accum, iter) => {
accum = [].concat(accum, iter.errors);
return accum;
}, []);

const mods = state.persistent.mods[gameMode] || {};
const modLookup: { [modPath: string]: string } = Object.keys(mods).reduce((prev, modId) => {
prev[mods[modId].installationPath] = modId;
Expand All @@ -151,8 +169,20 @@ async function checkForErrors(api: types.IExtensionApi) {
return `- "${input.dllName}" (${modName}): ${api.translate(input.message)}`;
};

const logTime = new Date(errLogTime);

const buildLogErrorString = (errLog: IErrorLog): string => {
const logTime = new Date(errLog.errLogTime);
return api.translate('[url={{logPathURI}}]{{logPath}}[/url] {{pathSep}} [url={{logURI}}]{{logName}}[/url]<br/>'
+ (((Date.now() - logTime.getTime()) > ONE_HOUR)
? '[color=red]Reported {{logTime}}.[/color]<br/><br/>'
: 'Reported {{logTime}}.<br/><br/>'), { replace: {
logPath: path.dirname(errLog.errLogFile),
logName: path.basename(errLog.errLogFile),
logPathURI: url.pathToFileURL(path.dirname(errLog.errLogFile)),
logURI: url.pathToFileURL(errLog.errLogFile),
pathSep: path.sep,
logTime: util.relativeTime(logTime, api.translate),
}});
};
api.sendNotification({
id: 'script-extender-errors',
type: 'warning',
Expand All @@ -162,25 +192,17 @@ async function checkForErrors(api: types.IExtensionApi) {
{
title: 'More', action: () =>
api.showDialog('info', 'Script extender plugin errors', {
bbcode: api.translate('Last time you ran the game, one or more script extender '
+ 'plugins failed to load.<br/>'
+ 'This is according to [url={{logPathURI}}]{{logPath}}[/url] {{pathSep}} [url={{logURI}}]{{logName}}[/url]<br/>'
+ (((Date.now() - logTime.getTime()) > ONE_HOUR)
? '[color=red]Reported {{logTime}}.[/color]<br/><br/>'
: 'Reported {{logTime}}.<br/><br/>')
bbcode: api.translate('Last time you ran the game or Creation kit, one or more script extender '
+ 'plugins failed to load; this is according to:<br/>'
+ '{{errorInformation}}'
+ 'This normally happens when you try to load mods which are not compatible with '
+ 'the installed version of the script extender.<br/>'
+ 'To fix this problem you can check for an update on the mod page of the failed '
+ 'plugin or disable the mod until it is updated.<br/><br/>'
+ 'Error(s) reported:'
+ '<br/>', {
replace: {
logPath: path.dirname(errLogFile),
logName: path.basename(errLogFile),
logPathURI: url.pathToFileURL(path.dirname(errLogFile)),
logURI: url.pathToFileURL(errLogFile),
pathSep: path.sep,
logTime: util.relativeTime(logTime, api.translate),
errorInformation: errorInstances.map(buildLogErrorString),
},
}) + errors.map(renderError).join('<br/>'),
options: {
Expand All @@ -204,7 +226,7 @@ async function checkForErrors(api: types.IExtensionApi) {
],
});
}
return errors.length > 0;
return errorInstances.length > 0;
}

const loadStatusMessages = [
Expand Down

0 comments on commit c5d4781

Please sign in to comment.