Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preview message is written to StdErr which causes scripts using the preview message fail in pipelines #166

Closed
atbagga opened this issue Oct 4, 2019 · 9 comments
Assignees

Comments

@atbagga
Copy link
Contributor

atbagga commented Oct 4, 2019

image

Reported on Azure-Devops extension - Azure/azure-devops-cli-extension#811

@jiasli
Copy link
Member

jiasli commented Oct 8, 2019

Writing to std.err is a very common behavior across many CLI tools.

The CI should not rely on the contents in std.err. The CI should check the exit code instead: https://github.com/Azure/azure-cli#exit-codes

@sebastianrogers
Copy link

sebastianrogers commented Oct 10, 2019

Whether it is common does not make it correct.

A warning is not an error it is information.

The decision on how the pipeline should handle warnings, as distinct from errors, has now been removed.

Azure pipelines, Microsoft's public CI tool treats any output on STDERR as an Error.

Can you amend the tool to write Warnings, information and debug out to an appropriate stream so that when a developer raises a warning via your tool it is identifiable as a warning and not an error.

To assume and imply that there is no distinction between a warning and an error is not a valid assumption and not a common use of the terms.

Cheers

@pmatthews05
Copy link

I have had the same issue with warnings in pipelines. Latest one I've had a problem with was with the Storage account, that the name is going to change from StorageV2 to Storage

az : WARNING: The default kind for created storage account will change to 'StorageV2' from 'Storage' in future

It doesn't matter if you set the name to Storage or StorageV2, this warning comes up every time and breaks the pipeline.

I have reported it here:
Developer Community Visual Studio

I've been told that they can replicate the issue and the ticket has been moved to the product team.

@atbagga
Copy link
Contributor Author

atbagga commented Oct 14, 2019

@jiasli How about having a suppress warning (--suppress-warning) flag in the command? This can be a global parameter and framework should handle not putting warnings in case the flag is specified.

This way users will know when they are taking dependency on a preview command and can explicitly suppress warnings in the scripts if they do not want the noise in the output.

@sebastianrogers @pmatthews05 What do you guys think? Will this be a reasonable option for fixing the issue.

@sebastianrogers
Copy link

I don't like this option as it is negating a negation. It would be best if only errors were output to the error output.

We are looking at a wrapper function in PowerShell to handle it at the moment, typing this from memory so may have the odd typo.

function Invoke-AzCommand() {
param(

The command to execute

[string]
$Command
)

$LastErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'Continue'
Invoke-Expression -Command:$Command
$ExitCode = $LastExitCode
$ErrorActionPreference = $LastErrorActionPreference
switch ($ExitCode) {
0 {}
default {
Write-Error -Message:$ExitCode
}
}
}

@jiasli
Copy link
Member

jiasli commented Oct 15, 2019

@sebastianrogers
Copy link

Been doing some reading and https://www.gnu.org/software/libc/manual/html_node/Standard-Streams.html seems to be the definitive link.

Variable: FILE * stderr
The standard error stream, which is used for error messages and diagnostics issued by the program.

So it looks like it depends on if you catagorise a warning as a diagnostic, which grammatically I would not, but it does imply that similarly if a verbose or debug output was requested then the logging should definitely put it out on STD_ERR!

Based on this it does appear that the script above for PowerShell or for Bash something like exec 2>&1 before the az command will be required.

@jiasli
Copy link
Member

jiasli commented Oct 16, 2019

2>&1 will pollute stdout where CLI writes result to. You may consider using 2>nul or disabling Fail on Standard Error in the pipeline. sys.stderr is the default and valid place for Python's logging mechanism: https://docs.python.org/3.7/howto/logging.html

@jiasli
Copy link
Member

jiasli commented Mar 24, 2020

We have added option --only-show-errors in #181 and also Azure/azure-cli#12604 to disable warnings that are written to stderr. Knack 0.7.0rc1 has already been released with this feature. Azure CLI will include it in S167 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants