mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2026-04-21 00:32:51 +02:00
BUGFIX: Fix inconsistencies of error handling in promise-based API (#1377)
This commit is contained in:
@@ -261,13 +261,7 @@ export const ns: InternalAPI<NSFull> = {
|
||||
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return Promise.resolve(0);
|
||||
}
|
||||
|
||||
const host = GetServer(ctx.workerScript.hostname);
|
||||
if (host === null) {
|
||||
throw new Error("Workerscript host is null");
|
||||
throw helpers.errorMessage(ctx, "Cannot be executed on this server.");
|
||||
}
|
||||
|
||||
// No root access or skill level too low
|
||||
@@ -286,6 +280,10 @@ export const ns: InternalAPI<NSFull> = {
|
||||
)} (t=${formatThreads(threads)}).`,
|
||||
);
|
||||
return helpers.netscriptDelay(ctx, growTime * 1000).then(function () {
|
||||
const host = GetServer(ctx.workerScript.hostname);
|
||||
if (host === null) {
|
||||
throw helpers.errorMessage(ctx, `Cannot find host of WorkerScript. Hostname: ${ctx.workerScript.hostname}.`);
|
||||
}
|
||||
const moneyBefore = server.moneyAvailable <= 0 ? 1 : server.moneyAvailable;
|
||||
processSingleServerGrowth(server, threads, host.cpuCores);
|
||||
const moneyAfter = server.moneyAvailable;
|
||||
@@ -360,8 +358,7 @@ export const ns: InternalAPI<NSFull> = {
|
||||
|
||||
const server = helpers.getServer(ctx, hostname);
|
||||
if (!(server instanceof Server)) {
|
||||
helpers.log(ctx, () => "Cannot be executed on this server.");
|
||||
return Promise.resolve(0);
|
||||
throw helpers.errorMessage(ctx, "Cannot be executed on this server.");
|
||||
}
|
||||
|
||||
// No root access or skill level too low
|
||||
@@ -382,8 +379,7 @@ export const ns: InternalAPI<NSFull> = {
|
||||
return helpers.netscriptDelay(ctx, weakenTime * 1000).then(function () {
|
||||
const host = GetServer(ctx.workerScript.hostname);
|
||||
if (host === null) {
|
||||
helpers.log(ctx, () => "Server is null, did it die?");
|
||||
return Promise.resolve(0);
|
||||
throw helpers.errorMessage(ctx, `Cannot find host of WorkerScript. Hostname: ${ctx.workerScript.hostname}.`);
|
||||
}
|
||||
const weakenAmt = getWeakenEffect(threads, host.cpuCores);
|
||||
server.weaken(weakenAmt);
|
||||
|
||||
Reference in New Issue
Block a user