當前位置: 首頁>>代碼示例>>Golang>>正文


Golang errors.WrapError函數代碼示例

本文整理匯總了Golang中bosh/errors.WrapError函數的典型用法代碼示例。如果您正苦於以下問題:Golang WrapError函數的具體用法?Golang WrapError怎麽用?Golang WrapError使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了WrapError函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: runCommand

func (res digDnsResolver) runCommand(cmdName string, args ...string) (stdout, stderr string, err error) {
	res.logger.Debug("Dig Dns Resolver", "Running command: %s %s", cmdName, strings.Join(args, " "))
	cmd := exec.Command(cmdName, args...)

	stdoutWriter := bytes.NewBufferString("")
	stderrWriter := bytes.NewBufferString("")
	cmd.Stdout = stdoutWriter
	cmd.Stderr = stderrWriter

	err = cmd.Start()
	if err != nil {
		err = bosherr.WrapError(err, "Starting dig command")
		return
	}

	err = cmd.Wait()
	stdout = string(stdoutWriter.Bytes())
	stderr = string(stderrWriter.Bytes())

	res.logger.Debug("Cmd Runner", "Stdout: %s", stdout)
	res.logger.Debug("Cmd Runner", "Stderr: %s", stderr)
	res.logger.Debug("Cmd Runner", "Successful: %t", err == nil)

	if err != nil {
		err = bosherr.WrapError(err, "Waiting for dig command")
	}
	return
}
開發者ID:UhuruSoftware,項目名稱:bosh_old,代碼行數:28,代碼來源:dig_dns_resolver.go

示例2: MountPersistentDisk

func (inf awsInfrastructure) MountPersistentDisk(volumeId string, mountPoint string) (err error) {
	inf.platform.GetFs().MkdirAll(mountPoint, os.FileMode(0700))

	realPath, err := inf.devicePathResolver.GetRealDevicePath(volumeId)

	if err != nil {
		err = bosherr.WrapError(err, "Getting real device path")
		return
	}

	partitions := []boshdisk.Partition{
		{Type: boshdisk.PartitionTypeLinux},
	}

	err = inf.platform.GetDiskManager().GetPartitioner().Partition(realPath, partitions)
	if err != nil {
		err = bosherr.WrapError(err, "Partitioning disk")
		return
	}

	partitionPath := realPath + "1"
	err = inf.platform.GetDiskManager().GetFormatter().Format(partitionPath, boshdisk.FileSystemExt4)
	if err != nil {
		err = bosherr.WrapError(err, "Formatting partition with ext4")
		return
	}

	err = inf.platform.GetDiskManager().GetMounter().Mount(partitionPath, mountPoint)
	if err != nil {
		err = bosherr.WrapError(err, "Mounting partition")
		return
	}
	return
}
開發者ID:velankanisys,項目名稱:bosh,代碼行數:34,代碼來源:aws_infrastructure.go

示例3: Start

func (h natsHandler) Start(handlerFunc boshhandler.HandlerFunc) (err error) {
	connProvider, err := h.getConnectionInfo()
	if err != nil {
		err = bosherr.WrapError(err, "Getting connection info")
		return
	}

	err = h.client.Connect(connProvider)
	if err != nil {
		err = bosherr.WrapError(err, "Connecting")
		return
	}

	subject := fmt.Sprintf("agent.%s", h.settings.GetAgentId())

	h.client.Subscribe(subject, func(natsMsg *yagnats.Message) {
		respBytes, req, err := boshhandler.PerformHandlerWithJSON(natsMsg.Payload, handlerFunc, h.logger)
		if err != nil {
			err = bosherr.WrapError(err, "Running handler in a nice JSON sandwhich")
			return
		}

		h.client.Publish(req.ReplyTo, respBytes)
	})

	return
}
開發者ID:reneedv,項目名稱:bosh,代碼行數:27,代碼來源:nats_handler.go

示例4: downloadAndInstall

func (s *concretePackageApplier) downloadAndInstall(pkg models.Package, pkgBundle bc.Bundle) error {
	tmpDir, err := s.fs.TempDir("bosh-agent-applier-packageapplier-ConcretePackageApplier-Apply")
	if err != nil {
		return bosherr.WrapError(err, "Getting temp dir")
	}

	defer s.fs.RemoveAll(tmpDir)

	file, err := s.blobstore.Get(pkg.Source.BlobstoreID, pkg.Source.Sha1)
	if err != nil {
		return bosherr.WrapError(err, "Fetching package blob")
	}

	defer s.blobstore.CleanUp(file)

	err = s.compressor.DecompressFileToDir(file, tmpDir)
	if err != nil {
		return bosherr.WrapError(err, "Decompressing package files")
	}

	_, _, err = pkgBundle.Install(tmpDir)
	if err != nil {
		return bosherr.WrapError(err, "Installling package directory")
	}

	return nil
}
開發者ID:punalpatel,項目名稱:bosh,代碼行數:27,代碼來源:concrete_package_applier.go

示例5: status

func (c httpClient) status() (status status, err error) {
	url := c.monitUrl("/_status2")
	url.RawQuery = "format=xml"

	response, err := c.makeRequest(url, "GET", "")
	if err != nil {
		err = bosherr.WrapError(err, "Sending status request to monit")
		return
	}
	defer response.Body.Close()

	err = c.validateResponse(response)
	if err != nil {
		err = bosherr.WrapError(err, "Getting monit status")
		return
	}

	decoder := xml.NewDecoder(response.Body)
	decoder.CharsetReader = charset.NewReader

	err = decoder.Decode(&status)
	if err != nil {
		err = bosherr.WrapError(err, "Unmarshalling Monit status")
	}
	return
}
開發者ID:UhuruSoftware,項目名稱:bosh_old,代碼行數:26,代碼來源:http_client.go

示例6: ConvergeFileContents

func (fs osFileSystem) ConvergeFileContents(path string, content []byte) (written bool, err error) {
	if fs.filesAreIdentical(content, path) {
		return
	}

	err = fs.MkdirAll(filepath.Dir(path), os.ModePerm)
	if err != nil {
		err = bosherr.WrapError(err, "Making dir for file %s", path)
		return
	}

	file, err := os.Create(path)
	if err != nil {
		err = bosherr.WrapError(err, "Creating file %s", path)
		return
	}
	defer file.Close()

	_, err = file.Write(content)
	if err != nil {
		err = bosherr.WrapError(err, "Writing content to file %s", path)
		return
	}

	written = true
	return
}
開發者ID:Jane4PKU,項目名稱:bosh,代碼行數:27,代碼來源:os_file_system.go

示例7: Chown

func (fs osFileSystem) Chown(path, username string) (err error) {
	fs.logger.Debug(fs.logTag, "Chown %s to user %s", path, username)

	user, err := osuser.Lookup(username)
	if err != nil {
		err = bosherr.WrapError(err, "Looking up user %s", username)
		return
	}

	uid, err := strconv.Atoi(user.Uid)
	if err != nil {
		err = bosherr.WrapError(err, "Converting UID to integer")
		return
	}

	gid, err := strconv.Atoi(user.Gid)
	if err != nil {
		err = bosherr.WrapError(err, "Converting GID to integer")
		return
	}

	err = os.Chown(path, uid, gid)
	if err != nil {
		err = bosherr.WrapError(err, "Doing Chown")
		return
	}
	return
}
開發者ID:Jane4PKU,項目名稱:bosh,代碼行數:28,代碼來源:os_file_system.go

示例8: Run

func (r concreteRunner) Run(action Action, payloadBytes []byte) (value interface{}, err error) {
	payloadArgs, err := r.extractJsonArguments(payloadBytes)
	if err != nil {
		err = bosherr.WrapError(err, "Extracting json arguments")
		return
	}

	actionValue := reflect.ValueOf(action)
	runMethodValue := actionValue.MethodByName("Run")
	if runMethodValue.Kind() != reflect.Func {
		err = bosherr.New("Run method not found")
		return
	}

	runMethodType := runMethodValue.Type()
	if r.invalidReturnTypes(runMethodType) {
		err = bosherr.New("Run method should return a value and an error")
		return
	}

	methodArgs, err := r.extractMethodArgs(runMethodType, payloadArgs)
	if err != nil {
		err = bosherr.WrapError(err, "Extracting method arguments from payload")
		return
	}

	values := runMethodValue.Call(methodArgs)
	return r.extractReturns(values)
}
開發者ID:UhuruSoftware,項目名稱:bosh_old,代碼行數:29,代碼來源:runner.go

示例9: Apply

func (s *concretePackageApplier) Apply(pkg models.Package) (err error) {
	_, packageDir, err := s.packagesBc.Install(pkg)
	if err != nil {
		err = bosherr.WrapError(err, "Installling package directory")
		return
	}

	file, err := s.blobstore.Get(pkg.Source.BlobstoreId, pkg.Source.Sha1)
	if err != nil {
		err = bosherr.WrapError(err, "Fetching package blob")
		return
	}

	defer s.blobstore.CleanUp(file)

	err = s.compressor.DecompressFileToDir(file, packageDir)
	if err != nil {
		err = bosherr.WrapError(err, "Decompressing package files")
		return
	}

	err = s.packagesBc.Enable(pkg)
	if err != nil {
		err = bosherr.WrapError(err, "Enabling package")
	}

	return
}
開發者ID:UhuruSoftware,項目名稱:bosh_old,代碼行數:28,代碼來源:concrete_package_applier.go

示例10: WriteToFile

func (fs osFileSystem) WriteToFile(path, content string) (written bool, err error) {
	fs.logger.DebugWithDetails(fs.logTag, "Writing to file %s", path, content)

	if fs.filesAreIdentical(content, path) {
		return
	}

	err = fs.MkdirAll(filepath.Dir(path), os.ModePerm)
	if err != nil {
		err = bosherr.WrapError(err, "Making dir for file %s", path)
		return
	}

	file, err := os.Create(path)
	if err != nil {
		err = bosherr.WrapError(err, "Creating file %s", path)
		return
	}
	defer file.Close()

	_, err = file.WriteString(content)
	if err != nil {
		err = bosherr.WrapError(err, "Writing content to file %s", path)
		return
	}

	written = true
	return
}
開發者ID:reneedv,項目名稱:bosh,代碼行數:29,代碼來源:os_file_system.go

示例11: runCmd

func (run execCmdRunner) runCmd(cmd *exec.Cmd) (stdout, stderr string, err error) {
	cmdString := strings.Join(cmd.Args, " ")

	run.logger.Debug("Cmd Runner", "Running command: %s", cmdString)

	stdoutWriter := bytes.NewBufferString("")
	stderrWriter := bytes.NewBufferString("")
	cmd.Stdout = stdoutWriter
	cmd.Stderr = stderrWriter

	err = cmd.Start()
	if err != nil {
		err = bosherr.WrapError(err, "Starting command %s", cmdString)
		return
	}

	err = cmd.Wait()
	stdout = string(stdoutWriter.Bytes())
	stderr = string(stderrWriter.Bytes())

	run.logger.Debug("Cmd Runner", "Stdout: %s", stdout)
	run.logger.Debug("Cmd Runner", "Stderr: %s", stderr)
	run.logger.Debug("Cmd Runner", "Successful: %t", err == nil)

	if err != nil {
		err = bosherr.WrapError(err, "Running command: '%s', stdout: '%s', stderr: '%s'", cmdString, stdout, stderr)
	}
	return
}
開發者ID:velankanisys,項目名稱:bosh,代碼行數:29,代碼來源:exec_cmd_runner.go

示例12: setupSsh

func (a SshAction) setupSsh(params SshParams) (value interface{}, err error) {
	boshSshPath := filepath.Join(a.dirProvider.BaseDir(), "bosh_ssh")
	err = a.platform.CreateUser(params.User, params.Password, boshSshPath)
	if err != nil {
		err = bosherr.WrapError(err, "Creating user")
		return
	}

	err = a.platform.AddUserToGroups(params.User, []string{boshsettings.VCAPUsername, boshsettings.AdminGroup})
	if err != nil {
		err = bosherr.WrapError(err, "Adding user to groups")
		return
	}

	err = a.platform.SetupSsh(params.PublicKey, params.User)
	if err != nil {
		err = bosherr.WrapError(err, "Setting ssh public key")
		return
	}

	defaultIP, found := a.settings.GetDefaultIP()

	if !found {
		err = errors.New("No default ip could be found")
		return
	}

	value = map[string]string{
		"command": "setup",
		"status":  "success",
		"ip":      defaultIP,
	}
	return
}
開發者ID:punalpatel,項目名稱:bosh,代碼行數:34,代碼來源:ssh.go

示例13: Reload

func (m monitJobSupervisor) Reload() (err error) {
	oldIncarnation, err := m.getIncarnation()
	if err != nil {
		err = bosherr.WrapError(err, "Getting monit incarnation")
		return err
	}

	// Exit code or output cannot be trusted
	m.runner.RunCommand("monit", "reload")

	for attempt := 1; attempt < 60; attempt++ {
		err = nil
		currentIncarnation, err := m.getIncarnation()
		if err != nil {
			err = bosherr.WrapError(err, "Getting monit incarnation")
			return err
		}

		if oldIncarnation < currentIncarnation {
			return nil
		}

		time.Sleep(m.delayBetweenReloadCheckRetries)
	}

	err = bosherr.New("Failed to reload monit")
	return
}
開發者ID:velankanisys,項目名稱:bosh,代碼行數:28,代碼來源:monit_job_supervisor.go

示例14: Run

func (action logsAction) Run(payloadBytes []byte) (value interface{}, err error) {
	filters, err := extractFilters(payloadBytes)
	if err != nil {
		err = bosherr.WrapError(err, "Extracting filters from payload")
		return
	}

	if len(filters) == 0 {
		filters = []string{"**/*"}
	}

	logsDir := filepath.Join(boshsettings.VCAP_BASE_DIR, "bosh", "log")
	tarball, err := action.compressor.CompressFilesInDir(logsDir, filters)
	if err != nil {
		err = bosherr.WrapError(err, "Making logs tarball")
		return
	}

	blobId, err := action.blobstore.Create(tarball)
	if err != nil {
		err = bosherr.WrapError(err, "Create file on blobstore")
		return
	}

	value = map[string]string{"blobstore_id": blobId}
	return
}
開發者ID:nicregez,項目名稱:bosh,代碼行數:27,代碼來源:logs.go

示例15: validateJob

func (v SyntaxValidator) validateJob(job *Job) error {
	if job.Name == "" {
		return bosherr.New("Missing job name")
	}

	if job.Template != nil {
		return bosherr.New("'template' is deprecated in favor of 'templates'")
	}

	err := v.validateUpdate(&job.Update)
	if err != nil {
		return bosherr.WrapError(err, "Update")
	}

	props, err := bputil.NewStringKeyed().ConvertMap(job.PropertiesRaw)
	if err != nil {
		return bosherr.WrapError(err, "Properties")
	}

	job.Properties = props

	for i, na := range job.NetworkAssociations {
		err := v.validateNetworkAssociation(&job.NetworkAssociations[i])
		if err != nil {
			return bosherr.WrapError(err, "Network association %s (%d)", na.NetworkName, i)
		}
	}

	return nil
}
開發者ID:ronakbanka,項目名稱:vagrant-bosh,代碼行數:30,代碼來源:syntax_validator.go


注:本文中的bosh/errors.WrapError函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。