Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore(cli): use xerrors.Errorf instead of fmt.Errorf#12368

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
johnstcn merged 2 commits intomainfromcj/lint-xerrors
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
16 changes: 9 additions & 7 deletionscli/organization.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,8 @@ import (
"slices"
"strings"

"golang.org/x/xerrors"

"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/cli/config"
Expand DownExpand Up@@ -60,7 +62,7 @@ func (r *RootCmd) switchOrganization() *clibase.Cmd {
conf := r.createConfig()
orgs, err := client.OrganizationsByUser(inv.Context(), codersdk.Me)
if err != nil {
returnfmt.Errorf("failed to get organizations: %w", err)
returnxerrors.Errorf("failed to get organizations: %w", err)
}
// Keep the list of orgs sorted
slices.SortFunc(orgs, func(a, b codersdk.Organization) int {
Expand All@@ -84,7 +86,7 @@ func (r *RootCmd) switchOrganization() *clibase.Cmd {
if switchToOrg == "" {
err := conf.Organization().Delete()
if err != nil && !errors.Is(err, os.ErrNotExist) {
returnfmt.Errorf("failed to unset organization: %w", err)
returnxerrors.Errorf("failed to unset organization: %w", err)
}
_, _ = fmt.Fprintf(inv.Stdout, "Organization unset\n")
} else {
Expand All@@ -107,7 +109,7 @@ func (r *RootCmd) switchOrganization() *clibase.Cmd {
// Always write the uuid to the config file. Names can change.
err := conf.Organization().Write(orgs[index].ID.String())
if err != nil {
returnfmt.Errorf("failed to write organization to config file: %w", err)
returnxerrors.Errorf("failed to write organization to config file: %w", err)
}
}

Expand All@@ -123,7 +125,7 @@ func (r *RootCmd) switchOrganization() *clibase.Cmd {
}
return sdkError
}
returnfmt.Errorf("failed to get current organization: %w", err)
returnxerrors.Errorf("failed to get current organization: %w", err)
}

_, _ = fmt.Fprintf(inv.Stdout, "Current organization context set to %s (%s)\n", current.Name, current.ID.String())
Expand DownExpand Up@@ -213,7 +215,7 @@ func (r *RootCmd) currentOrganization() *clibase.Cmd {
typed, ok := data.([]codersdk.Organization)
if !ok {
// This should never happen
return "",fmt.Errorf("expected []Organization, got %T", data)
return "",xerrors.Errorf("expected []Organization, got %T", data)
}
return stringFormat(typed)
}),
Expand DownExpand Up@@ -250,7 +252,7 @@ func (r *RootCmd) currentOrganization() *clibase.Cmd {
case "current":
stringFormat = func(orgs []codersdk.Organization) (string, error) {
if len(orgs) != 1 {
return "",fmt.Errorf("expected 1 organization, got %d", len(orgs))
return "",xerrors.Errorf("expected 1 organization, got %d", len(orgs))
}
return fmt.Sprintf("Current CLI Organization: %s (%s)\n", orgs[0].Name, orgs[0].ID.String()), nil
}
Expand All@@ -275,7 +277,7 @@ func (r *RootCmd) currentOrganization() *clibase.Cmd {
default:
stringFormat = func(orgs []codersdk.Organization) (string, error) {
if len(orgs) != 1 {
return "",fmt.Errorf("expected 1 organization, got %d", len(orgs))
return "",xerrors.Errorf("expected 1 organization, got %d", len(orgs))
}
return fmt.Sprintf("Organization: %s (%s)\n", orgs[0].Name, orgs[0].ID.String()), nil
}
Expand Down
5 changes: 3 additions & 2 deletionscli/organizationmanage.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,6 +4,7 @@ import (
"fmt"

"github.com/google/uuid"
"golang.org/x/xerrors"

"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/cliui"
Expand DownExpand Up@@ -34,7 +35,7 @@ func (r *RootCmd) createOrganization() *clibase.Cmd {
// from creating it.
existing, _ := client.OrganizationByName(inv.Context(), orgName)
if existing.ID != uuid.Nil {
returnfmt.Errorf("organization %q already exists", orgName)
returnxerrors.Errorf("organization %q already exists", orgName)
}

_, err := cliui.Prompt(inv, cliui.PromptOptions{
Expand All@@ -53,7 +54,7 @@ func (r *RootCmd) createOrganization() *clibase.Cmd {
Name: orgName,
})
if err != nil {
returnfmt.Errorf("failed to create organization: %w", err)
returnxerrors.Errorf("failed to create organization: %w", err)
}

_, _ = fmt.Fprintf(inv.Stdout, "Organization %s (%s) created.\n", organization.Name, organization.ID)
Expand Down
2 changes: 1 addition & 1 deletioncli/root.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -715,7 +715,7 @@ func CurrentOrganization(r *RootCmd, inv *clibase.Invocation, client *codersdk.C
if selected == "" && conf.Organization().Exists() {
org, err := conf.Organization().Read()
if err != nil {
return codersdk.Organization{},fmt.Errorf("read selected organization from config file %q: %w", conf.Organization(), err)
return codersdk.Organization{},xerrors.Errorf("read selected organization from config file %q: %w", conf.Organization(), err)
}
selected = org
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp