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

chore: use fmt.Errorf(...) instead of errors.New(fmt.Sprintf(...)) #83

Open
wants to merge 1 commit into
base: master
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
13 changes: 6 additions & 7 deletions throttler/pfctl.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package throttler

import (
"errors"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -48,13 +47,13 @@ func (i *pfctlThrottler) setup(c *Config) error {
// Enable firewall
err := i.c.execute(pfctlEnableFirewall)
if err != nil {
return errors.New(fmt.Sprintf("Could not enable firewall using: `%s`. Error: %s", pfctlEnableFirewall, err.Error()))
return fmt.Errorf("Could not enable firewall using: `%s`. Error: %s", pfctlEnableFirewall, err.Error())
}

// Add the dummynet and anchor
err = i.c.execute(pfctlCreateAnchor)
if err != nil {
return errors.New(fmt.Sprintf("Could not create anchor rule for dummynet using: `%s`. Error: %s", pfctlCreateAnchor, err.Error()))
return fmt.Errorf("Could not create anchor rule for dummynet using: `%s`. Error: %s", pfctlCreateAnchor, err.Error())
}

// Add 'execute' portion of the command
Expand All @@ -63,7 +62,7 @@ func (i *pfctlThrottler) setup(c *Config) error {

err = i.c.execute(cmd)
if err != nil {
return errors.New(fmt.Sprintf("Could not create dummynet using: `%s`. Error: %s", input, err.Error()))
return fmt.Errorf("Could not create dummynet using: `%s`. Error: %s", input, err.Error())
}

// Apply the shaping etc.
Expand All @@ -82,19 +81,19 @@ func (i *pfctlThrottler) teardown(_ *Config) error {
// Reset firewall rules, leave it running
err := i.c.execute(pfctlTeardown)
if err != nil {
return errors.New(fmt.Sprintf("Could not remove firewall rules using: `%s`. Error: %s", pfctlTeardown, err.Error()))
return fmt.Errorf("Could not remove firewall rules using: `%s`. Error: %s", pfctlTeardown, err.Error())
}

// Turn off the firewall, discarding any rules
err = i.c.execute(pfctlDisableFirewall)
if err != nil {
return errors.New(fmt.Sprintf("Could not disable firewall using: `%s`. Error: %s", pfctlDisableFirewall, err.Error()))
return fmt.Errorf("Could not disable firewall using: `%s`. Error: %s", pfctlDisableFirewall, err.Error())
}

// Disable dnctl rules
err = i.c.execute(dnctlTeardown)
if err != nil {
return errors.New(fmt.Sprintf("Could not disable dnctl rules using: `%s`. Error: %s", dnctlTeardown, err.Error()))
return fmt.Errorf("Could not disable dnctl rules using: `%s`. Error: %s", dnctlTeardown, err.Error())
}

return nil
Expand Down