unity-gaming-services-cli icon indicating copy to clipboard operation
unity-gaming-services-cli copied to clipboard

Ugs login, env and config print on stderr instead of stdout

Open VGMFR opened this issue 1 year ago • 4 comments

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.

VGMFR avatar Aug 21 '24 13:08 VGMFR

Hi @VGMFR,

We've created a ticket on our side to investigate

Thank you for reporting

yoan-bernatchez avatar Aug 21 '24 14:08 yoan-bernatchez

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.

VGMFR avatar Aug 21 '24 19:08 VGMFR

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.

VGMFR avatar Aug 22 '24 08:08 VGMFR

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.

GabrielBelmonteUnity avatar Aug 29 '24 15:08 GabrielBelmonteUnity