Skip to content

Commit

Permalink
detect terminal is not a console.File to avoid a panic
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed May 15, 2023
1 parent dc01b98 commit 18a112e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ require (
github.com/bugsnag/bugsnag-go v1.5.0 // indirect
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cloudflare/cfssl v1.4.1 // indirect
github.com/cloudflare/cfssl v1.4.1
github.com/containerd/continuity v0.3.0 // indirect
github.com/containerd/ttrpc v1.1.1 // indirect
github.com/containerd/typeurl v1.0.2 // indirect
Expand Down
12 changes: 9 additions & 3 deletions pkg/progress/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"io"
"sync"

"github.com/cloudflare/cfssl/log"
"github.com/docker/compose/v2/pkg/api"

"github.com/containerd/console"
Expand Down Expand Up @@ -118,11 +119,16 @@ func NewWriter(ctx context.Context, out io.Writer, progressTitle string) (Writer
if !ok {
dryRun = false
}
if Mode == ModeAuto && isTerminal {
return newTTYWriter(out.(console.File), dryRun, progressTitle)
f, isConsole := out.(console.File) // see https://github.com/docker/compose/issues/10560
if Mode == ModeAuto && isTerminal && isConsole {
return newTTYWriter(f, dryRun, progressTitle)
}
if Mode == ModeTTY {
return newTTYWriter(out.(console.File), dryRun, progressTitle)
if !isConsole {
log.Warning("Terminal is not a POSIX console")
} else {
return newTTYWriter(f, dryRun, progressTitle)
}
}
return &plainWriter{
out: out,
Expand Down

0 comments on commit 18a112e

Please sign in to comment.