WhiteflagProtocol / whiteflag-api

Reference implementation of the Whiteflag protocol in Node.js that acts as an API to connect applications with the underlying blockchains
https://api.whiteflagprotocol.org
Other
4 stars 5 forks source link

Saving state to file results in fatal error #19

Closed ts5746 closed 4 years ago

ts5746 commented 4 years ago

Description

State cannot be written to file when set to do so in the configuration. The process exists with a FATAL error due to an uncaught exception, probably due to a coding error.

Environment / Versions

Software

OS: Ubuntu 16.04.6 LTS Node.js: v10.20.1 whiteflag-api: v1.0.0-beta

Blockchain

N/A

Symptoms and Problem details

Steps to reproduce

  1. Changed the whiteflag.toml configuration file to save the state to the specified file:
    [state]
    saveToFile = true
    file = "/var/lib/whiteflag/whiteflag.state"
  2. Restarted the whiteflag-api service.

Expected result

The state should have been written to the file /var/lib/whiteflag/whiteflag.state, and the process should have continued.

Actual result

The process exists with a fatal error and exit code 2.

npm[114613]: [FATAL] api: UNCAUGHT EXCEPTION: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be one of type string, Buffer, or URL. Received type boolean
npm[114613]:     at Object.open (fs.js:408:3)
npm[114613]:     at Object.writeFile (fs.js:1172:6)
npm[114613]:     at saveState (/srv/src/whiteflag-api/lib/protocol/state.js:237:12)

Also, the exit code 2 is (correctly) interpreted by the system as INVALIDARGUMENT i.a.w. https://freedesktop.org/software/systemd/man/systemd.exec.html#id-1.20.8, but that is not in line with the root cause of the error.

ts5746 commented 4 years ago

Exception due to wrong variable assignment. Bugfix in commit 7525d80. Also corrected exit code.