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

Last Go Printf output missing if no newline #3982

Closed
clstokes opened this issue Feb 26, 2020 · 1 comment
Closed

Last Go Printf output missing if no newline #3982

clstokes opened this issue Feb 26, 2020 · 1 comment
Assignees
Labels
kind/bug Some behavior is incorrect or out of spec language/go resolution/fixed This issue was fixed

Comments

@clstokes
Copy link
Contributor

Problem

It seems that if the last fmt.Printf("") in my Go pulumi application does not end with a newline, it's output never gets printed/flushed to the user's terminal.

Suggestion

Print all console output.

Steps to reproduce

  1. preview the code below

Code to reproduce

package main

import (
	"fmt"

	"github.com/pulumi/pulumi-aws/sdk/go/aws/s3"
	"github.com/pulumi/pulumi/sdk/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		// Create an AWS resource (S3 Bucket)
		bucket, err := s3.NewBucket(ctx, "my-bucket", nil)
		if err != nil {
			return err
		}

		fmt.Printf("1 - with newline\n")
		fmt.Printf("2 - no newline")
		fmt.Printf("3 - with newline\n")
		fmt.Printf("4 - no newline")
		// fmt.Printf("\n") // <-- uncomment this to see the "4 - no newline" get printed

		// Export the name of the bucket
		ctx.Export("bucketName", bucket.ID())
		return nil
	})
}

Output from the code above

aws-go-printf % pulumi preview
Previewing update (dev):
     Type                 Name               Plan       Info
 +   pulumi:pulumi:Stack  aws-go-printf-dev  create     2 messages
 +   └─ aws:s3:Bucket     my-bucket          create     
 
Diagnostics:
  pulumi:pulumi:Stack (aws-go-printf-dev):
    1 - with newline
    2 - no newline3 - with newline
 

Permalink: https://app.pulumi.com/clstokes/aws-go-printf/dev/previews/84e69cb9-ebe4-4ec0-becf-0ac1b91004f3
@lukehoban lukehoban added the kind/bug Some behavior is incorrect or out of spec label Feb 26, 2020
@rjshrjndrn
Copy link

I was checking why my debug messages never shows. Thanks for bringing this up. 👍

joeduffy added a commit that referenced this issue Dec 31, 2021
If the last line printed to stdout or stderr was missing a
terminating newline, it would go entirely missing (in all languages).
The reason for this is a bug in the engine's handling of plugin
outputs: Go's Reader.ReadString('\n') returns a string containing what
was read and/or an error; if the string terminated in a '\n', the
error is nil, and the entire line is returned; if the stream ends,
however, a non-nil error is returned *and* what was read is returned,
even though it wasn't terminated in a newline. The fix is simple:
instead of ignoring that text, we use it, and *then* exit the read-loop.

Also added some test cases since this is subtle and easy to regress.
@pulumi-bot pulumi-bot added the resolution/fixed This issue was fixed label Jan 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Some behavior is incorrect or out of spec language/go resolution/fixed This issue was fixed
Projects
None yet
Development

No branches or pull requests

5 participants