From 6589bcc0a20642d47f7404f48b85bf0ae7784c8a Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 19 Oct 2023 15:18:07 +0100 Subject: [PATCH] Show human readable error when two mods have conflciting load order requirements Improve cyclic error message text --- project/assets/database/locales/server/en.json | 3 ++- project/src/loaders/ModLoadOrder.ts | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/project/assets/database/locales/server/en.json b/project/assets/database/locales/server/en.json index 5b1fdbb9..f616bfa4 100644 --- a/project/assets/database/locales/server/en.json +++ b/project/assets/database/locales/server/en.json @@ -116,7 +116,8 @@ "mod-send_bundle_url": "[BUNDLE]: %s", "modloader-checked": "checked", "modloader-checking_mod": "checking: %s", - "modloader-cyclic_dependency": "Cyclic dependency detected", + "modloader-cyclic_dependency": "Cyclic dependency detected. This error needs to be fixed. The server is unable to start until this is fixed and will shut down", + "modloader-load_order_conflict": "`{{modOneName}}` and `{{modTwoName}}` have conflicting load order requirements, the server is unable to start until this is fixed and will shut down", "modloader-dependency_container_not_initalized": "The dependency container was requested but it wasnt initialized", "modloader-error_parsing_mod_load_order": "Error parsing mod load order", "modloader-incompatibilities_not_string_array": "Mod %s package.json property 'incompatibilities' should be a string array", diff --git a/project/src/loaders/ModLoadOrder.ts b/project/src/loaders/ModLoadOrder.ts index a68c0fe5..99b6ed34 100644 --- a/project/src/loaders/ModLoadOrder.ts +++ b/project/src/loaders/ModLoadOrder.ts @@ -1,4 +1,5 @@ import { inject, injectable } from "tsyringe"; + import { IPackageJsonData } from "../models/spt/mod/IPackageJsonData"; import { ILogger } from "../models/spt/utils/ILogger"; import { LocalisationService } from "../services/LocalisationService"; @@ -139,19 +140,25 @@ export class ModLoadOrder config.loadAfter ??= []; config.modDependencies ??= {}; - const loadAfter = new Set(Object.keys(config.modDependencies)); + const dependencies = new Set(Object.keys(config.modDependencies)); - for (const after of config.loadAfter) + for (const modAfter of config.loadAfter) { - if (this.modsAvailable.has(after)) + if (this.modsAvailable.has(modAfter)) { - loadAfter.add(after); + if (this.modsAvailable.get(modAfter)?.loadAfter?.includes(mod)) + { + this.logger.error(this.localisationService.getText("modloader-load_order_conflict", {modOneName: mod, modTwoName: modAfter})); + process.exit(1); + } + + dependencies.add(modAfter); } } visited.add(mod); - for (const mod of loadAfter) + for (const mod of dependencies) { this.getLoadOrderRecursive(mod, visited); }