BUGFIX: Missing error handler when calling libarg (#1625)

This commit is contained in:
catloversg 2024-08-25 04:08:42 +07:00 committed by GitHub
parent 49629d1d28
commit ac0c9bd7e8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 8 deletions

@ -18,10 +18,16 @@ export function runScript(path: ScriptFilePath, commandArgs: (string | number |
if (!script) return Terminal.error(`Script ${path} does not exist on this server.`);
const runArgs = { "--tail": Boolean, "-t": Number, "--ram-override": Number };
const flags = libarg(runArgs, {
permissive: true,
argv: commandArgs,
});
let flags;
try {
flags = libarg(runArgs, {
permissive: true,
argv: commandArgs,
});
} catch (error) {
Terminal.error(`Invalid arguments. ${String(error)}.`);
return;
}
const tailFlag = flags["--tail"] === true;
const numThreads = parseFloat(flags["-t"] ?? 1);
const ramOverride = flags["--ram-override"] != null ? roundToTwo(parseFloat(flags["--ram-override"])) : null;

@ -276,10 +276,21 @@ export async function getTabCompletionPossibilities(terminalText: string, baseDi
if (!loadedModule || !loadedModule.autocomplete) return; // Doesn't have an autocomplete function.
const runArgs = { "--tail": Boolean, "-t": Number, "--ram-override": Number };
const flags = libarg(runArgs, {
permissive: true,
argv: command.slice(2),
});
let flags = {
_: [],
};
try {
flags = libarg(runArgs, {
permissive: true,
argv: command.slice(2),
});
} catch (error) {
/**
* This error can only happen when the player specifies "-t" or "--ram-override", then presses [Tab] without
* giving a number. We don't need to show an error here.
*/
console.warn(error);
}
const flagFunc = Flags(flags._);
const autocompleteData: AutocompleteData = {
servers: GetAllServers()