Skip to content

Commit

Permalink
fix-lint: replace fmt.Errorf with errors.New
Browse files Browse the repository at this point in the history
  • Loading branch information
F1bonacc1 committed Oct 2, 2024
1 parent 16eabf9 commit f3a41fd
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/app/project_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (p *ProjectRunner) StopProcesses(names []string) (map[string]string, error)
if successes == 0 {
return stopped, fmt.Errorf("no such processes or not running: %v", names)
}
return stopped, fmt.Errorf("failed to stop some processes")
return stopped, errors.New("failed to stop some processes")
}
return stopped, nil
}
Expand Down Expand Up @@ -398,7 +398,7 @@ func (p *ProjectRunner) SetProcessPassword(name, pass string) error {
}
}

return fmt.Errorf("password not accepted")
return errors.New("password not accepted")

}

Expand Down
3 changes: 2 additions & 1 deletion src/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"context"
"errors"
"fmt"
"github.com/f1bonacc1/process-compose/src/pclog"
"github.com/f1bonacc1/process-compose/src/types"
Expand Down Expand Up @@ -161,7 +162,7 @@ func (p *PcClient) GetProjectState(withMemory bool) (*types.ProjectState, error)
}

func (p *PcClient) SetProcessPassword(_, _ string) error {
return fmt.Errorf("set process password not allowed for PC client")
return errors.New("set process password not allowed for PC client")
}

func (p *PcClient) UpdateProject(project *types.Project) (map[string]string, error) {
Expand Down
5 changes: 3 additions & 2 deletions src/client/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/f1bonacc1/process-compose/src/types"
"github.com/rs/zerolog/log"
Expand Down Expand Up @@ -76,7 +77,7 @@ func (p *PcClient) updateProject(project *types.Project) (map[string]string, err
log.Err(err).Msg("failed to decode err update project")
return nil, err
}
return nil, fmt.Errorf(respErr.Error)
return nil, errors.New(respErr.Error)
}

func (p *PcClient) reloadProject() (map[string]string, error) {
Expand All @@ -102,5 +103,5 @@ func (p *PcClient) reloadProject() (map[string]string, error) {
log.Err(err).Msg("failed to decode err update project")
return nil, err
}
return nil, fmt.Errorf(respErr.Error)
return nil, errors.New(respErr.Error)
}
3 changes: 2 additions & 1 deletion src/client/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"encoding/json"
"errors"
"fmt"
"github.com/rs/zerolog/log"
"net/http"
Expand All @@ -22,5 +23,5 @@ func (p *PcClient) restartProcess(name string) error {
log.Error().Msgf("failed to decode restart process %s response: %v", name, err)
return err
}
return fmt.Errorf(respErr.Error)
return errors.New(respErr.Error)
}
3 changes: 2 additions & 1 deletion src/client/scale_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"encoding/json"
"errors"
"fmt"
"github.com/rs/zerolog/log"
"net/http"
Expand All @@ -26,5 +27,5 @@ func (p *PcClient) scaleProcess(name string, scale int) error {
log.Error().Msgf("failed to decode scale process %s response: %v", name, err)
return err
}
return fmt.Errorf(respErr.Error)
return errors.New(respErr.Error)
}
3 changes: 2 additions & 1 deletion src/client/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package client

import (
"encoding/json"
"errors"
"fmt"
"github.com/rs/zerolog/log"
"net/http"
Expand All @@ -22,5 +23,5 @@ func (p *PcClient) startProcess(name string) error {
log.Error().Msgf("failed to decode start process %s response: %v", name, err)
return err
}
return fmt.Errorf(respErr.Error)
return errors.New(respErr.Error)
}
5 changes: 3 additions & 2 deletions src/client/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package client
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"github.com/rs/zerolog/log"
"net/http"
Expand All @@ -28,7 +29,7 @@ func (p *PcClient) stopProcess(name string) error {
log.Error().Msgf("failed to decode stop process %s response: %v", name, err)
return err
}
return fmt.Errorf(respErr.Error)
return errors.New(respErr.Error)
}

func (p *PcClient) stopProcesses(names []string) (map[string]string, error) {
Expand Down Expand Up @@ -62,5 +63,5 @@ func (p *PcClient) stopProcesses(names []string) (map[string]string, error) {
log.Err(err).Msgf("failed to decode err stop processes %v", names)
return nil, err
}
return nil, fmt.Errorf(respErr.Error)
return nil, errors.New(respErr.Error)
}
3 changes: 2 additions & 1 deletion src/command/command_wrapper_pty.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package command

import (
"errors"
"fmt"
"github.com/creack/pty"
"golang.org/x/term"
Expand Down Expand Up @@ -39,7 +40,7 @@ func (c *CmdWrapperPty) StdoutPipe() (io.ReadCloser, error) {
}

func (c *CmdWrapperPty) StderrPipe() (io.ReadCloser, error) {
return nil, fmt.Errorf("not supported in PTY")
return nil, errors.New("not supported in PTY")
}
func (c *CmdWrapperPty) StdinPipe() (io.WriteCloser, error) {
if c.ptmx == nil {
Expand Down
13 changes: 7 additions & 6 deletions src/loader/validators.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package loader

import (
"errors"
"fmt"
"github.com/f1bonacc1/process-compose/src/types"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -114,22 +115,22 @@ func validateHealthDependencyHasHealthCheck(p *types.Project) error {
if !ok {
errStr := fmt.Sprintf("dependency process '%s' in process '%s' is not defined", depName, procName)
if p.IsStrict {
return fmt.Errorf(errStr)
return errors.New(errStr)
}
log.Error().Msg(errStr)
continue
}
if dep.Condition == types.ProcessConditionHealthy && depProc.ReadinessProbe == nil && depProc.LivenessProbe == nil {
errStr := fmt.Sprintf("health dependency defined in '%s' but no health check exists in '%s'", procName, depName)
if p.IsStrict {
return fmt.Errorf(errStr)
return errors.New(errStr)
}
log.Error().Msg(errStr)
}
if dep.Condition == types.ProcessConditionLogReady && depProc.ReadyLogLine == "" {
errStr := fmt.Sprintf("log ready dependency defined in '%s' but no ready log line exists in '%s'", procName, depName)
log.Error().Msg(errStr)
return fmt.Errorf(errStr)
return errors.New(errStr)
}
}
}
Expand All @@ -141,7 +142,7 @@ func validateNoIncompatibleHealthChecks(p *types.Project) error {
if proc.ReadinessProbe != nil && proc.ReadyLogLine != "" {
errStr := fmt.Sprintf("'ready_log_line' and readiness probe defined in '%s' are incompatible", procName)
log.Error().Msg(errStr)
return fmt.Errorf(errStr)
return errors.New(errStr)
}
}
return nil
Expand All @@ -154,15 +155,15 @@ func validateDependencyIsEnabled(p *types.Project) error {
if !ok {
errStr := fmt.Sprintf("dependency process '%s' in process '%s' is not defined", depName, procName)
if p.IsStrict {
return fmt.Errorf(errStr)
return errors.New(errStr)
}
log.Error().Msg(errStr)
continue
}
if depProc.Disabled {
errStr := fmt.Sprintf("dependency process '%s' in process '%s' is disabled", depName, procName)
if p.IsStrict {
return fmt.Errorf(errStr)
return errors.New(errStr)
}
log.Error().Msg(errStr)
}
Expand Down
2 changes: 1 addition & 1 deletion src/tui/proc-editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,5 @@ func findTextEditor() (string, error) {
}
}

return "", fmt.Errorf("no text editor found")
return "", errors.New("no text editor found")
}
3 changes: 2 additions & 1 deletion src/tui/proc-table.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tui

import (
"context"
"errors"
"fmt"
"github.com/f1bonacc1/process-compose/src/types"
"github.com/gdamore/tcell/v2"
Expand Down Expand Up @@ -159,7 +160,7 @@ func (pv *pcView) isPassModeNeeded(state *types.ProcessState) bool {
func (pv *pcView) getSelectedProcState() (*types.ProcessState, error) {
name := pv.getSelectedProcName()
if len(name) == 0 {
return nil, fmt.Errorf("no process selected")
return nil, errors.New("no process selected")
}
return pv.project.GetProcessState(name)
}
Expand Down
3 changes: 2 additions & 1 deletion src/tui/procstate_sorter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tui

import (
"errors"
"fmt"
"github.com/f1bonacc1/process-compose/src/types"
"sort"
Expand Down Expand Up @@ -81,7 +82,7 @@ type sortFn func(i, j int) bool
func sortProcessesState(sortBy ColumnID, asc bool, states *types.ProcessesState) error {

if states == nil {
return fmt.Errorf("empty states")
return errors.New("empty states")
}
sorter := getSorter(sortBy, states)
if !asc {
Expand Down

0 comments on commit f3a41fd

Please sign in to comment.