Ugs login, env and config print on stderr instead of stdout
I migrated from ucd cli to ugs cli, and our C# command line management tools were not working anymore. I was quite surprised, but after some investigation I noticed that some commands print their result on stderr instead of stdout.
To reproduce, create a simple script named cdnUploadToDevBucket.sh:
ugs login --service-key-id #SERVICE_KEY --secret-key-stdin < "#SECRET_KEY_PATH"
ugs env use development
ugs config set project-id #PROJECT_ID
ugs config set bucket-name #BUCKET
Then execute it like this:
./cdnUploadToDevBucket.sh 2>stderr.log 1>stdout.log
Check the logs: stdout.log is empty when stderr.log contains the following information:
[Information]:
Service Account key saved in local configuration.
[Information]:
Environment has been changed to 'development'
[Information]:
The config 'project-id' has been set to 'xxx'.
[Information]:
The config 'bucket-name' has been set to 'xxx'.
This is very annoying as it breaks workflows and will make us code tricky things to bypass it. It would be nice if it could be fixed asap.
Please note that some of the ugs commands work correctly, for example ugs ccd entries sync or ccd entries delete.
Edit: ccd entries delete is incorrect as well, my bad.
I'm on MacOS.
Thank you.
Hi @VGMFR,
We've created a ticket on our side to investigate
Thank you for reporting
Hi @VGMFR,
We've created a ticket on our side to investigate
Thank you for reporting
Perfect thank you. Don't hesitate to keep us updated if you can.
If any other people run into this issue as well: making the requests silent by adding the --quiet argument is a workaround that is not ideal (nothing is printed anymore) but that works, waiting for a fix.
I edited my original message because actually ccd entries delete is incorrect as well. There are probably others that I did not check that are also incorrect.
Hi @VGMFR !
This is currently expected behavior: https://services.docs.unity.com/guides/ugs-cli/latest/general/samples/stdout-stderr-piping/
All logs are piped to stderr, which keeps stdout clean with the json output of all services.
I understand this can be annoying, the idea is that we clearly separate logs and command result. And you can json parse the stdout for the exact object, which creates symmetry in many services. (e.g. ugs serv get some_id > my.json, ugs serv create some_id my.json -e other_env).
If you want to check command success failure, use the exit code instead: https://github.com/Unity-Technologies/unity-gaming-services-cli/blob/main/Unity.Services.Cli/Unity.Services.Cli.Common/Exceptions/ExitCode.cs .
We will revisit this decision in the team, but changing it would be a major breaking change on expected behavior, so it would probably not happen until 2.x.
Would the above solution work for you? (exit code).
EDIT: It's also possible some CCD commands are not respecting the above guidance, which we can definitely get fixed, std-err for log messages only, and stdout for result object.