DrPaulBrewer / single-market-robot-simulator

Runs numerical experiments for a single market populated by robot traders
Other
7 stars 5 forks source link

6.9.0 throws TypeError in stand-alone mode while writing out period number #35

Closed DrPaulBrewer closed 3 years ago

DrPaulBrewer commented 3 years ago

Error messages looked like this in Docker container

/work $ node ~/single-market-robot-simulator/build/index.js sim.json
internal/fs/utils.js:657
    throw new ERR_INVALID_ARG_TYPE(
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "data" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received type number (1)
    at Object.writeFileSync (fs.js:1380:5)
    at mainPeriod (/home/node/single-market-robot-simulator/build/index.js:763:8)
    at Simulation.run (/home/node/single-market-robot-simulator/build/index.js:720:9)
    at main (/home/node/single-market-robot-simulator/build/index.js:767:26)
    at Object.<anonymous> (/home/node/single-market-robot-simulator/build/index.js:775:43)
    at Module._compile (internal/modules/cjs/loader.js:1200:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) {
  code: 'ERR_INVALID_ARG_TYPE'
}
DrPaulBrewer commented 3 years ago

This happens in the fs.writeFileSync() call when writing out the period number.

Apparently, the type checking for this call has become more strict. It used to convert the number to a string but now it throws a TypeError instead.

It doesn't affect node version 12.18.1.

It does affect node version 14.4.0

DrPaulBrewer commented 3 years ago

fs.writeFileSync is only called in one place in single-market-robot-simulator, here:

https://github.com/DrPaulBrewer/single-market-robot-simulator/blob/76a6e066a32a21caa36ca173f6b7edf8cef22cf2/src/index.js#L751-L753

DrPaulBrewer commented 3 years ago

converting to string manually should fix

DrPaulBrewer commented 3 years ago

done