Skip to content

Commit fd46a83

Browse files
author
Christian Weichel
committed
[ws-daemon] Improve error when content init fails
1 parent 53c5662 commit fd46a83

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

components/content-service/pkg/git/git.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@ func (s *Status) ToAPI() *csapi.GitStatus {
132132
}
133133
}
134134

135-
// ErrGitOpFailed is returned by GitWithOutput if the operation fails
135+
// GitOpFailedError is returned by GitWithOutput if the operation fails
136136
// e.g. returns with a non-zero exit code.
137-
type ErrGitOpFailed struct {
137+
type GitOpFailedError struct {
138138
Subcommand string
139139
Args []string
140140
ExecErr error
141141
Output string
142142
}
143143

144-
func (e ErrGitOpFailed) Error() string {
144+
func (e GitOpFailedError) Error() string {
145145
return fmt.Sprintf("git %s %s failed (%v): %v", e.Subcommand, strings.Join(e.Args, " "), e.ExecErr, e.Output)
146146
}
147147

@@ -186,7 +186,7 @@ func (c *Client) GitWithOutput(ctx context.Context, subcommand string, args ...s
186186

187187
res, err := cmd.CombinedOutput()
188188
if err != nil {
189-
return nil, ErrGitOpFailed{
189+
return nil, GitOpFailedError{
190190
Args: args,
191191
ExecErr: err,
192192
Output: string(res),

components/content-service/pkg/initializer/prebuild.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (p *PrebuildInitializer) Run(ctx context.Context, mappings []archive.IDMapp
8787
if git.IsWorkingCopy(p.Git.Location) {
8888
out, err := p.Git.GitWithOutput(ctx, "stash", "push", "-u")
8989
if err != nil {
90-
var giterr git.ErrGitOpFailed
90+
var giterr git.GitOpFailedError
9191
if errors.As(err, &giterr) && strings.Contains(giterr.Output, "You do not have the initial commit yet") {
9292
// git stash push returns a non-zero exit code if the repository does not have a single commit.
9393
// In this case that's not an error though, hence we don't want to fail here.

components/ws-daemon/pkg/content/initializer.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ import (
1515
"os/exec"
1616
"path/filepath"
1717
"strings"
18+
"syscall"
1819

1920
"github.com/gitpod-io/gitpod/common-go/log"
2021
"github.com/gitpod-io/gitpod/common-go/tracing"
2122
csapi "github.com/gitpod-io/gitpod/content-service/api"
2223
"github.com/gitpod-io/gitpod/content-service/pkg/archive"
2324
wsinit "github.com/gitpod-io/gitpod/content-service/pkg/initializer"
2425
"github.com/gitpod-io/gitpod/content-service/pkg/storage"
26+
"github.com/sirupsen/logrus"
2527

2628
"github.com/golang/protobuf/proto"
2729
"github.com/opencontainers/runtime-spec/specs-go"
@@ -233,6 +235,13 @@ func RunInitializer(ctx context.Context, destination string, initializer *csapi.
233235
cmd.Stdin = os.Stdin
234236
err = cmd.Run()
235237
if err != nil {
238+
if exiterr, ok := err.(*exec.ExitError); ok {
239+
// The program has exited with an exit code != 0. If it's 42, it was deliberate.
240+
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok && status.ExitStatus() == 42 {
241+
return fmt.Errorf("content initializer failed")
242+
}
243+
}
244+
236245
return err
237246
}
238247

@@ -251,6 +260,7 @@ func RunInitializerChild() (err error) {
251260
if err != nil {
252261
return err
253262
}
263+
log.Log = logrus.WithFields(initmsg.OWI)
254264

255265
defer func() {
256266
if err != nil {

0 commit comments

Comments
 (0)