当前位置: 首页>>代码示例>>Golang>>正文


Golang errors.NewErrorWithMessage函数代码示例

本文整理汇总了Golang中cf/errors.NewErrorWithMessage函数的典型用法代码示例。如果您正苦于以下问题:Golang NewErrorWithMessage函数的具体用法?Golang NewErrorWithMessage怎么用?Golang NewErrorWithMessage使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewErrorWithMessage函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: createBuildpack

func (cmd CreateBuildpack) createBuildpack(buildpackName string, c *cli.Context) (buildpack models.Buildpack, apiErr errors.Error) {
	position, err := strconv.Atoi(c.Args()[2])
	if err != nil {
		apiErr = errors.NewErrorWithMessage("Invalid position. %s", err.Error())
		return
	}

	enabled := c.Bool("enable")
	disabled := c.Bool("disable")
	if enabled && disabled {
		apiErr = errors.NewErrorWithMessage("Cannot specify both enabled and disabled.")
		return
	}

	var enableOption *bool = nil
	if enabled {
		enableOption = &enabled
	}
	if disabled {
		disabled = false
		enableOption = &disabled
	}

	buildpack, apiErr = cmd.buildpackRepo.Create(buildpackName, &position, enableOption, nil)

	return
}
开发者ID:knolleary,项目名称:cli,代码行数:27,代码来源:create_buildpack.go

示例2: UploadApp

func (repo CloudControllerApplicationBitsRepository) UploadApp(appGuid string, appDir string, cb func(path string, zipSize, fileCount uint64)) (apiErr errors.Error) {
	fileutils.TempDir("apps", func(uploadDir string, err error) {
		if err != nil {
			apiErr = errors.NewErrorWithMessage(err.Error())
			return
		}

		var presentResourcesJson []byte
		repo.sourceDir(appDir, func(sourceDir string, sourceErr error) {
			if sourceErr != nil {
				err = sourceErr
				return
			}
			presentResourcesJson, err = repo.copyUploadableFiles(sourceDir, uploadDir)
		})

		if err != nil {
			apiErr = errors.NewErrorWithMessage("%s", err)
			return
		}

		fileutils.TempFile("uploads", func(zipFile *os.File, err error) {
			if err != nil {
				apiErr = errors.NewErrorWithMessage("%s", err.Error())
				return
			}

			err = repo.zipper.Zip(uploadDir, zipFile)
			if err != nil {
				apiErr = errors.NewErrorWithError("Error zipping application", err)
				return
			}

			stat, err := zipFile.Stat()
			if err != nil {
				apiErr = errors.NewErrorWithError("Error zipping application", err)
				return
			}
			cb(appDir, uint64(stat.Size()), app_files.CountFiles(uploadDir))

			apiErr = repo.uploadBits(appGuid, zipFile, presentResourcesJson)
			if apiErr != nil {
				return
			}
		})
	})
	return
}
开发者ID:knolleary,项目名称:cli,代码行数:48,代码来源:application_bits.go

示例3: getAuthEndpoint

func (repo CloudControllerUserRepository) getAuthEndpoint() (string, errors.Error) {
	uaaEndpoint := repo.config.UaaEndpoint()
	if uaaEndpoint == "" {
		return "", errors.NewErrorWithMessage("UAA endpoint missing from config file")
	}
	return uaaEndpoint, nil
}
开发者ID:knolleary,项目名称:cli,代码行数:7,代码来源:users.go

示例4: waitForJob

func (gateway Gateway) waitForJob(jobUrl, accessToken string, timeout time.Duration) (apiErr errors.Error) {
	startTime := time.Now()
	for true {
		if time.Since(startTime) > timeout {
			apiErr = errors.NewErrorWithMessage("Error: timed out waiting for async job '%s' to finish", jobUrl)
			return
		}

		var request *Request
		request, apiErr = gateway.NewRequest("GET", jobUrl, accessToken, nil)
		response := &JobResponse{}

		_, apiErr = gateway.PerformRequestForJSONResponse(request, response)
		if apiErr != nil {
			return
		}

		switch response.Entity.Status {
		case JOB_FINISHED:
			return
		case JOB_FAILED:
			apiErr = errors.NewError("Job failed", JOB_FAILED)
			return
		}

		accessToken = request.HttpReq.Header.Get("Authorization")

		time.Sleep(gateway.PollingThrottle)
	}
	return
}
开发者ID:knolleary,项目名称:cli,代码行数:31,代码来源:gateway.go

示例5: DeleteService

func (repo CloudControllerServiceRepository) DeleteService(instance models.ServiceInstance) (apiErr errors.Error) {
	if len(instance.ServiceBindings) > 0 {
		return errors.NewErrorWithMessage("Cannot delete service instance, apps are still bound to it")
	}
	path := fmt.Sprintf("%s/v2/service_instances/%s", repo.config.ApiEndpoint(), instance.Guid)
	return repo.gateway.DeleteResource(path, repo.config.AccessToken())
}
开发者ID:knolleary,项目名称:cli,代码行数:7,代码来源:services.go

示例6: UploadBuildpack

func (repo *FakeBuildpackBitsRepository) UploadBuildpack(buildpack models.Buildpack, dir string) errors.Error {
	if repo.UploadBuildpackErr {
		return errors.NewErrorWithMessage("Invalid buildpack")
	}

	repo.UploadBuildpackPath = dir
	return repo.UploadBuildpackApiResponse
}
开发者ID:knolleary,项目名称:cli,代码行数:8,代码来源:fake_buildpack_bits_repo.go

示例7: GetCloudControllerEndpoint

func (repo RemoteEndpointRepository) GetCloudControllerEndpoint() (endpoint string, apiErr errors.Error) {
	if repo.config.ApiEndpoint() == "" {
		apiErr = errors.NewErrorWithMessage("Target endpoint missing from config file")
		return
	}

	endpoint = repo.config.ApiEndpoint()
	return
}
开发者ID:jibin-tomy,项目名称:cli,代码行数:9,代码来源:endpoints.go

示例8: Update

func (repo *FakeApplicationRepository) Update(appGuid string, params models.AppParams) (updatedApp models.Application, apiErr errors.Error) {
	repo.UpdateAppGuid = appGuid
	repo.UpdateParams = params
	updatedApp = repo.UpdateAppResult
	if repo.UpdateErr {
		apiErr = errors.NewErrorWithMessage("Error updating app.")
	}
	return
}
开发者ID:knolleary,项目名称:cli,代码行数:9,代码来源:fake_app_repo.go

示例9: GetUAAEndpoint

func (repo RemoteEndpointRepository) GetUAAEndpoint() (endpoint string, apiErr errors.Error) {
	if repo.config.AuthorizationEndpoint() == "" {
		apiErr = errors.NewErrorWithMessage("UAA endpoint missing from config file")
		return
	}

	endpoint = strings.Replace(repo.config.AuthorizationEndpoint(), "login", "uaa", 1)

	return
}
开发者ID:jibin-tomy,项目名称:cli,代码行数:10,代码来源:endpoints.go

示例10: FindByHost

func (repo *FakeRouteRepository) FindByHost(host string) (route models.Route, apiErr errors.Error) {
	repo.FindByHostHost = host

	if repo.FindByHostErr {
		apiErr = errors.NewErrorWithMessage("Route not found")
	}

	route = repo.FindByHostRoute
	return
}
开发者ID:knolleary,项目名称:cli,代码行数:10,代码来源:fake_route_repo.go

示例11: checkSpaceRole

func (repo CloudControllerUserRepository) checkSpaceRole(userGuid, spaceGuid, role string) (fullPath string, apiErr errors.Error) {
	rolePath, found := spaceRoleToPathMap[role]

	if !found {
		apiErr = errors.NewErrorWithMessage("Invalid Role %s", role)
	}

	fullPath = fmt.Sprintf("%s/v2/spaces/%s/%s/%s", repo.config.ApiEndpoint(), spaceGuid, rolePath, userGuid)
	return
}
开发者ID:jibin-tomy,项目名称:cli,代码行数:10,代码来源:users.go

示例12: UpdatePassword

func (repo CloudControllerPasswordRepository) UpdatePassword(old string, new string) errors.Error {
	uaaEndpoint := repo.config.UaaEndpoint()
	if uaaEndpoint == "" {
		return errors.NewErrorWithMessage("UAA endpoint missing from config file")
	}

	url := fmt.Sprintf("%s/Users/%s/password", uaaEndpoint, repo.config.UserGuid())
	body := fmt.Sprintf(`{"password":"%s","oldPassword":"%s"}`, new, old)

	return repo.gateway.UpdateResource(url, repo.config.AccessToken(), strings.NewReader(body))
}
开发者ID:knolleary,项目名称:cli,代码行数:11,代码来源:password.go

示例13: ListRoutes

func (repo *FakeRouteRepository) ListRoutes(cb func(models.Route) bool) (apiErr errors.Error) {
	if repo.ListErr {
		return errors.NewErrorWithMessage("WHOOPSIE")
	}

	for _, route := range repo.Routes {
		if !cb(route) {
			break
		}
	}
	return
}
开发者ID:knolleary,项目名称:cli,代码行数:12,代码来源:fake_route_repo.go

示例14: FindByName

func (repo *FakeQuotaRepository) FindByName(name string) (quota models.QuotaFields, apiErr errors.Error) {
	repo.FindByNameName = name
	quota = repo.FindByNameQuota

	if repo.FindByNameNotFound {
		apiErr = errors.NewModelNotFoundError("Org", name)
	}
	if repo.FindByNameErr {
		apiErr = errors.NewErrorWithMessage("Error finding quota")
	}

	return
}
开发者ID:knolleary,项目名称:cli,代码行数:13,代码来源:fake_quota_repo.go

示例15: setOrganization

func (cmd Target) setOrganization(orgName string) error {
	// setting an org necessarily invalidates any space you had previously targeted
	cmd.config.SetOrganizationFields(models.OrganizationFields{})
	cmd.config.SetSpaceFields(models.SpaceFields{})

	org, apiErr := cmd.orgRepo.FindByName(orgName)
	if apiErr != nil {
		return errors.NewErrorWithMessage("Could not target org.\n%s", apiErr.Error())
	}

	cmd.config.SetOrganizationFields(org.OrganizationFields)
	return nil
}
开发者ID:knolleary,项目名称:cli,代码行数:13,代码来源:target.go


注:本文中的cf/errors.NewErrorWithMessage函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。