Skip to content

Commit

Permalink
Redirect stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
stonegray committed Oct 14, 2023
1 parent 80ce1eb commit 02d1f88
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/backendSpeedtest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function cmd(command, args, opts) {
let buf = '';

p.stdout.on("data", (x) => buf += x);
p.stderr.on("data", (x) => buf += x);
p.stderr.on("data", (x) => console.error("speedtest-cli: ", x.toString()));

// We can ignore exit codes, as errors are printed.
p.on("exit", (code) => {
Expand Down Expand Up @@ -78,6 +78,10 @@ export async function speedtest(server, exclude, useSingleMode) {
// Call external speedtest library:
const r = await cmd('speedtest-cli', args, opts);

if (process.env.SPEEDTEST_DEBUG == "true"){
console.log("DEBUG::", r);
}

// Handle syntax errors nicely:
if (/^ERROR: .*/.test(r.stdout)) {
const message = (r.stdout).substring(7).replace("\n", '');
Expand Down Expand Up @@ -116,7 +120,7 @@ export async function speedtest(server, exclude, useSingleMode) {
};
}

const result = JSON.parse(r.stdout);
const result = JSON.parse(r.stdout);

// Temporary hack until I decide where to put this logic:
result.download = ~~(result.download / 1e4) / 1e2;
Expand Down

0 comments on commit 02d1f88

Please sign in to comment.