Skip to content
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

refactor: clean-up nil error checks #851

Merged
merged 1 commit into from
Mar 1, 2023
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
6 changes: 1 addition & 5 deletions pkg/commands/acl/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(out, a)
if err != nil {
return err
}
return nil
return c.print(out, a)
}

// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/aclentry/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(out, a)
if err != nil {
return err
}
return nil
return c.print(out, a)
}

// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/authtoken/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(out, r)
if err != nil {
return err
}
return nil
return c.print(out, r)
}

// print displays the information returned from the API.
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/backend/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(out, backend)
if err != nil {
return err
}
return nil
return c.print(out, backend)
}

// print displays the information returned from the API.
Expand Down
12 changes: 2 additions & 10 deletions pkg/commands/compute/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,11 +782,7 @@ func pkgUpload(spinner text.Spinner, client api.Interface, serviceID string, ver
}

spinner.StopMessage(msg)
err = spinner.Stop()
if err != nil {
return err
}
return nil
return spinner.Stop()
}

// displayDomain displays a domain from those available in the service.
Expand Down Expand Up @@ -1117,9 +1113,5 @@ func processService(c *DeployCommand, serviceID string, serviceVersion int, spin
}

spinner.StopMessage(msg)
err = spinner.Stop()
if err != nil {
return err
}
return nil
return spinner.Stop()
}
7 changes: 1 addition & 6 deletions pkg/commands/compute/hashsum.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,5 @@ func (c *HashsumCommand) Build(in io.Reader, out io.Writer) error {
if !c.Globals.Verbose() {
output = io.Discard
}

err := c.buildCmd.Exec(in, output)
if err != nil {
return err
}
return nil
return c.buildCmd.Exec(in, output)
}
30 changes: 5 additions & 25 deletions pkg/commands/compute/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -638,11 +638,7 @@ func fetchPackageTemplate(
}

spinner.StopMessage(msg)
err = spinner.Stop()
if err != nil {
return err
}
return nil
return spinner.Stop()
}

req, err := http.NewRequest("GET", c.cloneFrom, nil)
Expand All @@ -659,11 +655,7 @@ func fetchPackageTemplate(
}

spinner.StopMessage(msg)
err = spinner.Stop()
if err != nil {
return err
}
return nil
return spinner.Stop()
}

spinner.StopFailMessage(msg)
Expand Down Expand Up @@ -823,11 +815,7 @@ mimes:
}

spinner.StopMessage(msg)
err = spinner.Stop()
if err != nil {
return err
}
return nil
return spinner.Stop()
}

if err := clonePackageFromEndpoint(c.cloneFrom, branch, tag, c.dir); err != nil {
Expand All @@ -840,11 +828,7 @@ mimes:
}

spinner.StopMessage(msg)
err = spinner.Stop()
if err != nil {
return err
}
return nil
return spinner.Stop()
}

// clonePackageFromEndpoint clones the given repo (from) into a temp directory,
Expand Down Expand Up @@ -1102,11 +1086,7 @@ func updateManifest(
}

spinner.StopMessage(msg)
err = spinner.Stop()
if err != nil {
return m, err
}
return m, nil
return m, spinner.Stop()
}

// initializeLanguage for newly cloned package.
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/compute/pack.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,5 @@ func (c *PackCommand) Exec(_ io.Reader, out io.Writer) (err error) {
}

spinner.StopMessage(msg)
err = spinner.Stop()
if err != nil {
return err
}
return nil
return spinner.Stop()
}
12 changes: 2 additions & 10 deletions pkg/commands/compute/serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,7 @@ func GetViceroy(spinner text.Spinner, out io.Writer, av github.AssetVersioner, g
}

spinner.StopMessage(msg)
err = spinner.Stop()
if err != nil {
return bin, err
}
return bin, nil
return bin, spinner.Stop()
}

spinner.StopMessage(msg)
Expand Down Expand Up @@ -389,11 +385,7 @@ func installViceroy(spinner text.Spinner, av github.AssetVersioner, bin string)
}

spinner.StopMessage(msg)
err = spinner.Stop()
if err != nil {
return err
}
return nil
return spinner.Stop()
}

// updateViceroy checks if the currently installed version is out-of-date and
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/compute/setup/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,7 @@ func (d *Domains) createDomain(name string, attempt int) error {
}

d.Spinner.StopMessage(msg)
err = d.Spinner.Stop()
if err != nil {
return err
}
return nil
return d.Spinner.Stop()
}

func generateDomainName() string {
Expand Down
7 changes: 1 addition & 6 deletions pkg/commands/profile/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,7 @@ func (c *CreateCommand) tokenFlow(profileName string, def bool, in io.Reader, ou
return err
}

err = c.updateInMemCfg(profileName, user.Login, token, endpoint, def, spinner)
if err != nil {
return err
}

return nil
return c.updateInMemCfg(profileName, user.Login, token, endpoint, def, spinner)
}

func promptForToken(in io.Reader, out io.Writer, errLog fsterr.LogInterface) (string, error) {
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/service/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(service, out)
if err != nil {
return err
}
return nil
return c.print(service, out)
}

func (c *DescribeCommand) print(s *fastly.ServiceDetail, out io.Writer) error {
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/serviceauth/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(service, out)
if err != nil {
return err
}
return nil
return c.print(service, out)
}

func (c *DescribeCommand) print(s *fastly.ServiceAuthorization, out io.Writer) error {
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/tls/config/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(out, r)
if err != nil {
return err
}
return nil
return c.print(out, r)
}

// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/tls/custom/activation/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(out, r)
if err != nil {
return err
}
return nil
return c.print(out, r)
}

// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/tls/custom/certificate/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(out, r)
if err != nil {
return err
}
return nil
return c.print(out, r)
}

// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/tls/custom/privatekey/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(out, r)
if err != nil {
return err
}
return nil
return c.print(out, r)
}

// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/tls/platform/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(out, r)
if err != nil {
return err
}
return nil
return c.print(out, r)
}

// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/tls/subscription/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(out, r)
if err != nil {
return err
}
return nil
return c.print(out, r)
}

// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
Expand Down
6 changes: 1 addition & 5 deletions pkg/commands/vcl/custom/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(out, v)
if err != nil {
return err
}
return nil
return c.print(out, v)
}

// constructInput transforms values parsed from CLI flags into an object to be used by the API client library.
Expand Down
12 changes: 2 additions & 10 deletions pkg/commands/vcl/snippet/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
})
return err
}
err = c.printDynamic(out, v)
if err != nil {
return err
}
return nil
return c.printDynamic(out, v)
}

input, err := c.constructInput(serviceID, serviceVersion.Number)
Expand All @@ -133,11 +129,7 @@ func (c *DescribeCommand) Exec(_ io.Reader, out io.Writer) error {
return err
}

err = c.print(out, v)
if err != nil {
return err
}
return nil
return c.print(out, v)
}

// constructDynamicInput transforms values parsed from CLI flags into an object to be used by the API client library.
Expand Down
6 changes: 1 addition & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,7 @@ type StarterKit struct {
// doesn't already exist.
func createConfigDir(path string) error {
basePath := filepath.Dir(path)
err := filesystem.MakeDirectoryIfNotExists(basePath)
if err != nil {
return err
}
return nil
return filesystem.MakeDirectoryIfNotExists(basePath)
}

// File represents our application toml configuration.
Expand Down
11 changes: 2 additions & 9 deletions pkg/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,21 +593,14 @@ func stripManifestSection(r io.Reader, path string) (*bytes.Buffer, error) {
}

err := os.WriteFile(path, buf.Bytes(), FilePermissions)
if err != nil {
return buf, err
}

return buf, nil
return buf, err
}

// appendSpecRef appends the fastly.toml specification URL to the manifest.
func appendSpecRef(w io.Writer) error {
s := fmt.Sprintf("# %s\n# %s\n\n", SpecIntro, SpecURL)
_, err := io.WriteString(w, s)
if err != nil {
return err
}
return nil
return err
}

// Flag represents all of the manifest parameters that can be set with explicit
Expand Down