Skip to content

Support some commands offline #1237

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions src/cmd/cli/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func prettyError(err error) error {
term.Debug("Server error:", cerr)
err = errors.Unwrap(cerr)
}
if cli.IsNetworkError(err) {
return fmt.Errorf("%w; please check network settings and try again", err)
Copy link
Collaborator

@commit111 commit111 Jun 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now it appears as:
Error: dial tcp: lookup fabric-prod1.defang.dev: no such host; please check network settings and try again

I'm a bit inclined to show the friendlier message unable to connect to Defang server %q; please check network settings and try again to the user instead of the raw error for simplicity, but this is just a matter of personal preference.

Otherwise, looks good to me.

}
return err
}

Expand Down Expand Up @@ -361,9 +364,6 @@ var RootCmd = &cobra.Command{
}

client, err = cli.Connect(cmd.Context(), getCluster())
if cli.IsNetworkError(err) {
return fmt.Errorf("unable to connect to Defang server %q; please check network settings and try again", cluster)
}

if v, err := client.GetVersions(cmd.Context()); err == nil {
version := cmd.Root().Version // HACK to avoid circular dependency with RootCmd
Expand Down Expand Up @@ -1280,7 +1280,7 @@ func determineProviderID(ctx context.Context, loader cliClient.Loader) (string,
if projectName != "" && !RootCmd.PersistentFlags().Changed("provider") { // If user manually selected auto provider, do not load from remote
resp, err := client.GetSelectedProvider(ctx, &defangv1.GetSelectedProviderRequest{Project: projectName})
if err != nil {
term.Warnf("Unable to get selected provider: %v", err)
term.Debugf("Unable to get selected provider: %v", err)
} else if resp.Provider != defangv1.Provider_PROVIDER_UNSPECIFIED {
providerID.SetValue(resp.Provider)
return "stored preference", nil
Expand All @@ -1293,7 +1293,7 @@ func determineProviderID(ctx context.Context, loader cliClient.Loader) (string,
// Save the selected provider to the fabric
if projectName != "" {
if err := client.SetSelectedProvider(ctx, &defangv1.SetSelectedProviderRequest{Project: projectName, Provider: providerID.Value()}); err != nil {
term.Warnf("Unable to save selected provider to defang server: %v", err)
term.Debugf("Unable to save selected provider to defang server: %v", err)
} else {
term.Printf("%v is now the default provider for project %v and will auto-select next time if no other provider is specified. Use --provider=auto to reselect.", providerID, projectName)
}
Expand Down
Loading