Do not use a scanner to read the logs
Using a scanner can cause issues when reading long lines. Also make sure we return the error correctly while planning.
This commit is contained in:
parent
cc38debace
commit
7cf744241a
|
@ -228,37 +228,51 @@ func (b *Remote) parseVariableValues(op *backend.Operation) (terraform.InputValu
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *Remote) costEstimation(stopCtx, cancelCtx context.Context, op *backend.Operation, r *tfe.Run) error {
|
func (b *Remote) costEstimation(stopCtx, cancelCtx context.Context, op *backend.Operation, r *tfe.Run) error {
|
||||||
|
if r.CostEstimation != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if b.CLI != nil {
|
if b.CLI != nil {
|
||||||
b.CLI.Output("\n------------------------------------------------------------------------\n")
|
b.CLI.Output("\n------------------------------------------------------------------------\n")
|
||||||
}
|
}
|
||||||
var ce = r.CostEstimation
|
|
||||||
|
|
||||||
logs, err := b.client.CostEstimations.Logs(stopCtx, ce.ID)
|
logs, err := b.client.CostEstimations.Logs(stopCtx, r.CostEstimation.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return generalError("Failed to retrieve cost estimation logs", err)
|
return generalError("Failed to retrieve cost estimation logs", err)
|
||||||
}
|
}
|
||||||
scanner := bufio.NewScanner(logs)
|
reader := bufio.NewReaderSize(logs, 64*1024)
|
||||||
|
|
||||||
// Retrieve the cost estimation to get its current status.
|
// Retrieve the cost estimation to get its current status.
|
||||||
ce, err = b.client.CostEstimations.Read(stopCtx, ce.ID)
|
ce, err := b.client.CostEstimations.Read(stopCtx, r.CostEstimation.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return generalError("Failed to retrieve cost estimation", err)
|
return generalError("Failed to retrieve cost estimation", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var msgPrefix = "Cost estimation"
|
msgPrefix := "Cost estimation"
|
||||||
|
|
||||||
if b.CLI != nil {
|
if b.CLI != nil {
|
||||||
b.CLI.Output(b.Colorize().Color(msgPrefix + ":\n"))
|
b.CLI.Output(b.Colorize().Color(msgPrefix + ":\n"))
|
||||||
}
|
}
|
||||||
|
|
||||||
for scanner.Scan() {
|
|
||||||
if b.CLI != nil {
|
if b.CLI != nil {
|
||||||
b.CLI.Output(b.Colorize().Color(scanner.Text()))
|
for next := true; next; {
|
||||||
}
|
var l, line []byte
|
||||||
}
|
|
||||||
if err := scanner.Err(); err != nil {
|
for isPrefix := true; isPrefix; {
|
||||||
|
l, isPrefix, err = reader.ReadLine()
|
||||||
|
if err != nil {
|
||||||
|
if err != io.EOF {
|
||||||
return generalError("Failed to read logs", err)
|
return generalError("Failed to read logs", err)
|
||||||
}
|
}
|
||||||
|
next = false
|
||||||
|
}
|
||||||
|
line = append(line, l...)
|
||||||
|
}
|
||||||
|
|
||||||
|
if next || len(line) > 0 {
|
||||||
|
b.CLI.Output(b.Colorize().Color(string(line)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch ce.Status {
|
switch ce.Status {
|
||||||
case tfe.CostEstimationFinished:
|
case tfe.CostEstimationFinished:
|
||||||
|
|
|
@ -294,7 +294,7 @@ func (b *Remote) plan(stopCtx, cancelCtx context.Context, op *backend.Operation,
|
||||||
if r.CostEstimation != nil {
|
if r.CostEstimation != nil {
|
||||||
err = b.costEstimation(stopCtx, cancelCtx, op, r)
|
err = b.costEstimation(stopCtx, cancelCtx, op, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
generalError("Cost Estimation error", err)
|
return r, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue