Skip to content

Fix stdout and errors in image/trust#636

Merged
dnephin merged 1 commit into
docker:masterfrom
dnephin:fix-trust-output-stream
Oct 27, 2017
Merged

Fix stdout and errors in image/trust#636
dnephin merged 1 commit into
docker:masterfrom
dnephin:fix-trust-output-stream

Conversation

@dnephin
Copy link
Copy Markdown
Contributor

@dnephin dnephin commented Oct 23, 2017

Fixes #631

Move some output to stderr.
Moved some error output into the error message instead of as a separate print.
Changed the behaviour in some cases where the conenction to notary failed to error instead of exit without an error.


if target == nil {
fmt.Fprintln(streams.Out(), "No targets found, please provide a specific tag in order to sign it")
return nil
Copy link
Copy Markdown
Contributor Author

@dnephin dnephin Oct 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this is now an error, so the cli will exit with non-zero. Since the push was not actually completed it seems like this should be an error.

@codecov-io
Copy link
Copy Markdown

codecov-io commented Oct 23, 2017

Codecov Report

Merging #636 into master will increase coverage by 0.01%.
The diff coverage is 0%.

@@            Coverage Diff             @@
##           master     #636      +/-   ##
==========================================
+ Coverage    49.4%   49.41%   +0.01%     
==========================================
  Files         208      208              
  Lines       17190    17186       -4     
==========================================
+ Hits         8492     8493       +1     
+ Misses       8265     8260       -5     
  Partials      433      433

@dnephin dnephin force-pushed the fix-trust-output-stream branch from 78c5719 to 8f86a25 Compare October 23, 2017 17:54
Signed-off-by: Daniel Nephin <dnephin@docker.com>
trustedFamiliarRef := reference.FamiliarString(trustedRef)

fmt.Fprintf(cli.Out(), "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
fmt.Fprintf(cli.Err(), "Tagging %s as %s\n", trustedFamiliarRef, familiarRef)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note sure whether this should go to stderr. This is the success message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the fix for the issue raised in #631.

The convention we should follow for stdout vs stderr error is:

  • stdout is for "normal program output"
  • stderr is for everything else (logging, warnings, etc)

This function is called from 3 commands. For both image build and container create this is definitely not normal program output, it's logging, so stderr is definitely correct.

For the last (image pull) it is a little less clear, but I think it could still easily be considered logging, since the desired action was "pull", not "tag".

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that depends on whether one expects command "X" to be different to command "X with trust." In my mind, we should send some minimal amount of info to stdout such that if I pipe stderr to /dev/null I can still determine the operation behaved as desired.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not how posix programs are supported to work. If we send anything to stdout we break anyone trying to use docker build and docker run in a script, when used with trust. The only output to stdout should be normal program output, which is the output from the command being run by docker run.

There is already a mechanism that allows you to determine if the operation behaved correctly or not, the exit status code. This PR also fixes some problems where the exit status was not being used correctly.

Copy link
Copy Markdown
Contributor

@ijc ijc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW LGTM

Copy link
Copy Markdown
Collaborator

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🐮

Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants