Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 2 additions & 38 deletions src/cmd/cli/command/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/DefangLabs/defang/src/pkg/stacks"
"github.com/DefangLabs/defang/src/pkg/term"
"github.com/DefangLabs/defang/src/pkg/timeutils"
"github.com/DefangLabs/defang/src/pkg/track"
"github.com/DefangLabs/defang/src/pkg/types"
defangv1 "github.com/DefangLabs/defang/src/protos/io/defang/v1"
"github.com/bufbuild/connect-go"
Expand Down Expand Up @@ -83,23 +82,7 @@ func makeComposeUpCmd() *cobra.Command {

project, loadErr := session.Loader.LoadProject(ctx)
if loadErr != nil {
if global.NonInteractive {
return loadErr
}

term.Error("Cannot load project:", loadErr)
project, err := session.Loader.CreateProjectForDebug()
if err != nil {
return err
}

debugger, err := debug.NewDebugger(ctx, global.Cluster, session.Stack)
if err != nil {
return err
}
return debugger.DebugComposeLoadError(ctx, debug.DebugConfig{
Project: project,
}, loadErr)
return handleInvalidComposeFileErr(ctx, loadErr)
}

// Check if the user has permission to use the provider
Expand Down Expand Up @@ -550,26 +533,7 @@ func makeComposeConfigCmd() *cobra.Command {

project, loadErr := sessionx.Loader.LoadProject(ctx)
if loadErr != nil {
if global.NonInteractive {
return loadErr
}

term.Error("Cannot load project:", loadErr)
project, err := sessionx.Loader.CreateProjectForDebug()
if err != nil {
term.Warn("Failed to create project for debug:", err)
return loadErr
}

track.Evt("Debug Prompted", P("loadErr", loadErr))
debugger, err := debug.NewDebugger(ctx, global.Cluster, &global.Stack)
if err != nil {
term.Warn("Failed to initialize debugger:", err)
return loadErr
}
return debugger.DebugComposeLoadError(ctx, debug.DebugConfig{
Project: project,
}, loadErr)
return handleInvalidComposeFileErr(ctx, loadErr)
}

_, _, err = cli.ComposeUp(ctx, global.Client, sessionx.Provider, sessionx.Stack, cli.ComposeUpParams{
Expand Down
33 changes: 33 additions & 0 deletions src/cmd/cli/command/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import (
"github.com/AlecAivazis/survey/v2"
"github.com/DefangLabs/defang/src/pkg/cli/client"
"github.com/DefangLabs/defang/src/pkg/cli/compose"
"github.com/DefangLabs/defang/src/pkg/debug"
"github.com/DefangLabs/defang/src/pkg/session"
"github.com/DefangLabs/defang/src/pkg/stacks"
"github.com/DefangLabs/defang/src/pkg/term"
"github.com/DefangLabs/defang/src/pkg/track"
"github.com/DefangLabs/defang/src/pkg/types"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -102,6 +104,9 @@ func newStackManagerForLoader(ctx context.Context, loader *compose.Loader) (sess
}
projectName, _, err := loader.LoadProjectName(ctx)
if err != nil {
if !errors.Is(err, types.ErrComposeFileNotFound) {
return nil, handleInvalidComposeFileErr(ctx, err)
}
term.Debugf("Could not determine project name: %v", err)
}
sm, err := stacks.NewManager(global.Client, targetDirectory, projectName, ec)
Expand Down Expand Up @@ -133,3 +138,31 @@ func findTargetDirectory() (string, error) {
wd = parent
}
}

func handleInvalidComposeFileErr(ctx context.Context, err error) error {
if global.NonInteractive {
return err
}

if !strings.HasPrefix(err.Error(), "yaml: ") && !strings.HasPrefix(err.Error(), "validating ") {
return err
}

term.Error("Cannot load project:", err)
project, err := compose.NewLoader().CreateProjectForDebug()
if err != nil {
return err
}

debugger, err := debug.NewDebugger(ctx, global.Cluster, &stacks.Parameters{})
if err != nil {
return err
}
debugErr := debugger.DebugComposeLoadError(ctx, debug.DebugConfig{
Project: project,
}, err)
if debugErr != nil {
return fmt.Errorf("failed to debug compose load error: %w; original error: %v", debugErr, err)
}
return err
}
1 change: 0 additions & 1 deletion src/pkg/cli/compose/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ func (l *Loader) loadProject(ctx context.Context, suppressWarn bool) (*Project,
if errors.Is(err, errdefs.ErrNotFound) {
return nil, types.ErrComposeFileNotFound
}

return nil, err
}

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/debug/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func (d *Debugger) promptAndTrackDebugSession(fn func() error, eventName string,
func (d *Debugger) promptForPermission() (bool, error) {
var aiDebug bool
err := d.surveyor.AskOne(&survey.Confirm{
Message: "Would you like to debug the deployment with AI?",
Message: "Would you like to debug this with the Defang AI Agent?",
Help: "This will send logs and artifacts to our backend and attempt to diagnose the issue and provide a solution.",
}, &aiDebug, survey.WithStdio(term.DefaultTerm.Stdio()))
if err != nil {
Expand Down