8000 SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 1 of the JSON data · Issue #5 · mrv777/ckstats · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 1 of the JSON data #5
Open
@kic0

Description

@kic0

Hi,

I installed ckpool-solo and then this repo, everything seems fine with instalation of both repos although the file provided under ~/ckpool-solo/src/logs/pool/pool.status seems to be broken for a valid json file and this breaks the instalation of ckstats when running pnpm seed:

$ pnpm seed

> ckstats@0.2.3 seed /home/user/ckstats
> node scripts/seed.js

Fetching pool stats...
Fetching pool stats...
Error seeding database: SyntaxError: Unexpected token < in JSON at position 0
    at JSON.parse (<anonymous>)
    at /home/user/ckstats/scripts/seed.js:11:73
    at Array.reduce (<anonymous>)
    at fetchPoolStats (/home/user/ckstats/scripts/seed.js:11:32)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async seed (/home/user/ckstats/scripts/seed.js:18:19)

The API seems correctly setup from this request:

https://pool.address/api/users/btcaddress

Shows a correctly parsed json:

{
 "hashrate1m": "3.7T",
 "hashrate5m": "3.88T",
 "hashrate1hr": "4.01T",
 "hashrate1d": "3.97T",
 "hashrate7d": "2.67T",
 "lastshare": 1732006226,
 "workers": 1,
 "shares": 632592715,
 "bestshare": 2921653605.24227,
 "bestever": 2921653605,
 "authorised": 1731297741,
 "worker": [
  {
   "workername": "btcaddress.worker1",
   "hashrate1m": "3.7T",
   "hashrate5m": "3.88T",
   "hashrate1hr": "4.01T",
   "hashrate1d": "3.97T",
   "hashrate7d": "2.67T",
   "lastshare": 1732006226,
   "shares": 632592715,
   "bestshare": 2921653605.24227,
   "bestever": 2921653605
  }
 ]
}

While https://pool.address/api/pool/pool.status shows:

{"runtime": 9120, "lastupdate": 1732006226, "Users": 1, "Workers": 1, "Idle": 0, "Disconnected": 0}
{"hashrate1m": "3.49T", "hashrate5m": "3.85T", "hashrate15m": "4.04T", "hashrate1hr": "4.01T", "hashrate6hr": "3.98T", "hashrate1d": "3.96T", "hashrate7d": "2.67T"}
{"diff": 0.0, "accepted": 632592715, "rejected": 545404, "bestshare": 2921653605, "SPS1m": 0.274, "SPS5m": 0.302, "SPS15m": 0.317, "SPS1h": 0.309}

Error:

SyntaxError: JSON.parse: unexpected non-whitespace character after JSON data at line 2 column 1 of the JSON data

Same reply from an online Json parser:

Error: Parse error on line 1:
... "Disconnected": 0}{"hashrate1m": "3.49
----------------------^
Expecting 'EOF', '}', ',', ']', got '{'

Either the file under ~/ckpool-solo/src/logs/pool/pool.status needs to be generated in another way to make it a valid Json file or it needs to be parsed differently under ~/ckstats/scripts/seed.js in order to be correctly parsed.

After fiddling around with the Json output a bit it seems it should be:

[{"runtime": 15300, "lastupdate": 1732012407, "Users": 1, "Workers": 1, "Idle": 0, "Disconnected": 0},
{"hashrate1m": "5.12T", "hashrate5m": "4.42T", "hashrate15m": "4.07T", "hashrate1hr": "3.91T", "hashrate6hr": "3.96T", "hashrate1d": "3.95T", "hashrate7d": "2.68T"},
{"diff": 0.0, "accepted": 638159590, "rejected": 548373, "bestshare": 2921653605, "SPS1m": 0.402, "SPS5m": 0.347, "SPS15m": 0.319, "SPS1h": 0.306}]

This parses to:

[
  {
    "runtime": 9120,
    "lastupdate": 1732006226,
    "Users": 1,
    "Workers": 1,
    "Idle": 0,
    "Disconnected": 0
  },
  {
    "hashrate1m": "3.49T",
    "hashrate5m": "3.85T",
    "hashrate15m": "4.04T",
    "hashrate1hr": "4.01T",
    "hashrate6hr": "3.98T",
    "hashrate1d": "3.96T",
    "hashrate7d": "2.67T"
  },
  {
    "diff": 0,
    "accepted": 632592715,
    "rejected": 545404,
    "bestshare": 2921653605,
    "SPS1m": 0.274,
    "SPS5m": 0.302,
    "SPS15m": 0.317,
    "SPS1h": 0.309
  }
]

Given this the issue seems to be in the way the log file "json" is being created under ~/ckpool-solo/src/logs/pool/pool.status and maybe this issue belongs on the other repo?

Any help would be great, thanks in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0