Skip to content

Commit 7994211

Browse files
praveenkumaranjannath
authored andcommitted
Rename error functions to adopt format convention
NewF => Newf
1 parent d1eb47a commit 7994211

6 files changed

Lines changed: 16 additions & 16 deletions

File tree

pkg/crc/config/viper_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ func Unset(key string) error {
3333
delete(ViperConfig, key)
3434
encodedConfig, err := json.MarshalIndent(ViperConfig, "", " ")
3535
if err != nil {
36-
return errors.NewF("Error encoding config to JSON: %v", err)
36+
return errors.Newf("Error encoding config to JSON: %v", err)
3737
}
3838
err = globalViper.ReadConfig(bytes.NewBuffer(encodedConfig))
3939
if err != nil {
40-
return errors.NewF("Error reading in new config: %s : %v", constants.ConfigFile, err)
40+
return errors.Newf("Error reading in new config: %s : %v", constants.ConfigFile, err)
4141
}
4242
return nil
4343
}

pkg/crc/errors/error.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func New(text string) error {
1212
return goerrors.New(text)
1313
}
1414

15-
func NewF(text string, args ...interface{}) error {
15+
func Newf(text string, args ...interface{}) error {
1616
logging.Errorf(fmt.Sprintf("Error occurred: %s", text), args...)
1717
return fmt.Errorf(text, args...)
1818
}

pkg/crc/machine/driver.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ func getDriverInfo(driver string) (*MachineDriver, error) {
3232
return &d, nil
3333
}
3434
}
35-
return nil, errors.NewF("No info about unknown driver: %s", driver)
35+
return nil, errors.Newf("No info about unknown driver: %s", driver)
3636
}

pkg/crc/machine/machine.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func Start(startConfig StartConfig) (StartResult, error) {
124124
}
125125

126126
if host.Driver.DriverName() != startConfig.VMDriver {
127-
err := errors.NewF("VM driver '%s' was requested, but loaded VM is using '%s' instead",
127+
err := errors.Newf("VM driver '%s' was requested, but loaded VM is using '%s' instead",
128128
startConfig.VMDriver, host.Driver.DriverName())
129129
result.Error = err.Error()
130130
return *result, err
@@ -453,7 +453,7 @@ func Status(statusConfig ClusterStatusConfig) (ClusterStatusResult, error) {
453453
func existVM(api libmachine.API, machineConfig config.MachineConfig) (bool, error) {
454454
exists, err := api.Exists(machineConfig.Name)
455455
if err != nil {
456-
return false, errors.NewF("Error checking if the host exists: %s", err)
456+
return false, errors.Newf("Error checking if the host exists: %s", err)
457457
}
458458
return exists, nil
459459
}
@@ -465,11 +465,11 @@ func createHost(api libmachine.API, driverPath string, machineConfig config.Mach
465465
vm, err := api.NewHost(machineConfig.VMDriver, driverPath, jsonDriverConfig)
466466

467467
if err != nil {
468-
return nil, errors.NewF("Error creating new host: %s", err)
468+
return nil, errors.Newf("Error creating new host: %s", err)
469469
}
470470

471471
if err := api.Create(vm); err != nil {
472-
return nil, errors.NewF("Error creating the VM. %s", err)
472+
return nil, errors.Newf("Error creating the VM. %s", err)
473473
}
474474

475475
return vm, nil

pkg/crc/validation/validation.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ func ValidateDriver(driver string) error {
2121
return nil
2222
}
2323
}
24-
return errors.NewF("Unsupported driver: %s, use '--vm-driver' option to provide a supported driver %s\n", driver, machine.SupportedDriverValues())
24+
return errors.Newf("Unsupported driver: %s, use '--vm-driver' option to provide a supported driver %s\n", driver, machine.SupportedDriverValues())
2525
}
2626

2727
// ValidateCPUs checks if provided cpus count is valid
2828
func ValidateCPUs(value int) error {
2929
if value < constants.DefaultCPUs {
30-
return errors.NewF("CPUs required >=%d", constants.DefaultCPUs)
30+
return errors.Newf("CPUs required >=%d", constants.DefaultCPUs)
3131
}
3232
return nil
3333
}
3434

3535
// ValidateMemory checks if provided Memory count is valid
3636
func ValidateMemory(value int) error {
3737
if value < constants.DefaultMemory {
38-
return errors.NewF("Memory required >=%d", constants.DefaultMemory)
38+
return errors.Newf("Memory required >=%d", constants.DefaultMemory)
3939
}
4040
return nil
4141
}
@@ -49,7 +49,7 @@ func ValidateBundle(bundle string) error {
4949
releaseBundleVersion := version.GetBundleVersion()
5050
userProvidedBundleVersion := filepath.Base(bundle)
5151
if !strings.Contains(userProvidedBundleVersion, fmt.Sprintf("%s.crcbundle", releaseBundleVersion)) {
52-
return errors.NewF("%s bundle is not supported for this release use updated one (crc_<hypervisor>_%s.crcbundle)", userProvidedBundleVersion, releaseBundleVersion)
52+
return errors.Newf("%s bundle is not supported for this release use updated one (crc_<hypervisor>_%s.crcbundle)", userProvidedBundleVersion, releaseBundleVersion)
5353
}
5454
return nil
5555
}
@@ -58,15 +58,15 @@ func ValidateBundle(bundle string) error {
5858
func ValidateIpAddress(ipAddress string) error {
5959
ip := net.ParseIP(ipAddress).To4()
6060
if ip == nil {
61-
return errors.NewF("IPv4 address is not valid: '%s'", ipAddress)
61+
return errors.Newf("IPv4 address is not valid: '%s'", ipAddress)
6262
}
6363
return nil
6464
}
6565

6666
// ValidatePath check if provide path is exist
6767
func ValidatePath(path string) error {
6868
if _, err := os.Stat(path); os.IsNotExist(err) {
69-
return errors.NewF("File %s does not exist", path)
69+
return errors.Newf("File %s does not exist", path)
7070
}
7171
return nil
7272
}

pkg/download/download.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ func Download(uri, destination string) (string, error) {
1313
client := grab.NewClient()
1414
req, err := grab.NewRequest(destination, uri)
1515
if err != nil {
16-
return "", errors.NewF("Not able to get response from %s: %v", uri, err)
16+
return "", errors.Newf("Not able to get response from %s: %v", uri, err)
1717
}
1818
resp := client.Do(req)
1919
// check for errors
2020
if err := resp.Err(); err != nil {
21-
return "", errors.NewF("Download failed: %v\n", err)
21+
return "", errors.Newf("Download failed: %v\n", err)
2222
}
2323

2424
logging.Debugf("Download saved to %v \n", resp.Filename)

0 commit comments

Comments
 (0)