Skip to content

Commit

Permalink
chore: added semantic exit codes
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Oct 7, 2023
1 parent 81b4533 commit 1fea72e
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 34 deletions.
2 changes: 1 addition & 1 deletion core/components/AdminVault/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ export default class AdminVault {
console.error('You can rey restoring it or you can delete it and let txAdmin create a new one.');
}
console.error(`Admin File Path: ${this.adminsFile}`);
process.exit(1);
process.exit(5300);
};

try {
Expand Down
6 changes: 3 additions & 3 deletions core/components/ConfigVault.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ export default class ConfigVault {
this.config = this.setupConfigDefaults(this.configFile);
this.setupFolderStructure();
} catch (error) {
console.error(error.message);
process.exit(0);
console.error(error);
process.exit(5100);
}
}

Expand Down Expand Up @@ -276,7 +276,7 @@ export default class ConfigVault {
}
} catch (error) {
console.error(`Failed to set up folder structure in '${this.serverProfilePath}/' with error: ${error.message}`);
process.exit();
process.exit(5101);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/components/FxRunner/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export default class FXRunner {
} catch (error) {
console.error('Failed to start FXServer with the following error:');
console.dir(error);
process.exit(0);
process.exit(5400);
}

//Setting up stream handlers
Expand Down
2 changes: 1 addition & 1 deletion core/components/PerformanceCollector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default class PerformanceCollector {
this.perfSeries = [];
} catch (error) {
console.error(`Unable to create stats_heatmapData_v1 with error: ${error.message}`);
process.exit();
process.exit(5500);
}
};

Expand Down
4 changes: 2 additions & 2 deletions core/components/PlayerDatabase/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export class Database {
console.error(`Backup error: '${(errorBackup as Error).message}'`);
console.error(`Database path: '${this.dbPath}'`);
console.error('If there is a file in that location, you may try to delete or restore it manually.');
process.exit();
process.exit(5600);
}
}

Expand All @@ -141,7 +141,7 @@ export class Database {
} catch (error) {
console.error('Failed to setup database object.');
console.dir(error);
process.exit();
process.exit(5601);
}
}

Expand Down
6 changes: 3 additions & 3 deletions core/components/PlayerDatabase/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ export default async (dbo) => {
}
if (typeof dbo.data.version !== 'number') {
console.error('Your players database version is not a number!');
process.exit(1);
process.exit(5650);
}
if (dbo.data.version > DATABASE_VERSION) {
console.error(`Your players database is on v${dbo.data.version}, and this txAdmin supports up to v${DATABASE_VERSION}.`);
console.error('This means you likely downgraded your txAdmin version. Please update txAdmin.');
process.exit(1);
process.exit(5651);
}

//Migrate database
Expand Down Expand Up @@ -142,7 +142,7 @@ export default async (dbo) => {
console.error(`Your players database is on v${dbo.data.version}, which is different from this version of txAdmin (v${DATABASE_VERSION}).`);
console.error('Since there is currently no migration method ready for the migration, txAdmin will attempt to use it anyways.');
console.error('Please make sure your txAdmin is on the most updated version!');
process.exit(1);
process.exit(5652);
}
console.ok('Database migrated successfully');
return dbo;
Expand Down
2 changes: 1 addition & 1 deletion core/components/StatisticsManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default class StatisticsManager {
this.#publicKey = await jose.importSPKI(statsPublicKeyPem, 'RS256');
} catch (error) {
console.dir(error);
process.exit(1);
process.exit(5700);
}
}

Expand Down
2 changes: 1 addition & 1 deletion core/components/Translator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export default class Translator {
this.#polyglot = new Polyglot(polyglotOptions);
} catch (error) {
console.dir(error);
if (isFirstTime) process.exit();
if (isFirstTime) process.exit(5200);
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/components/WebServer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ export default class WebServer {
console.error('Maybe you already have another txAdmin running in this port.');
console.error('If you want to run multiple txAdmin instances, check the documentation for the port convar.');
console.error('You can also try restarting the host machine.');
process.exit(1);
process.exit(5800);
};
this.httpServer = HttpClass.createServer(this.httpCallbackHandler.bind(this, 'httpserver'));
this.httpServer.on('error', listenErrorHandler);
Expand All @@ -258,7 +258,7 @@ export default class WebServer {
} catch (error) {
console.error('Failed to start HTTP server with error:');
console.dir(error);
process.exit();
process.exit(5801);
}
}
};
4 changes: 2 additions & 2 deletions core/extras/checkPreRelease.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const cronCheckExpiration = () => {
if (timeUntilExpiration < 0) {
console.error('This pre-release version has expired, please update your txAdmin.');
console.error('For more information: https://discord.gg/txAdmin.');
process.exit(1);
process.exit(400);
} else if (timeUntilExpiration < 24 * 60 * 60 * 1000) {
printExpirationBanner(timeUntilExpiration);
}
Expand All @@ -41,7 +41,7 @@ export default () => {
if (timeUntilExpiration < 0) {
console.error('This pre-release version has expired, please update your txAdmin.');
console.error('For more information: https://discord.gg/txAdmin.');
process.exit(1);
process.exit(401);
}

//First warning
Expand Down
16 changes: 9 additions & 7 deletions core/extras/setupProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default (osType, fxServerPath, fxServerVersion, serverProfile, profilePat
//Sanity check presence of profile
if (fs.existsSync(profilePath)) {
console.error(`There is already a profile named '${serverProfile}'.`);
process.exit();
process.exit(500);
}

//Create new profile folder
Expand All @@ -53,20 +53,22 @@ export default (osType, fxServerPath, fxServerVersion, serverProfile, profilePat
} catch (error) {
console.error(`Failed to set up folder structure in '${profilePath}' with error:`);
console.dir(error);
process.exit();
process.exit(501);
}
console.ok(`Server profile was saved in '${profilePath}'`);


//Saving start.bat
if (osType == 'windows') {
try {
const batData = `@echo off
"${fxServerPath}/FXServer.exe" +set serverProfile "${serverProfile}"
pause`;
const batLines = [
`@echo off`,
`"${fxServerPath}/FXServer.exe" +set serverProfile "${serverProfile}"`,
`pause`
];
const batFolder = path.resolve(fxServerPath, '..');
const batPath = path.join(batFolder, `start_${fxServerVersion}_${serverProfile}.bat`);
fs.writeFileSync(batPath, batData);
const batPath = path.join(batFolder, `start_${fxServerVersion}_${serverProfile}.bat`);
fs.writeFileSync(batPath, batLines.join('\r\n'));
console.ok(`You can use ${chalk.inverse(batPath)} to start this profile.`);
} catch (error) {
console.warn(`Failed to create 'start_${fxServerVersion}_${serverProfile}.bat' with error:`);
Expand Down
10 changes: 4 additions & 6 deletions core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,14 @@ const console = consoleFactory();
/**
* Starting txAdmin (have fun :p)
*/
const logDie = (x: string) => {
console.error(x);
process.exit(1);
};
const serverProfile = GetConvar('serverProfile', 'default').replace(/[^a-z0-9._-]/gi, '').trim();
if (serverProfile.endsWith('.base')) {
logDie(`Looks like the folder named '${serverProfile}' is actually a deployed base instead of a profile.`);
console.error(`Looks like the folder named '${serverProfile}' is actually a deployed base instead of a profile.`);
process.exit(200);
}
if (!serverProfile.length) {
logDie('Invalid server profile name. Are you using Google Translator on the instructions page? Make sure there are no additional spaces in your command.');
console.error('Invalid server profile name. Are you using Google Translator on the instructions page? Make sure there are no additional spaces in your command.');
process.exit(201);
}

setTTYTitle(serverProfile);
Expand Down
6 changes: 3 additions & 3 deletions core/txAdmin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default class TxAdmin {
setupProfile(txEnv.osType, txEnv.fxServerPath, txEnv.fxServerVersion, serverProfile, profilePath);
} catch (error) {
console.error(`Failed to create profile '${serverProfile}' with error: ${(error as Error).message}`);
process.exit();
process.exit(300);
}
}
this.info = {
Expand All @@ -144,7 +144,7 @@ export default class TxAdmin {
} catch (error) {
console.error(`Error starting ConfigVault:`);
console.dir(error);
process.exit(1);
process.exit(301);
}

//Start all modules
Expand Down Expand Up @@ -205,7 +205,7 @@ export default class TxAdmin {
} catch (error) {
console.error(`Error starting main components:`);
console.dir(error);
process.exit(1);
process.exit(302);
}

//Once they all finish loading, the function below will print the banner
Expand Down
2 changes: 1 addition & 1 deletion entrypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ try {
if (!IsDuplicityVersion()) throw new Error();
} catch (error) {
console.log('txAdmin must be run inside FXServer in monitor mode!');
process.exit();
process.exit(999);
}

//Checking monitor mode and starting
Expand Down

0 comments on commit 1fea72e

Please sign in to comment.