apify-cli icon indicating copy to clipboard operation
apify-cli copied to clipboard

Output from warnings doesn't go to `stderr` and breaks working `*nix` integrations even on non otherwise non-breaking releases

Open netmilk opened this issue 1 year ago • 4 comments

Example:

$ apify actor:get-input 2>/dev/null

Warning: You are using an old version of Apify CLI. We strongly recommend you always use the latest available version.
       ↪ Run ' brew update && brew upgrade apify-cli ' to update! 👍

{ "usernames":
  ["netmilk", "n1k"]
}

Example of a broken integration then:

$ apify actor:get-input | jq
jq: parse error: Invalid numeric literal at line 2, column 8

Expected behavior:

$ apify actor:get-input 2>stderr.txt
{ "usernames":
  ["netmilk", "n1k"]
}
$ cat stderr.txt

Warning: You are using an old version of Apify CLI. We strongly recommend you always use the latest available version.
       ↪ Run ' brew update && brew upgrade apify-cli ' to update! 👍


netmilk avatar Apr 30 '24 08:04 netmilk

As a quick remediation I propose to use console.warn() and console.error() instead of console.log() at least for warn and error in output.ts

$ cat warn-test.js
console.log("this is a standard output")
console.warn("this is a warning")
console.error("this is an error")
$ node warn-test.js 2>/dev/null
this is a standard output

netmilk avatar Apr 30 '24 08:04 netmilk

Feel free to PR the changes, because I agree and they look correct!

vladfrangu avatar Apr 30 '24 13:04 vladfrangu

Yeah, good point.

B4nan avatar Apr 30 '24 13:04 B4nan

The same goes for the info level:

$ cat storage/key_value_stores/default/INPUT.json
{
  "urls": [
    "http://google.com"
  ]
}
$ apify actor:get-input 2>/dev/null

Info: Making sure that Apify CLI is up to date...
Info: Apify CLI is up to date 👍

{
  "urls": [
    "http://google.com"
  ]
}
Info: Apify collects telemetry data about general usage of Apify CLI to help us improve the product. This feature is enabled by default, and you can disable it by setting the "APIFY_CLI_DISABLE_TELEMETRY" environment variable to "1". You can find more information about our telemetry in https://docs.apify.com/cli/docs/telemetry.
INPUT: http://google.com

That isn't a parseable JSON output.

netmilk avatar May 03 '24 07:05 netmilk