Originally posted by dkebler May 7, 2023
I am unable to track down why this is happening but with a got post call I keep getting some unwanted response to the console when I run a particular command on a remote device. It's not part of the result of the resolved promise so I'm scratching my head?
this calls got post with a remote command. In this case UrlFetch
which is specific to a tasmota device. This command will have the tasmota device pull a file from the fileurl
which is where I have a simple (nodejs based) static file server running.
async function fetch(host, server, file) {
const temp = path.parse(file);
if (temp.ext === '.be') {
temp.ext = '.bec';
temp.base = null;
await remove(host, path.format(temp));
}
const fileurl = `${server}/${file}`;
const res = await cmnd(host, 'UrlFetch ' + fileurl);
if ((res || {}).UrlFetch === 'Done') {
console.log(res);
return 'success';
}
return null;
}
post command
async function cmnd(host, cmnd) {
const url = `http://${host}/cm`;
return got.post(url, {
form: {cmnd},
timeout: {
request: 30000,
connect: 30000,
},
}).json()
.catch(err => {
console.log('---------ERROR----------');
console.log(err);
});
}
when successful the output to the console is
Stats {
dev: 8388828,
mode: 33188,
nlink: 1,
uid: 1000,
gid: 1000,
rdev: 0,
blksize: 4096,
ino: 242034,
size: 0,
blocks: 0,
atimeMs: 1683484733037.572,
mtimeMs: 1683484733037.572,
ctimeMs: 1683484733037.572,
birthtimeMs: 0,
atime: 2023-05-07T18:38:53.038Z,
mtime: 2023-05-07T18:38:53.038Z,
ctime: 2023-05-07T18:38:53.038Z,
birthtime: 1970-01-01T00:00:00.000Z
}
true
{ UrlFetch: 'Done' }
but should only be
{ UrlFetch: 'Done' }
which is what is in res
so how is it possible that this other "stuff" appears in the console. I didn't log it there. Does got post have some "verbose/debug" setting (by default) that sends other parts of the post response to the console? this appears to be info about the file that was fetched. If I send other commands like UfsDelete
that extra "stuff" does not appear.
SO
if I noop the console.log function before calling cmnd
(that returns got.post promise) and then restore it afterwards I can suppress that unexpected console output. That kinda indicates to me that it's an (unsuppressible) console.log statement somewhere in got.post
and/or mabye .json()
. So I'm assuming this is a bug and making this issue. Obviously I have a workaround so it's not critical.
const t = console.log;
console.log = function () {};
const res = await cmnd(host, 'UrlFetch ' + fileurl);
if ((res || {}).UrlFetch === 'Done') {
console.log = t;
console.log(res);
return 'success';
}
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too