fix errname linting issues
Rename error variables and types to follow errname linter conventions: - Exported sentinels: ErrXxx - Unexported sentinels: errXxx - Exported error types: XxxError - Unexported error types: xxxError Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
dca59d52b6
commit
fb2162c027
105 changed files with 285 additions and 280 deletions
|
|
@ -377,7 +377,7 @@ func getExtensions(opts ExtBrowseOpts) ([]extEntry, error) {
|
|||
return extEntries, nil
|
||||
}
|
||||
|
||||
func ExtBrowse(opts ExtBrowseOpts) error {
|
||||
func ExtBrowse(opts ExtBrowseOpts) error { //nolint:gocyclo
|
||||
if opts.Debug {
|
||||
f, err := os.CreateTemp("", "extBrowse-*.txt")
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var alreadyInstalledError = errors.New("alreadyInstalledError")
|
||||
var errAlreadyInstalled = errors.New("errAlreadyInstalled")
|
||||
|
||||
func NewCmdExtension(f *cmdutil.Factory) *cobra.Command {
|
||||
func NewCmdExtension(f *cmdutil.Factory) *cobra.Command { //nolint:gocyclo
|
||||
m := f.ExtensionManager
|
||||
io := f.IOStreams
|
||||
gc := f.GitClient
|
||||
|
|
@ -61,12 +61,12 @@ func NewCmdExtension(f *cmdutil.Factory) *cobra.Command {
|
|||
if err != nil {
|
||||
if name != "" {
|
||||
fmt.Fprintf(io.ErrOut, "%s Failed upgrading extension %s: %s\n", cs.FailureIcon(), name, err)
|
||||
} else if errors.Is(err, noExtensionsInstalledError) {
|
||||
} else if errors.Is(err, errNoExtensionsInstalled) {
|
||||
return cmdutil.NewNoResultsError("no installed extensions found")
|
||||
} else {
|
||||
fmt.Fprintf(io.ErrOut, "%s Failed upgrading extensions\n", cs.FailureIcon())
|
||||
}
|
||||
return cmdutil.SilentError
|
||||
return cmdutil.ErrSilent
|
||||
}
|
||||
|
||||
if io.IsStdoutTTY() {
|
||||
|
|
@ -354,11 +354,11 @@ func NewCmdExtension(f *cmdutil.Factory) *cobra.Command {
|
|||
}
|
||||
|
||||
err = m.InstallLocal(wd)
|
||||
var ErrExtensionExecutableNotFound *ErrExtensionExecutableNotFound
|
||||
if errors.As(err, &ErrExtensionExecutableNotFound) {
|
||||
var ExtensionExecutableNotFoundError *ExtensionExecutableNotFoundError
|
||||
if errors.As(err, &ExtensionExecutableNotFoundError) {
|
||||
cs := io.ColorScheme()
|
||||
if io.IsStdoutTTY() {
|
||||
fmt.Fprintf(io.ErrOut, "%s %s", cs.WarningIcon(), ErrExtensionExecutableNotFound.Error())
|
||||
fmt.Fprintf(io.ErrOut, "%s %s", cs.WarningIcon(), ExtensionExecutableNotFoundError.Error())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -378,7 +378,7 @@ func NewCmdExtension(f *cmdutil.Factory) *cobra.Command {
|
|||
return upgradeFunc(ext.Name(), forceFlag)
|
||||
}
|
||||
|
||||
if errors.Is(err, alreadyInstalledError) {
|
||||
if errors.Is(err, errAlreadyInstalled) {
|
||||
fmt.Fprintf(io.ErrOut, "%s Extension %s is already installed\n", cs.WarningIcon(), ghrepo.FullName(repo))
|
||||
return nil
|
||||
}
|
||||
|
|
@ -391,13 +391,13 @@ func NewCmdExtension(f *cmdutil.Factory) *cobra.Command {
|
|||
io.StopProgressIndicator()
|
||||
|
||||
if err != nil {
|
||||
if errors.Is(err, releaseNotFoundErr) {
|
||||
if errors.Is(err, errReleaseNotFound) {
|
||||
return fmt.Errorf("%s Could not find a release of %s for %s",
|
||||
cs.FailureIcon(), args[0], cs.Cyan(pinFlag))
|
||||
} else if errors.Is(err, commitNotFoundErr) {
|
||||
} else if errors.Is(err, errCommitNotFound) {
|
||||
return fmt.Errorf("%s %s does not exist in %s",
|
||||
cs.FailureIcon(), cs.Cyan(pinFlag), args[0])
|
||||
} else if errors.Is(err, repositoryNotFoundErr) {
|
||||
} else if errors.Is(err, errRepositoryNotFound) {
|
||||
return fmt.Errorf("%s Could not find extension '%s' on host %s",
|
||||
cs.FailureIcon(), args[0], repo.RepoHost())
|
||||
}
|
||||
|
|
@ -698,7 +698,7 @@ func checkValidExtension(rootCmd *cobra.Command, m extensions.ExtensionManager,
|
|||
for _, ext := range m.List() {
|
||||
if ext.Name() == commandName {
|
||||
if extOwner != "" && ext.Owner() == extOwner {
|
||||
return ext, alreadyInstalledError
|
||||
return ext, errAlreadyInstalled
|
||||
}
|
||||
return ext, fmt.Errorf("there is already an installed extension that provides the %q command", commandName)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -290,7 +290,7 @@ func TestNewCmdExtension(t *testing.T) {
|
|||
args: []string{"install", "."},
|
||||
managerStubs: func(em *extensions.ExtensionManagerMock) func(*testing.T) {
|
||||
em.InstallLocalFunc = func(dir string) error {
|
||||
return &ErrExtensionExecutableNotFound{
|
||||
return &ExtensionExecutableNotFoundError{
|
||||
Dir: tempDir,
|
||||
Name: "gh-test",
|
||||
}
|
||||
|
|
@ -309,7 +309,7 @@ func TestNewCmdExtension(t *testing.T) {
|
|||
args: []string{"install", "."},
|
||||
managerStubs: func(em *extensions.ExtensionManagerMock) func(*testing.T) {
|
||||
em.InstallLocalFunc = func(dir string) error {
|
||||
return &ErrExtensionExecutableNotFound{
|
||||
return &ExtensionExecutableNotFoundError{
|
||||
Dir: tempDir,
|
||||
Name: "gh-test",
|
||||
}
|
||||
|
|
@ -331,7 +331,7 @@ func TestNewCmdExtension(t *testing.T) {
|
|||
return []extensions.Extension{}
|
||||
}
|
||||
em.InstallFunc = func(_ ghrepo.Interface, _ string) error {
|
||||
return repositoryNotFoundErr
|
||||
return errRepositoryNotFound
|
||||
}
|
||||
return func(t *testing.T) {
|
||||
installCalls := em.InstallCalls()
|
||||
|
|
@ -445,7 +445,7 @@ func TestNewCmdExtension(t *testing.T) {
|
|||
},
|
||||
isTTY: false,
|
||||
wantErr: true,
|
||||
errMsg: "SilentError",
|
||||
errMsg: "ErrSilent",
|
||||
wantStdout: "",
|
||||
wantStderr: "X Failed upgrading extension hello: oh no\n",
|
||||
},
|
||||
|
|
@ -522,7 +522,7 @@ func TestNewCmdExtension(t *testing.T) {
|
|||
args: []string{"upgrade", "--all"},
|
||||
managerStubs: func(em *extensions.ExtensionManagerMock) func(*testing.T) {
|
||||
em.UpgradeFunc = func(name string, force bool) error {
|
||||
return noExtensionsInstalledError
|
||||
return errNoExtensionsInstalled
|
||||
}
|
||||
return func(t *testing.T) {
|
||||
calls := em.UpgradeCalls()
|
||||
|
|
@ -1052,7 +1052,7 @@ func Test_checkValidExtension(t *testing.T) {
|
|||
extOwner: "monalisa",
|
||||
extName: "gh-triage",
|
||||
},
|
||||
wantError: "alreadyInstalledError",
|
||||
wantError: "errAlreadyInstalled",
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
|
|
|||
|
|
@ -107,9 +107,9 @@ func downloadAsset(httpClient *http.Client, asset releaseAsset, destPath string)
|
|||
return
|
||||
}
|
||||
|
||||
var commitNotFoundErr = errors.New("commit not found")
|
||||
var releaseNotFoundErr = errors.New("release not found")
|
||||
var repositoryNotFoundErr = errors.New("repository not found")
|
||||
var errCommitNotFound = errors.New("commit not found")
|
||||
var errReleaseNotFound = errors.New("release not found")
|
||||
var errRepositoryNotFound = errors.New("repository not found")
|
||||
|
||||
// fetchLatestRelease finds the latest published release for a repository.
|
||||
func fetchLatestRelease(httpClient *http.Client, baseRepo ghrepo.Interface) (*release, error) {
|
||||
|
|
@ -127,7 +127,7 @@ func fetchLatestRelease(httpClient *http.Client, baseRepo ghrepo.Interface) (*re
|
|||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode == 404 {
|
||||
return nil, releaseNotFoundErr
|
||||
return nil, errReleaseNotFound
|
||||
}
|
||||
if resp.StatusCode > 299 {
|
||||
return nil, api.HandleHTTPError(resp)
|
||||
|
|
@ -164,7 +164,7 @@ func fetchReleaseFromTag(httpClient *http.Client, baseRepo ghrepo.Interface, tag
|
|||
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == 404 {
|
||||
return nil, releaseNotFoundErr
|
||||
return nil, errReleaseNotFound
|
||||
}
|
||||
if resp.StatusCode > 299 {
|
||||
return nil, api.HandleHTTPError(resp)
|
||||
|
|
@ -201,7 +201,7 @@ func fetchCommitSHA(httpClient *http.Client, baseRepo ghrepo.Interface, targetRe
|
|||
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode == 422 {
|
||||
return "", commitNotFoundErr
|
||||
return "", errCommitNotFound
|
||||
}
|
||||
if resp.StatusCode > 299 {
|
||||
return "", api.HandleHTTPError(resp)
|
||||
|
|
|
|||
|
|
@ -30,12 +30,12 @@ import (
|
|||
// ErrInitialCommitFailed indicates the initial commit when making a new extension failed.
|
||||
var ErrInitialCommitFailed = errors.New("initial commit failed")
|
||||
|
||||
type ErrExtensionExecutableNotFound struct {
|
||||
type ExtensionExecutableNotFoundError struct {
|
||||
Dir string
|
||||
Name string
|
||||
}
|
||||
|
||||
func (e *ErrExtensionExecutableNotFound) Error() string {
|
||||
func (e *ExtensionExecutableNotFoundError) Error() string {
|
||||
return fmt.Sprintf("an extension has been installed but there is no executable: executable file named \"%s\" in %s is required to run the extension after install. Perhaps you need to build it?\n", e.Name, e.Dir)
|
||||
}
|
||||
|
||||
|
|
@ -225,7 +225,7 @@ func (m *Manager) InstallLocal(dir string) error {
|
|||
// the executable file is built or created manually somehow.
|
||||
if _, err := os.Stat(filepath.Join(dir, name)); err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
return &ErrExtensionExecutableNotFound{
|
||||
return &ExtensionExecutableNotFoundError{
|
||||
Dir: dir,
|
||||
Name: name,
|
||||
}
|
||||
|
|
@ -249,11 +249,11 @@ type binManifest struct {
|
|||
func (m *Manager) Install(repo ghrepo.Interface, target string) error {
|
||||
isBin, err := isBinExtension(m.client, repo)
|
||||
if err != nil {
|
||||
if errors.Is(err, releaseNotFoundErr) {
|
||||
if errors.Is(err, errReleaseNotFound) {
|
||||
if ok, err := repoExists(m.client, repo); err != nil {
|
||||
return err
|
||||
} else if !ok {
|
||||
return repositoryNotFoundErr
|
||||
return errRepositoryNotFound
|
||||
}
|
||||
} else {
|
||||
return fmt.Errorf("could not check for binary extension: %w", err)
|
||||
|
|
@ -446,10 +446,10 @@ func (m *Manager) installGit(repo ghrepo.Interface, target string) error {
|
|||
return f.Close()
|
||||
}
|
||||
|
||||
var pinnedExtensionUpgradeError = errors.New("pinned extensions can not be upgraded")
|
||||
var localExtensionUpgradeError = errors.New("local extensions can not be upgraded")
|
||||
var upToDateError = errors.New("already up to date")
|
||||
var noExtensionsInstalledError = errors.New("no extensions installed")
|
||||
var errPinnedExtensionUpgrade = errors.New("pinned extensions can not be upgraded")
|
||||
var errLocalExtensionUpgrade = errors.New("local extensions can not be upgraded")
|
||||
var errUpToDate = errors.New("already up to date")
|
||||
var errNoExtensionsInstalled = errors.New("no extensions installed")
|
||||
|
||||
func (m *Manager) Upgrade(name string, force bool) error {
|
||||
// Fetch metadata during list only when upgrading all extensions.
|
||||
|
|
@ -458,7 +458,7 @@ func (m *Manager) Upgrade(name string, force bool) error {
|
|||
fetchMetadata := name == ""
|
||||
exts, _ := m.list(fetchMetadata)
|
||||
if len(exts) == 0 {
|
||||
return noExtensionsInstalledError
|
||||
return errNoExtensionsInstalled
|
||||
}
|
||||
if name == "" {
|
||||
return m.upgradeExtensions(exts, force)
|
||||
|
|
@ -468,7 +468,7 @@ func (m *Manager) Upgrade(name string, force bool) error {
|
|||
continue
|
||||
}
|
||||
if f.IsLocal() {
|
||||
return localExtensionUpgradeError
|
||||
return errLocalExtensionUpgrade
|
||||
}
|
||||
// For single extensions manually retrieve latest version since we forgo doing it during list.
|
||||
if latestVersion := f.LatestVersion(); latestVersion == "" {
|
||||
|
|
@ -491,9 +491,9 @@ func (m *Manager) upgradeExtensions(exts []*Extension, force bool) error {
|
|||
currentVersion := displayExtensionVersion(f, f.CurrentVersion())
|
||||
err := m.upgradeExtension(f, force)
|
||||
if err != nil {
|
||||
if !errors.Is(err, localExtensionUpgradeError) &&
|
||||
!errors.Is(err, upToDateError) &&
|
||||
!errors.Is(err, pinnedExtensionUpgradeError) {
|
||||
if !errors.Is(err, errLocalExtensionUpgrade) &&
|
||||
!errors.Is(err, errUpToDate) &&
|
||||
!errors.Is(err, errPinnedExtensionUpgrade) {
|
||||
failed = true
|
||||
}
|
||||
fmt.Fprintf(m.io.Out, "%s\n", err)
|
||||
|
|
@ -514,13 +514,13 @@ func (m *Manager) upgradeExtensions(exts []*Extension, force bool) error {
|
|||
|
||||
func (m *Manager) upgradeExtension(ext *Extension, force bool) error {
|
||||
if ext.IsLocal() {
|
||||
return localExtensionUpgradeError
|
||||
return errLocalExtensionUpgrade
|
||||
}
|
||||
if !force && ext.IsPinned() {
|
||||
return pinnedExtensionUpgradeError
|
||||
return errPinnedExtensionUpgrade
|
||||
}
|
||||
if !ext.UpdateAvailable() {
|
||||
return upToDateError
|
||||
return errUpToDate
|
||||
}
|
||||
var err error
|
||||
if ext.IsBinary() {
|
||||
|
|
|
|||
|
|
@ -719,7 +719,7 @@ func TestManager_UpgradeExtension_BinaryExtension_Pinned(t *testing.T) {
|
|||
|
||||
err = m.upgradeExtension(ext, false)
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, err, pinnedExtensionUpgradeError)
|
||||
assert.Equal(t, err, errPinnedExtensionUpgrade)
|
||||
}
|
||||
|
||||
func TestManager_UpgradeExtension_GitExtension_Pinned(t *testing.T) {
|
||||
|
|
@ -746,7 +746,7 @@ func TestManager_UpgradeExtension_GitExtension_Pinned(t *testing.T) {
|
|||
|
||||
err = m.upgradeExtension(ext, false)
|
||||
assert.NotNil(t, err)
|
||||
assert.Equal(t, err, pinnedExtensionUpgradeError)
|
||||
assert.Equal(t, err, errPinnedExtensionUpgrade)
|
||||
gc.AssertExpectations(t)
|
||||
gcOne.AssertExpectations(t)
|
||||
}
|
||||
|
|
@ -814,7 +814,7 @@ func TestManager_Install_local_no_executable_found(t *testing.T) {
|
|||
// to simulate an attempt to install a local extension without an executable
|
||||
|
||||
err := m.InstallLocal(localDir)
|
||||
require.ErrorAs(t, err, new(*ErrExtensionExecutableNotFound))
|
||||
require.ErrorAs(t, err, new(*ExtensionExecutableNotFoundError))
|
||||
assert.Equal(t, "", stdout.String())
|
||||
assert.Equal(t, "", stderr.String())
|
||||
require.NoDirExistsf(t, extensionUpdatePath, "update directory should be removed")
|
||||
|
|
@ -1274,8 +1274,8 @@ func TestManager_repo_not_found(t *testing.T) {
|
|||
|
||||
m := newTestManager(dataDir, updateDir, &http.Client{Transport: ®}, nil, ios)
|
||||
|
||||
if err := m.Install(repo, ""); err != repositoryNotFoundErr {
|
||||
t.Errorf("expected repositoryNotFoundErr, got: %v", err)
|
||||
if err := m.Install(repo, ""); err != errRepositoryNotFound {
|
||||
t.Errorf("expected errRepositoryNotFound, got: %v", err)
|
||||
}
|
||||
|
||||
assert.Equal(t, "", stdout.String())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue