Skip to content

Commit 9fd82a9

Browse files
committed
Use errors.New instead of fmt.Errorf for plain strings.
This is what go-1.22 enforces. Signed-off-by: Kurt Garloff <kurt@garloff.de>
1 parent cdbcc97 commit 9fd82a9

File tree

4 files changed

+12
-12
lines changed

4 files changed

+12
-12
lines changed

pkg/clusterstack/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ func GetCsctlConfig(path string) (*CsctlConfig, error) {
5858
}
5959

6060
if cs.Config.Provider.Type == "" {
61-
return nil, fmt.Errorf("provider type must not be empty")
61+
return nil, errors.New("provider type must not be empty")
6262
}
6363

6464
if len(cs.Config.Provider.Type) > 253 {
65-
return nil, fmt.Errorf("provider name must not be greater than 253")
65+
return nil, errors.New("provider name must not be greater than 253")
6666
}
6767

6868
match, err := regexp.MatchString(`^[a-z0-9]([-a-z0-9]*[a-z0-9])?$`, cs.Config.Provider.Type)
@@ -74,7 +74,7 @@ func GetCsctlConfig(path string) (*CsctlConfig, error) {
7474
}
7575

7676
if cs.Config.ClusterStackName == "" {
77-
return nil, fmt.Errorf("cluster stack name must not be empty")
77+
return nil, errors.New("cluster stack name must not be empty")
7878
}
7979

8080
// Validate kubernetes version

pkg/clusterstack/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func BumpVersion(version string) (string, error) {
3030

3131
// Check if a numeric part was found
3232
if len(matches) < 2 {
33-
return "", fmt.Errorf("invalid version format")
33+
return "", errors.New("invalid version format")
3434
}
3535

3636
// Extract and convert the numeric part to an integer

pkg/cmd/create.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,13 @@ func GetCreateOptions(ctx context.Context, clusterStackPath string) (*CreateOpti
185185
}
186186
case customMode:
187187
if clusterStackVersion == "" {
188-
return nil, fmt.Errorf("please specify a semver for custom version with --cluster-stack-version flag")
188+
return nil, errors.New("please specify a semver for custom version with --cluster-stack-version flag")
189189
}
190190
if clusterAddonVersion == "" {
191-
return nil, fmt.Errorf("please specify a semver for custom version with --cluster-addon-version flag")
191+
return nil, errors.New("please specify a semver for custom version with --cluster-addon-version flag")
192192
}
193193
if nodeImageVersion == "" {
194-
return nil, fmt.Errorf("please specify a semver for custom version with --node-image-version flag")
194+
return nil, errors.New("please specify a semver for custom version with --node-image-version flag")
195195
}
196196

197197
createOption.Metadata, err = clusterstack.HandleCustomMode(createOption.Config.Config.KubernetesVersion, clusterStackVersion, clusterAddonVersion, nodeImageVersion)
@@ -222,7 +222,7 @@ func createAction(cmd *cobra.Command, args []string) error {
222222
defer cleanTmpDirectory()
223223

224224
if len(args) != 1 {
225-
return fmt.Errorf("please provide a valid command, create only accept one argument to path to the cluster stacks")
225+
return errors.New("please provide a valid command, create only accept one argument to path to the cluster stacks")
226226
}
227227
clusterStackPath := args[0]
228228

@@ -253,7 +253,7 @@ func (c *CreateOptions) validateHash() error {
253253
if c.CurrentReleaseHash.ClusterAddonDir == c.LatestReleaseHash.ClusterAddonDir &&
254254
c.CurrentReleaseHash.ClusterAddonValues == c.LatestReleaseHash.ClusterAddonValues &&
255255
c.CurrentReleaseHash.NodeImageDir == c.LatestReleaseHash.NodeImageDir {
256-
return fmt.Errorf("no change in the cluster stack")
256+
return errors.New("no change in the cluster stack")
257257
}
258258

259259
return nil
@@ -351,7 +351,7 @@ func (c *CreateOptions) generateRelease(ctx context.Context) error {
351351

352352
if publish {
353353
if remote != "oci" {
354-
return fmt.Errorf("not pushing assets. --publish is only implemented for remote OCI")
354+
return errors.New("not pushing assets. --publish is only implemented for remote OCI")
355355
}
356356

357357
ociClient, err := oci.NewClient()
@@ -410,7 +410,7 @@ func overwriteVersionInFile(chartYaml, newVersion string) error {
410410
v := m["version"]
411411
oldVersion, ok := v.(string)
412412
if !ok {
413-
return fmt.Errorf("failed to read version in yaml")
413+
return errors.New("failed to read version in yaml")
414414
}
415415

416416
m["version"] = newVersion

pkg/hash/hash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func (r ReleaseHash) ValidateWithLatestReleaseHash(latestReleaseHash ReleaseHash
111111
if r.ClusterAddonDir == latestReleaseHash.ClusterAddonDir &&
112112
r.ClusterAddonValues == latestReleaseHash.ClusterAddonValues &&
113113
r.NodeImageDir == latestReleaseHash.NodeImageDir {
114-
return fmt.Errorf("no change in the cluster stack")
114+
return errors.New("no change in the cluster stack")
115115
}
116116

117117
return nil

0 commit comments

Comments
 (0)