Skip to content

MISC: Explicitly convert absolute-reserve arg of host-manager.js to number - #485

Merged
alainbryden merged 1 commit into
alainbryden:mainfrom
catloversg:pull-request/misc/Explicitly-convert-absolute-reserve-arg-of-host-manager.js-to-number
Feb 22, 2026
Merged

alainbryden merged 1 commit into
alainbryden:mainfrom
catloversg:pull-request/misc/Explicitly-convert-absolute-reserve-arg-of-host-manager.js-to-number

Conversation

@catloversg

Copy link
Copy Markdown
Contributor

While testing #482, I occasionally see the warning from formatNumberShort (formatNumberShort called with "num" set to a non-numeric ). This happens when daemon.js runs host-manager.js. The value passed to --absolute-reserve is a number, but after reading it with ns.flags (via getConfiguration), it becomes a string. ns.flags has a special behavior when the schema does not define a default value for an arg. For example:

/** @param {NS} ns */
export async function main(ns) {
  const schema = [
    ['foo', 1000],
    ['bar', null]
  ];
  console.log(ns.flags(schema));
}

If you run run test.js --foo 1 --bar 2, ns.flags(schema) is:

{_: Array(0), foo: 1, bar: '2'}

bar is "2" (a string), not 2 (a number).

It's even worse if you try to pass a boolean: run test.js --foo 1 --bar false. ns.flags(schema) is:

{_: Array(0), foo: 1, bar: 'false'}

bar is a string instead of a boolean. This will mess up any logical operations involving bar. For example, !!ns.flags(schema).bar is true.

You may need to check other files to see if this is a problem in those files.

@alainbryden

Copy link
Copy Markdown
Owner

Dang good catch. Yeah I think I use null defaults in a bunch of scripts, I'm going to have to do a sweep and either convert as you did here, or use a special case value as a default (like -1).

@alainbryden
alainbryden merged commit e3f9ee5 into alainbryden:main Feb 22, 2026
1 check passed
@catloversg
catloversg deleted the pull-request/misc/Explicitly-convert-absolute-reserve-arg-of-host-manager.js-to-number branch February 22, 2026 17:37
@alainbryden alainbryden added the bug Something isn't working label Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants