diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index ec0a863c8f9..71b59e592c1 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -36,7 +36,7 @@ jobs: - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: - version: v1.61 + version: v1.64 args: -v --exclude-dirs cf --exclude-dirs fixtures --exclude-dirs plugin --exclude-dirs command/plugin format: name: Run go fmt diff --git a/cf/actors/push.go b/cf/actors/push.go index 182e2b2f308..a034ed868d7 100644 --- a/cf/actors/push.go +++ b/cf/actors/push.go @@ -7,6 +7,8 @@ import ( "path/filepath" "runtime" + "errors" + "code.cloudfoundry.org/cli/cf/api/applicationbits" "code.cloudfoundry.org/cli/cf/api/resources" "code.cloudfoundry.org/cli/cf/appfiles" @@ -186,29 +188,29 @@ func (actor PushActorImpl) ValidateAppParams(apps []models.AppParams) []error { appName := app.Name if app.HealthCheckType != nil && *app.HealthCheckType != "http" && app.HealthCheckHTTPEndpoint != nil { - errs = append(errs, fmt.Errorf(T("Health check type must be 'http' to set a health check HTTP endpoint."))) + errs = append(errs, errors.New(T("Health check type must be 'http' to set a health check HTTP endpoint."))) } if app.Routes != nil { if app.Hosts != nil { - errs = append(errs, fmt.Errorf(T("Application {{.AppName}} must not be configured with both 'routes' and 'host'/'hosts'", map[string]interface{}{"AppName": appName}))) + errs = append(errs, errors.New(T("Application {{.AppName}} must not be configured with both 'routes' and 'host'/'hosts'", map[string]interface{}{"AppName": appName}))) } if app.Domains != nil { - errs = append(errs, fmt.Errorf(T("Application {{.AppName}} must not be configured with both 'routes' and 'domain'/'domains'", map[string]interface{}{"AppName": appName}))) + errs = append(errs, errors.New(T("Application {{.AppName}} must not be configured with both 'routes' and 'domain'/'domains'", map[string]interface{}{"AppName": appName}))) } if app.NoHostname != nil { - errs = append(errs, fmt.Errorf(T("Application {{.AppName}} must not be configured with both 'routes' and 'no-hostname'", map[string]interface{}{"AppName": appName}))) + errs = append(errs, errors.New(T("Application {{.AppName}} must not be configured with both 'routes' and 'no-hostname'", map[string]interface{}{"AppName": appName}))) } } if app.BuildpackURL != nil && app.DockerImage != nil { - errs = append(errs, fmt.Errorf(T("Application {{.AppName}} must not be configured with both 'buildpack' and 'docker'", map[string]interface{}{"AppName": appName}))) + errs = append(errs, errors.New(T("Application {{.AppName}} must not be configured with both 'buildpack' and 'docker'", map[string]interface{}{"AppName": appName}))) } if app.Path != nil && app.DockerImage != nil { - errs = append(errs, fmt.Errorf(T("Application {{.AppName}} must not be configured with both 'docker' and 'path'", map[string]interface{}{"AppName": appName}))) + errs = append(errs, errors.New(T("Application {{.AppName}} must not be configured with both 'docker' and 'path'", map[string]interface{}{"AppName": appName}))) } } diff --git a/cf/actors/routes.go b/cf/actors/routes.go index 0b360480504..70ad3e3d437 100644 --- a/cf/actors/routes.go +++ b/cf/actors/routes.go @@ -233,7 +233,7 @@ func (routeActor routeActor) FindAndBindRoute(routeName string, app models.Appli func validateRoute(routeName string, domainType string, port int, path string) error { if domainType == tcp && path != "" { - return fmt.Errorf(T("Path not allowed in TCP route {{.RouteName}}", + return errors.New(T("Path not allowed in TCP route {{.RouteName}}", map[string]interface{}{ "RouteName": routeName, }, @@ -241,7 +241,7 @@ func validateRoute(routeName string, domainType string, port int, path string) e } if domainType == "" && port != 0 { - return fmt.Errorf(T("Port not allowed in HTTP route {{.RouteName}}", + return errors.New(T("Port not allowed in HTTP route {{.RouteName}}", map[string]interface{}{ "RouteName": routeName, }, @@ -288,7 +288,7 @@ func parseRoute(routeName string, findFunc func(domainName string) (models.Domai return routeParts[0], domain, false, nil } - return "", models.DomainFields{}, true, fmt.Errorf(T( + return "", models.DomainFields{}, true, errors.New(T( "The route {{.RouteName}} did not match any existing domains.", map[string]interface{}{ "RouteName": routeName, diff --git a/cf/api/resources/events.go b/cf/api/resources/events.go index a94d520589e..133410ad6cf 100644 --- a/cf/api/resources/events.go +++ b/cf/api/resources/events.go @@ -57,12 +57,12 @@ func (resource EventResourceOldV2) ToFields() models.EventFields { GUID: resource.Metadata.GUID, Name: T("app crashed"), Timestamp: resource.Entity.Timestamp, - Description: fmt.Sprintf(T("instance: {{.InstanceIndex}}, reason: {{.ExitDescription}}, exit_status: {{.ExitStatus}}", + Description: T("instance: {{.InstanceIndex}}, reason: {{.ExitDescription}}, exit_status: {{.ExitStatus}}", map[string]interface{}{ "InstanceIndex": resource.Entity.InstanceIndex, "ExitDescription": resource.Entity.ExitDescription, "ExitStatus": strconv.Itoa(resource.Entity.ExitStatus), - })), + }), } } diff --git a/cf/api/stacks/stacks.go b/cf/api/stacks/stacks.go index 94c5136102c..e2085bf0405 100644 --- a/cf/api/stacks/stacks.go +++ b/cf/api/stacks/stacks.go @@ -41,7 +41,7 @@ func (repo CloudControllerStackRepository) FindByGUID(guid string) (models.Stack return models.Stack{}, errNotFound } - return models.Stack{}, fmt.Errorf(T("Error retrieving stacks: {{.Error}}", map[string]interface{}{ + return models.Stack{}, errors.New(T("Error retrieving stacks: {{.Error}}", map[string]interface{}{ "Error": err.Error(), })) } diff --git a/cf/api/users.go b/cf/api/users.go index bfe2c69520c..ab7069e4a9a 100644 --- a/cf/api/users.go +++ b/cf/api/users.go @@ -290,7 +290,7 @@ func userGUIDPath(apiEndpoint, userGUID, orgGUID string, role models.Role) (stri func (repo CloudControllerUserRepository) SetSpaceRoleByGUID(userGUID, spaceGUID, orgGUID string, role models.Role) error { rolePath, found := spaceRoleToPathMap[role] if !found { - return fmt.Errorf(T("Invalid Role {{.Role}}", map[string]interface{}{"Role": role})) + return errors.New(T("Invalid Role {{.Role}}", map[string]interface{}{"Role": role})) } err := repo.assocUserWithOrgByUserGUID(userGUID, orgGUID) @@ -330,7 +330,7 @@ func (repo CloudControllerUserRepository) SetSpaceRoleByUsername(username, space func (repo CloudControllerUserRepository) UnsetSpaceRoleByGUID(userGUID, spaceGUID string, role models.Role) error { rolePath, found := spaceRoleToPathMap[role] if !found { - return fmt.Errorf(T("Invalid Role {{.Role}}", map[string]interface{}{"Role": role})) + return errors.New(T("Invalid Role {{.Role}}", map[string]interface{}{"Role": role})) } apiURL := fmt.Sprintf("/v2/spaces/%s/%s/%s", spaceGUID, rolePath, userGUID) @@ -343,7 +343,7 @@ func (repo CloudControllerUserRepository) checkSpaceRole(spaceGUID string, role rolePath, found := spaceRoleToPathMap[role] if !found { - apiErr = fmt.Errorf(T("Invalid Role {{.Role}}", + apiErr = errors.New(T("Invalid Role {{.Role}}", map[string]interface{}{"Role": role})) } @@ -373,7 +373,7 @@ func rolePath(role models.Role) (string, error) { path, found := orgRoleToPathMap[role] if !found { - return "", fmt.Errorf(T("Invalid Role {{.Role}}", + return "", errors.New(T("Invalid Role {{.Role}}", map[string]interface{}{"Role": role})) } return path, nil diff --git a/cf/commandregistry/registry.go b/cf/commandregistry/registry.go index 2b7ee3cbf7f..ea0152dbca8 100644 --- a/cf/commandregistry/registry.go +++ b/cf/commandregistry/registry.go @@ -35,9 +35,10 @@ func initI18nFunc() bool { T = Init(config) if err != nil { - fmt.Fprintf(os.Stderr, fmt.Sprintf("%s\n", T(configErrTemplate, map[string]interface{}{ + msg := T(configErrTemplate, map[string]interface{}{ "FilePath": configv3.ConfigFilePath(), - }))) + }) + fmt.Fprintf(os.Stderr, "%s\n", msg) } return true } diff --git a/cf/commands/api.go b/cf/commands/api.go index 8c448835745..e793f95505b 100644 --- a/cf/commands/api.go +++ b/cf/commands/api.go @@ -61,8 +61,8 @@ func (cmd API) Execute(c flags.FlagContext) error { } else if len(c.Args()) == 0 { if cmd.config.APIEndpoint() == "" { - cmd.ui.Say(fmt.Sprintf(T("No api endpoint set. Use '{{.Name}}' to set an endpoint", - map[string]interface{}{"Name": terminal.CommandColor(cf.Name + " api")}))) + cmd.ui.Say(T("No api endpoint set. Use '{{.Name}}' to set an endpoint", + map[string]interface{}{"Name": terminal.CommandColor(cf.Name + " api")})) } else { cmd.ui.Say(T("API endpoint: {{.APIEndpoint}} (API version: {{.APIVersion}})", map[string]interface{}{"APIEndpoint": terminal.EntityNameColor(cmd.config.APIEndpoint()), @@ -106,8 +106,8 @@ func (cmd API) setAPIEndpoint(endpoint string, skipSSL bool, cmdName string) err switch typedErr := err.(type) { case *errors.InvalidSSLCert: cfAPICommand := terminal.CommandColor(fmt.Sprintf("%s %s --skip-ssl-validation", cf.Name, cmdName)) - tipMessage := fmt.Sprintf(T("TIP: Use '{{.APICommand}}' to continue with an insecure API endpoint", - map[string]interface{}{"APICommand": cfAPICommand})) + tipMessage := T("TIP: Use '{{.APICommand}}' to continue with an insecure API endpoint", + map[string]interface{}{"APICommand": cfAPICommand}) return errors.New(T("Invalid SSL Cert for {{.URL}}\n{{.TipMessage}}", map[string]interface{}{"URL": typedErr.URL, "TipMessage": tipMessage})) default: diff --git a/cf/commands/application/app.go b/cf/commands/application/app.go index de7ef2e8797..23871975ad1 100644 --- a/cf/commands/application/app.go +++ b/cf/commands/application/app.go @@ -183,15 +183,15 @@ func (cmd *ShowApp) ShowApp(app models.Application, orgName, spaceName string) e uihelpers.ColoredInstanceState(instance), instance.Since.Format("2006-01-02 03:04:05 PM"), fmt.Sprintf("%.1f%%", instance.CPUUsage*100), - fmt.Sprintf(T("{{.MemUsage}} of {{.MemQuota}}", + T("{{.MemUsage}} of {{.MemQuota}}", map[string]interface{}{ "MemUsage": formatters.ByteSize(instance.MemUsage), - "MemQuota": formatters.ByteSize(instance.MemQuota)})), - fmt.Sprintf(T("{{.DiskUsage}} of {{.DiskQuota}}", + "MemQuota": formatters.ByteSize(instance.MemQuota)}), + T("{{.DiskUsage}} of {{.DiskQuota}}", map[string]interface{}{ "DiskUsage": formatters.ByteSize(instance.DiskUsage), - "DiskQuota": formatters.ByteSize(instance.DiskQuota)})), - fmt.Sprintf("%s", instance.Details), + "DiskQuota": formatters.ByteSize(instance.DiskQuota)}), + instance.Details, ) } diff --git a/cf/commands/application/copy_source.go b/cf/commands/application/copy_source.go index a5c9b286bd5..8b591a03210 100644 --- a/cf/commands/application/copy_source.go +++ b/cf/commands/application/copy_source.go @@ -2,7 +2,6 @@ package application import ( "errors" - "fmt" "strings" "code.cloudfoundry.org/cli/cf/api/applications" @@ -171,7 +170,7 @@ func (cmd *CopySource) findSpaceFields(targetOrg, targetSpace string) (models.Sp } if !foundSpace { - return models.SpaceFields{}, fmt.Errorf(T("Could not find space {{.Space}} in organization {{.Org}}", + return models.SpaceFields{}, errors.New(T("Could not find space {{.Space}} in organization {{.Org}}", map[string]interface{}{ "Space": terminal.EntityNameColor(targetSpace), "Org": terminal.EntityNameColor(targetOrg), @@ -183,7 +182,7 @@ func (cmd *CopySource) findSpaceFields(targetOrg, targetSpace string) (models.Sp } func buildCopyString(sourceAppName, targetAppName, targetOrgName, targetSpaceName, username string) string { - return fmt.Sprintf(T("Copying source from app {{.SourceApp}} to target app {{.TargetApp}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", + return T("Copying source from app {{.SourceApp}} to target app {{.TargetApp}} in org {{.OrgName}} / space {{.SpaceName}} as {{.Username}}...", map[string]interface{}{ "SourceApp": terminal.EntityNameColor(sourceAppName), "TargetApp": terminal.EntityNameColor(targetAppName), @@ -191,6 +190,6 @@ func buildCopyString(sourceAppName, targetAppName, targetOrgName, targetSpaceNam "SpaceName": terminal.EntityNameColor(targetSpaceName), "Username": terminal.EntityNameColor(username), }, - )) + ) } diff --git a/cf/commands/application/push.go b/cf/commands/application/push.go index 8c48a7839a3..1b5d023bca6 100644 --- a/cf/commands/application/push.go +++ b/cf/commands/application/push.go @@ -784,7 +784,7 @@ func (cmd *Push) getAppParamsFromContext(c flags.FlagContext) (models.AppParams, if c.String("t") != "" { timeout, err := strconv.Atoi(c.String("t")) if err != nil { - return models.AppParams{}, fmt.Errorf("Error: %s", fmt.Errorf(T("Invalid timeout param: {{.Timeout}}\n{{.Err}}", + return models.AppParams{}, fmt.Errorf("Error: %s", errors.New(T("Invalid timeout param: {{.Timeout}}\n{{.Err}}", map[string]interface{}{"Timeout": c.String("t"), "Err": err.Error()}))) } @@ -798,7 +798,7 @@ func (cmd *Push) getAppParamsFromContext(c flags.FlagContext) (models.AppParams, case "http", "none", "port", "process": appParams.HealthCheckType = &healthCheckType default: - return models.AppParams{}, fmt.Errorf("Error: %s", fmt.Errorf(T("Invalid health-check-type param: {{.healthCheckType}}", + return models.AppParams{}, fmt.Errorf("Error: %s", errors.New(T("Invalid health-check-type param: {{.healthCheckType}}", map[string]interface{}{"healthCheckType": healthCheckType}))) } diff --git a/cf/commands/application/ssh.go b/cf/commands/application/ssh.go index f2a8e24481b..747ec3bdcf3 100644 --- a/cf/commands/application/ssh.go +++ b/cf/commands/application/ssh.go @@ -107,10 +107,10 @@ func (cmd *SSH) Execute(fc flags.FlagContext) error { if fc.IsSet("i") { instanceIndex := fc.Int("i") if instanceIndex < 0 { - return fmt.Errorf(T("The application instance index cannot be negative")) + return errors.New(T("The application instance index cannot be negative")) } if instanceIndex >= cmd.appReq.GetApplication().InstanceCount { - return fmt.Errorf(T("The specified application instance does not exist")) + return errors.New(T("The specified application instance does not exist")) } } diff --git a/cf/commands/application/start.go b/cf/commands/application/start.go index ee78184b8ee..7d6b95d1b60 100644 --- a/cf/commands/application/start.go +++ b/cf/commands/application/start.go @@ -340,7 +340,7 @@ func (cmd *Start) waitForOneRunningInstance(app models.Application) error { } if count.flapping > 0 || count.crashed > 0 { - return fmt.Errorf(T("Start unsuccessful\n\nTIP: use '{{.Command}}' for more information", + return errors.New(T("Start unsuccessful\n\nTIP: use '{{.Command}}' for more information", map[string]interface{}{"Command": terminal.CommandColor(fmt.Sprintf("%s logs %s --recent", cf.Name, app.Name))})) } @@ -393,40 +393,40 @@ func (cmd Start) fetchInstanceCount(appGUID string) (instanceCount, error) { } func instancesDetails(count instanceCount) string { - details := []string{fmt.Sprintf(T("{{.RunningCount}} of {{.TotalCount}} instances running", - map[string]interface{}{"RunningCount": count.running, "TotalCount": count.total}))} + details := []string{T("{{.RunningCount}} of {{.TotalCount}} instances running", + map[string]interface{}{"RunningCount": count.running, "TotalCount": count.total})} if count.starting > 0 { if len(count.startingDetails) == 0 { - details = append(details, fmt.Sprintf(T("{{.StartingCount}} starting", - map[string]interface{}{"StartingCount": count.starting}))) + details = append(details, T("{{.StartingCount}} starting", + map[string]interface{}{"StartingCount": count.starting})) } else { info := []string{} for d := range count.startingDetails { info = append(info, d) } sort.Strings(info) - details = append(details, fmt.Sprintf(T("{{.StartingCount}} starting ({{.Details}})", + details = append(details, T("{{.StartingCount}} starting ({{.Details}})", map[string]interface{}{ "StartingCount": count.starting, "Details": strings.Join(info, ", "), - }))) + })) } } if count.down > 0 { - details = append(details, fmt.Sprintf(T("{{.DownCount}} down", - map[string]interface{}{"DownCount": count.down}))) + details = append(details, T("{{.DownCount}} down", + map[string]interface{}{"DownCount": count.down})) } if count.flapping > 0 { - details = append(details, fmt.Sprintf(T("{{.FlappingCount}} failing", - map[string]interface{}{"FlappingCount": count.flapping}))) + details = append(details, T("{{.FlappingCount}} failing", + map[string]interface{}{"FlappingCount": count.flapping})) } if count.crashed > 0 { - details = append(details, fmt.Sprintf(T("{{.CrashedCount}} crashed", - map[string]interface{}{"CrashedCount": count.crashed}))) + details = append(details, T("{{.CrashedCount}} crashed", + map[string]interface{}{"CrashedCount": count.crashed})) } return strings.Join(details, ", ") diff --git a/cf/commands/buildpack/create_buildpack.go b/cf/commands/buildpack/create_buildpack.go index b04eceb9f05..4b0bb5e3fc5 100644 --- a/cf/commands/buildpack/create_buildpack.go +++ b/cf/commands/buildpack/create_buildpack.go @@ -115,7 +115,7 @@ func (cmd *CreateBuildpack) Execute(c flags.FlagContext) error { func (cmd CreateBuildpack) createBuildpack(buildpackName string, c flags.FlagContext) (buildpack models.Buildpack, apiErr error) { position, err := strconv.Atoi(c.Args()[2]) if err != nil { - apiErr = fmt.Errorf(T("Error {{.ErrorDescription}} is being passed in as the argument for 'Position' but 'Position' requires an integer. For more syntax help, see `cf create-buildpack -h`.", map[string]interface{}{"ErrorDescription": c.Args()[2]})) + apiErr = errors.New(T("Error {{.ErrorDescription}} is being passed in as the argument for 'Position' but 'Position' requires an integer. For more syntax help, see `cf create-buildpack -h`.", map[string]interface{}{"ErrorDescription": c.Args()[2]})) return } diff --git a/cf/commands/serviceaccess/service_access.go b/cf/commands/serviceaccess/service_access.go index 0a3ecf62897..4f774c61622 100644 --- a/cf/commands/serviceaccess/service_access.go +++ b/cf/commands/serviceaccess/service_access.go @@ -1,7 +1,6 @@ package serviceaccess import ( - "fmt" "strings" "code.cloudfoundry.org/cli/cf/actors" @@ -124,7 +123,7 @@ func (cmd *ServiceAccess) Execute(c flags.FlagContext) error { func (cmd ServiceAccess) printTable(brokers []models.ServiceBroker) error { for _, serviceBroker := range brokers { - cmd.ui.Say(fmt.Sprintf(T("broker: {{.Name}}", map[string]interface{}{"Name": serviceBroker.Name}))) + cmd.ui.Say(T("broker: {{.Name}}", map[string]interface{}{"Name": serviceBroker.Name})) table := cmd.ui.Table([]string{"", T("service"), T("plan"), T("access"), T("orgs")}) for _, service := range serviceBroker.Services { diff --git a/cf/commands/target.go b/cf/commands/target.go index 107ddb96fae..90ef8fed1bd 100644 --- a/cf/commands/target.go +++ b/cf/commands/target.go @@ -111,7 +111,7 @@ func (cmd Target) setOrganization(orgName string) error { org, apiErr := cmd.orgRepo.FindByName(orgName) if apiErr != nil { - return fmt.Errorf(T("Could not target org.\n{{.APIErr}}", + return errors.New(T("Could not target org.\n{{.APIErr}}", map[string]interface{}{"APIErr": apiErr.Error()})) } @@ -128,7 +128,7 @@ func (cmd Target) setSpace(spaceName string) error { space, apiErr := cmd.spaceRepo.FindByName(spaceName) if apiErr != nil { - return fmt.Errorf(T("Unable to access space {{.SpaceName}}.\n{{.APIErr}}", + return errors.New(T("Unable to access space {{.SpaceName}}.\n{{.APIErr}}", map[string]interface{}{"SpaceName": spaceName, "APIErr": apiErr.Error()})) } diff --git a/cf/commands/user/delete_user.go b/cf/commands/user/delete_user.go index 2d5dbd16855..aee07d64c96 100644 --- a/cf/commands/user/delete_user.go +++ b/cf/commands/user/delete_user.go @@ -76,7 +76,7 @@ func (cmd *DeleteUser) Execute(c flags.FlagContext) error { switch err.(type) { case nil: if len(users) > 1 { - return fmt.Errorf(T( + return errors.New(T( "Error deleting user {{.Username}} \nThe user exists in multiple origins.", map[string]interface{}{ "Username": username, diff --git a/cf/manifest/generate_manifest.go b/cf/manifest/generate_manifest.go index 6a8a9eb68c4..9954accadd1 100644 --- a/cf/manifest/generate_manifest.go +++ b/cf/manifest/generate_manifest.go @@ -194,7 +194,7 @@ func (m *appManifest) Save(f io.Writer) error { for _, app := range m.contents { appMap, mapErr := generateAppMap(app) if mapErr != nil { - return fmt.Errorf(T("Error saving manifest: {{.Error}}", map[string]interface{}{ + return errors.New(T("Error saving manifest: {{.Error}}", map[string]interface{}{ "Error": mapErr.Error(), })) } diff --git a/cf/manifest/manifest.go b/cf/manifest/manifest.go index 4d959ae5a06..87ef7a19891 100644 --- a/cf/manifest/manifest.go +++ b/cf/manifest/manifest.go @@ -72,7 +72,7 @@ func (m Manifest) getAppMaps(data generic.Map) ([]generic.Map, error) { for _, appData := range appMaps { if !generic.IsMappable(appData) { - errs = append(errs, fmt.Errorf(T("Expected application to be a list of key/value pairs\nError occurred in manifest near:\n'{{.YmlSnippet}}'", + errs = append(errs, errors.New(T("Expected application to be a list of key/value pairs\nError occurred in manifest near:\n'{{.YmlSnippet}}'", map[string]interface{}{"YmlSnippet": appData}))) continue } @@ -214,7 +214,7 @@ func mapToAppParams(basePath string, yamlMap generic.Map) (models.AppParams, err } if len(appParams.Buildpacks) > 0 { - errs = append(errs, fmt.Errorf(T("The following manifest fields cannot be used with legacy push: {{.fields}}", + errs = append(errs, errors.New(T("The following manifest fields cannot be used with legacy push: {{.fields}}", map[string]interface{}{ "fields": "buildpacks", }))) @@ -258,7 +258,7 @@ func checkForNulls(yamlMap generic.Map) error { return } if value == nil { - errs = append(errs, fmt.Errorf(T("{{.PropertyName}} should not be null", map[string]interface{}{"PropertyName": key}))) + errs = append(errs, errors.New(T("{{.PropertyName}} should not be null", map[string]interface{}{"PropertyName": key}))) } }) @@ -280,7 +280,7 @@ func stringVal(yamlMap generic.Map, key string, errs *[]error) *string { } result, ok := val.(string) if !ok { - *errs = append(*errs, fmt.Errorf(T("{{.PropertyName}} must be a string value", map[string]interface{}{"PropertyName": key}))) + *errs = append(*errs, errors.New(T("{{.PropertyName}} must be a string value", map[string]interface{}{"PropertyName": key}))) return nil } return &result @@ -300,7 +300,7 @@ func stringValOrDefault(yamlMap generic.Map, key string, errs *[]error) *string case nil: return &empty default: - *errs = append(*errs, fmt.Errorf(T("{{.PropertyName}} must be a string or null value", map[string]interface{}{"PropertyName": key}))) + *errs = append(*errs, errors.New(T("{{.PropertyName}} must be a string or null value", map[string]interface{}{"PropertyName": key}))) return nil } } @@ -314,7 +314,7 @@ func bytesVal(yamlMap generic.Map, key string, errs *[]error) *int64 { stringVal := coerceToString(yamlVal) value, err := formatters.ToMegabytes(stringVal) if err != nil { - *errs = append(*errs, fmt.Errorf(T("Invalid value for '{{.PropertyName}}': {{.StringVal}}\n{{.Error}}", + *errs = append(*errs, errors.New(T("Invalid value for '{{.PropertyName}}': {{.StringVal}}\n{{.Error}}", map[string]interface{}{ "PropertyName": key, "Error": err.Error(), @@ -341,7 +341,7 @@ func intVal(yamlMap generic.Map, key string, errs *[]error) *int { case nil: return nil default: - err = fmt.Errorf(T("Expected {{.PropertyName}} to be a number, but it was a {{.PropertyType}}.", + err = errors.New(T("Expected {{.PropertyName}} to be a number, but it was a {{.PropertyType}}.", map[string]interface{}{"PropertyName": key, "PropertyType": val})) } @@ -366,7 +366,7 @@ func boolVal(yamlMap generic.Map, key string, errs *[]error) bool { case string: return val == "true" default: - *errs = append(*errs, fmt.Errorf(T("Expected {{.PropertyName}} to be a boolean.", map[string]interface{}{"PropertyName": key}))) + *errs = append(*errs, errors.New(T("Expected {{.PropertyName}} to be a boolean.", map[string]interface{}{"PropertyName": key}))) return false } } @@ -382,7 +382,7 @@ func boolOrNil(yamlMap generic.Map, key string, errs *[]error) *bool { result = val == "true" return &result default: - *errs = append(*errs, fmt.Errorf(T("Expected {{.PropertyName}} to be a boolean.", map[string]interface{}{"PropertyName": key}))) + *errs = append(*errs, errors.New(T("Expected {{.PropertyName}} to be a boolean.", map[string]interface{}{"PropertyName": key}))) return &result } } @@ -394,7 +394,7 @@ func sliceOrNil(yamlMap generic.Map, key string, errs *[]error) []string { var err error stringSlice := []string{} - sliceErr := fmt.Errorf(T("Expected {{.PropertyName}} to be a list of strings.", map[string]interface{}{"PropertyName": key})) + sliceErr := errors.New(T("Expected {{.PropertyName}} to be a list of strings.", map[string]interface{}{"PropertyName": key})) switch input := yamlMap.Get(key).(type) { case []interface{}: @@ -444,7 +444,7 @@ func envVarOrEmptyMap(yamlMap generic.Map, errs *[]error) *map[string]interface{ return &result default: - *errs = append(*errs, fmt.Errorf(T("Expected {{.Name}} to be a set of key => value, but it was a {{.Type}}.", + *errs = append(*errs, errors.New(T("Expected {{.Name}} to be a set of key => value, but it was a {{.Type}}.", map[string]interface{}{"Name": key, "Type": envVars}))) return nil } @@ -453,7 +453,7 @@ func envVarOrEmptyMap(yamlMap generic.Map, errs *[]error) *map[string]interface{ func validateEnvVars(input generic.Map) (errs []error) { generic.Each(input, func(key, value interface{}) { if value == nil { - errs = append(errs, fmt.Errorf(T("env var '{{.PropertyName}}' should not be null", + errs = append(errs, errors.New(T("env var '{{.PropertyName}}' should not be null", map[string]interface{}{"PropertyName": key}))) } }) @@ -475,7 +475,7 @@ func parseRoutes(input generic.Map, errs *[]error) []models.ManifestRoute { genericRoutes, ok := input.Get("routes").([]interface{}) if !ok { - *errs = append(*errs, fmt.Errorf(T("'routes' should be a list"))) + *errs = append(*errs, errors.New(T("'routes' should be a list"))) return nil } @@ -483,7 +483,7 @@ func parseRoutes(input generic.Map, errs *[]error) []models.ManifestRoute { for _, genericRoute := range genericRoutes { route, ok := genericRoute.(map[interface{}]interface{}) if !ok { - *errs = append(*errs, fmt.Errorf(T("each route in 'routes' must have a 'route' property"))) + *errs = append(*errs, errors.New(T("each route in 'routes' must have a 'route' property"))) continue } @@ -492,7 +492,7 @@ func parseRoutes(input generic.Map, errs *[]error) []models.ManifestRoute { Route: routeVal.(string), }) } else { - *errs = append(*errs, fmt.Errorf(T("each route in 'routes' must have a 'route' property"))) + *errs = append(*errs, errors.New(T("each route in 'routes' must have a 'route' property"))) } } @@ -511,7 +511,7 @@ func parseDocker(input generic.Map, errs *[]error) models.ManifestDocker { var ok bool imageValue, ok = dockerMap.Get("image").(string) if !ok { - *errs = append(*errs, fmt.Errorf(T("'docker.image' must be a string"))) + *errs = append(*errs, errors.New(T("'docker.image' must be a string"))) return models.ManifestDocker{} } } @@ -521,7 +521,7 @@ func parseDocker(input generic.Map, errs *[]error) models.ManifestDocker { var ok bool usernameValue, ok = dockerMap.Get("username").(string) if !ok { - *errs = append(*errs, fmt.Errorf(T("'docker.username' must be a string"))) + *errs = append(*errs, errors.New(T("'docker.username' must be a string"))) return models.ManifestDocker{} } } diff --git a/cf/net/warnings_collector.go b/cf/net/warnings_collector.go index 0ae16613dcd..8438de7fccd 100644 --- a/cf/net/warnings_collector.go +++ b/cf/net/warnings_collector.go @@ -1,10 +1,11 @@ package net import ( - "fmt" "os" "strings" + "errors" + "code.cloudfoundry.org/cli/cf/terminal" ) @@ -41,7 +42,7 @@ func (warningsCollector WarningsCollector) PrintWarnings() error { if os.Getenv("CF_RAISE_ERROR_ON_WARNINGS") != "" { if len(warnings) > 0 { - return fmt.Errorf(strings.Join(warnings, "\n")) + return errors.New(strings.Join(warnings, "\n")) } } diff --git a/cf/requirements/targeted_organization.go b/cf/requirements/targeted_organization.go index adf4469ecf6..75a99ce3676 100644 --- a/cf/requirements/targeted_organization.go +++ b/cf/requirements/targeted_organization.go @@ -2,7 +2,6 @@ package requirements import ( "errors" - "fmt" "code.cloudfoundry.org/cli/cf" "code.cloudfoundry.org/cli/cf/configuration/coreconfig" @@ -28,7 +27,7 @@ func NewTargetedOrgRequirement(config coreconfig.Reader) TargetedOrgRequirement func (req targetedOrgAPIRequirement) Execute() error { if !req.config.HasOrganization() { - message := fmt.Sprintf(T("No org targeted, use '{{.Command}}' to target an org.", map[string]interface{}{"Command": terminal.CommandColor(cf.Name + " target -o ORG")})) + message := T("No org targeted, use '{{.Command}}' to target an org.", map[string]interface{}{"Command": terminal.CommandColor(cf.Name + " target -o ORG")}) return errors.New(message) } diff --git a/cf/requirements/targeted_space.go b/cf/requirements/targeted_space.go index 7f0bc55bba1..1d1d0da76eb 100644 --- a/cf/requirements/targeted_space.go +++ b/cf/requirements/targeted_space.go @@ -1,8 +1,6 @@ package requirements import ( - "fmt" - "errors" "code.cloudfoundry.org/cli/cf" @@ -21,12 +19,12 @@ func NewTargetedSpaceRequirement(config coreconfig.Reader) TargetedSpaceRequirem func (req TargetedSpaceRequirement) Execute() error { if !req.config.HasOrganization() { - message := fmt.Sprintf(T("No org and space targeted, use '{{.Command}}' to target an org and space", map[string]interface{}{"Command": terminal.CommandColor(cf.Name + " target -o ORG -s SPACE")})) + message := T("No org and space targeted, use '{{.Command}}' to target an org and space", map[string]interface{}{"Command": terminal.CommandColor(cf.Name + " target -o ORG -s SPACE")}) return errors.New(message) } if !req.config.HasSpace() { - message := fmt.Sprintf(T("No space targeted, use '{{.Command}}' to target a space.", map[string]interface{}{"Command": terminal.CommandColor("cf target -s")})) + message := T("No space targeted, use '{{.Command}}' to target a space.", map[string]interface{}{"Command": terminal.CommandColor("cf target -s")}) return errors.New(message) } diff --git a/cf/terminal/ui.go b/cf/terminal/ui.go index 18df1937bd6..21ea68b774f 100644 --- a/cf/terminal/ui.go +++ b/cf/terminal/ui.go @@ -19,8 +19,8 @@ import ( type ColoringFunction func(value string, row int, col int) string func NotLoggedInText() string { - return fmt.Sprintf(T("Not logged in. Use '{{.CFLoginCommand}}' or '{{.CFLoginCommandSSO}}' to log in.", map[string]interface{}{"CFLoginCommand": CommandColor(cf.Name + " " + "login"), - "CFLoginCommandSSO": CommandColor(cf.Name + " " + "login --sso")})) + return T("Not logged in. Use '{{.CFLoginCommand}}' or '{{.CFLoginCommandSSO}}' to log in.", map[string]interface{}{"CFLoginCommand": CommandColor(cf.Name + " " + "login"), + "CFLoginCommandSSO": CommandColor(cf.Name + " " + "login --sso")}) } //go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 . UI diff --git a/cf/terminal/ui_unix.go b/cf/terminal/ui_unix.go index 08ccdfbdd4a..2d37918fd21 100644 --- a/cf/terminal/ui_unix.go +++ b/cf/terminal/ui_unix.go @@ -7,6 +7,7 @@ package terminal import ( "bufio" + "errors" "fmt" "os" "os/signal" @@ -73,7 +74,7 @@ func echoOff(fd []uintptr) (int, error) { pid, err := syscall.ForkExec(sttyArg0, sttyArgvEOff, &syscall.ProcAttr{Dir: execCWDir, Files: fd}) if err != nil { - return 0, fmt.Errorf(T("failed turning off console echo for password entry:\n{{.ErrorDescription}}", map[string]interface{}{"ErrorDescription": err})) + return 0, errors.New(T("failed turning off console echo for password entry:\n{{.ErrorDescription}}", map[string]interface{}{"ErrorDescription": err})) } return pid, nil diff --git a/go.mod b/go.mod index 30690486a75..b87ce2c9391 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module code.cloudfoundry.org/cli -go 1.23.6 +go 1.24.3 require ( code.cloudfoundry.org/bytefmt v0.36.0