Fix #3982, missing output which lacks newlines (#8671)
* Fix #3982, missing output which lacks newlines
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.
* Add a changelog entry
2022-01-03 22:39:10 +00:00
|
|
|
// Copyright 2021, Pulumi Corporation. All rights reserved.
|
2022-09-14 03:02:19 +00:00
|
|
|
//go:build !all
|
|
|
|
// +build !all
|
Fix #3982, missing output which lacks newlines (#8671)
* Fix #3982, missing output which lacks newlines
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.
* Add a changelog entry
2022-01-03 22:39:10 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
pulumi.Run(func(ctx *pulumi.Context) error {
|
|
|
|
for i := 0; i < 10; i++ {
|
|
|
|
fmt.Printf("Line %d\n", i)
|
|
|
|
fmt.Fprintf(os.Stderr, "Errln %d\n", i+10)
|
|
|
|
}
|
|
|
|
fmt.Printf("Line 10")
|
|
|
|
fmt.Fprintf(os.Stderr, "Errln 20")
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
}
|