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


Golang errors.WrapError函數代碼示例

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


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

示例1: Pull

func (r CIRepository) Pull() (ImportRec, bool, error) {
	var relSourceRecs []relSourceRec

	err := r.index.ListKeys(&relSourceRecs)
	if err != nil {
		return ImportRec{}, false, bosherr.WrapError(err, "Finding release sources")
	}

	if len(relSourceRecs) == 0 {
		return ImportRec{}, false, nil
	}

	rec := relSourceRecs[0]

	r.logger.Debug(ciRepositoryLogTag, "Pulling import '%v'", rec)

	importRec := ImportRec{
		RelSource: rec.RelSource,
		Version:   rec.Version,
	}

	err = r.index.Remove(relSourceRec{rec.RelSource, rec.Version})
	if err != nil {
		return ImportRec{}, false, bosherr.WrapError(err, "Removing import")
	}

	return importRec, true, nil
}
開發者ID:pivotalservices,項目名稱:bosh-hub,代碼行數:28,代碼來源:concrete_imports_repository.go

示例2: diskMatchesPartitions

func (p sfdiskPartitioner) diskMatchesPartitions(devicePath string, partitionsToMatch []Partition) (result bool) {
	existingPartitions, err := p.getPartitions(devicePath)
	if err != nil {
		err = bosherr.WrapError(err, "Getting partitions for %s", devicePath)
		return
	}

	if len(existingPartitions) < len(partitionsToMatch) {
		return
	}

	remainingDiskSpace, err := p.GetDeviceSizeInMb(devicePath)
	if err != nil {
		err = bosherr.WrapError(err, "Getting device size for %s", devicePath)
		return
	}

	for index, partitionToMatch := range partitionsToMatch {
		if index == len(partitionsToMatch)-1 {
			partitionToMatch.SizeInMb = remainingDiskSpace
		}

		existingPartition := existingPartitions[index]
		switch {
		case existingPartition.Type != partitionToMatch.Type:
			return
		case notWithinDelta(existingPartition.SizeInMb, partitionToMatch.SizeInMb, 20):
			return
		}

		remainingDiskSpace = remainingDiskSpace - partitionToMatch.SizeInMb
	}

	return true
}
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:35,代碼來源:sfdisk_partitioner.go

示例3: validate

func (c Config) validate() error {
	if c.AssetsDir == "" {
		return bosherr.New("Must provide non-empty assets_dir")
	}

	if c.ReposDir == "" {
		return bosherr.New("Must provide non-empty repos_dir")
	}

	err := c.EventLog.Validate()
	if err != nil {
		return bosherr.WrapError(err, "Validating event_log configuration")
	}

	if c.Blobstore.Type != bpprov.BlobstoreConfigTypeLocal {
		return bosherr.New("Blobstore type must be local")
	}

	err = c.Blobstore.Validate()
	if err != nil {
		return bosherr.WrapError(err, "Validating blobstore configuration")
	}

	return nil
}
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:25,代碼來源:config.go

示例4: compileRelease

func (p ReleaseCompiler) compileRelease(pkgsCompiler bppkgscomp.PackagesCompiler, depRelease bpdep.Release) error {
	relReader := p.releaseReaderFactory.NewReader(
		depRelease.Name,
		depRelease.Version,
		depRelease.URL,
	)

	relRelease, err := relReader.Read()
	if err != nil {
		return bosherr.WrapError(err, "Reading release")
	}

	defer relReader.Close()

	err = pkgsCompiler.Compile(relRelease)
	if err != nil {
		return bosherr.WrapError(err, "Compiling release packages")
	}

	err = p.templatesCompiler.Precompile(relRelease)
	if err != nil {
		return bosherr.WrapError(err, "Precompiling release job templates")
	}

	return nil
}
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:26,代碼來源:release_compiler.go

示例5: importNotes

func (i PeriodicGithubNoteImporter) importNotes() error {
	// todo getting all releases; could be big
	sources, err := i.releasesRepo.ListAll()
	if err != nil {
		return bosherr.WrapError(err, "Listing releases")
	}

	for _, source := range sources {
		ghSource, valid := newGithubSource(source)
		if !valid {
			continue
		}

		// todo convert Source to string; argh
		relVerRecs, err := i.releasesRepo.FindAll(source.Full)
		if err != nil {
			return bosherr.WrapError(err, "Listing all versions for release source '%s'", source)
		}

		err = i.importNotesForRelease(ghSource, relVerRecs)
		if err != nil {
			return bosherr.WrapError(err, "Importing notes for release source '%s'", source)
		}
	}

	return nil
}
開發者ID:pivotalservices,項目名稱:bosh-hub,代碼行數:27,代碼來源:periodic_github_note_importer.go

示例6: Get

func (p BlobstoreProvider) Get(provider string, options map[string]interface{}) (boshblob.Blobstore, error) {
	configDir, err := p.fs.TempDir("blobstore-s3-config")
	if err != nil {
		return nil, bosherr.WrapError(err, "Cerating tmp dir for blobstore config")
	}

	configPath := filepath.Join(configDir, "config.json")

	blobstore := boshblob.NewExternalBlobstore(
		provider,
		options,
		p.fs,
		p.runner,
		p.uuidGen,
		configPath,
	)

	blobstore = boshblob.NewSHA1VerifiableBlobstore(blobstore)

	blobstore = boshblob.NewRetryableBlobstore(blobstore, 3, p.logger)

	err = blobstore.Validate()
	if err != nil {
		return nil, bosherr.WrapError(err, "Validating blobstore")
	}

	return blobstore, nil
}
開發者ID:pivotalservices,項目名稱:bosh-hub,代碼行數:28,代碼來源:blobstore_provider.go

示例7: fetchOnce

func (p *PlainBucketPage) fetchOnce() (plainBucketPage_ListBucketResult, error) {
	// Return memoized results; not thread safe
	if p.fetchedResult != nil || p.fetchedErr != nil {
		return *p.fetchedResult, p.fetchedErr
	}

	fullURL := p.fullURL()

	p.logger.Debug(p.logTag, "Fetching bucket page from url '%s'", fullURL)

	var result plainBucketPage_ListBucketResult

	resp, err := http.Get(fullURL)
	if err != nil {
		p.fetchedErr = err
		return result, bosherr.WrapError(err, "Requesting bucket page")
	}

	defer resp.Body.Close()

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

	err = decoder.Decode(&result)
	if err != nil {
		p.fetchedErr = err
		return result, bosherr.WrapError(err, "Parsing bucket page")
	}

	p.logger.Debug(p.logTag, "Saving bucket page result '%v'", result)

	p.fetchedResult = &result

	return result, nil
}
開發者ID:pivotalservices,項目名稱:bosh-hub,代碼行數:35,代碼來源:plain_bucket_page.go

示例8: SaveAll

func (r S3StemcellsRepository) SaveAll(s3Files []bhs3.File) error {
	var s3StemcellRecs []s3StemcellRec

	for _, s3File := range s3Files {
		url, err := s3File.URL()
		if err != nil {
			return bosherr.WrapError(err, "Generating S3 stemcell URL")
		}

		rec := s3StemcellRec{
			Key:  s3File.Key(),
			ETag: s3File.ETag(),

			Size:         s3File.Size(),
			LastModified: s3File.LastModified(),

			URL: url,
		}

		s3StemcellRecs = append(s3StemcellRecs, rec)
	}

	err := r.index.Save(s3StemcellsKeyLatest, s3StemcellRecs)
	if err != nil {
		return bosherr.WrapError(err, "Saving all S3 stemcell recs")
	}

	return nil
}
開發者ID:pivotalservices,項目名稱:bosh-hub,代碼行數:29,代碼來源:s3_stemcells_repository.go

示例9: Run

func (a MountDiskAction) Run(diskCid string) (interface{}, error) {
	err := a.settingsService.LoadSettings()
	if err != nil {
		return nil, bosherr.WrapError(err, "Refreshing the settings")
	}

	settings := a.settingsService.GetSettings()

	devicePath, found := settings.Disks.Persistent[diskCid]
	if !found {
		return nil, bosherr.New("Persistent disk with volume id '%s' could not be found", diskCid)
	}

	mountPoint := a.dirProvider.StoreDir()

	isMountPoint, err := a.mountPoints.IsMountPoint(mountPoint)
	if err != nil {
		return nil, bosherr.WrapError(err, "Checking mount point")
	}
	if isMountPoint {
		mountPoint = a.dirProvider.StoreMigrationDir()
	}

	err = a.diskMounter.MountPersistentDisk(devicePath, mountPoint)
	if err != nil {
		return nil, bosherr.WrapError(err, "Mounting persistent disk")
	}

	return map[string]string{}, nil
}
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:30,代碼來源:mount_disk.go

示例10: extractReleaseAndJobs

func (e Extractor) extractReleaseAndJobs(tgzPath string) (bprel.Release, []bpreljob.Job, error) {
	var rel bprel.Release

	relReader := e.releaseReaderFactory.NewTarReader("file://" + tgzPath)

	rel, err := relReader.Read()
	if err != nil {
		return rel, nil, bosherr.WrapError(err, "Reading release")
	}

	defer relReader.Close()

	var relJobs []bpreljob.Job

	for _, j := range rel.Jobs {
		relJobReader := e.jobReaderFactory.NewTarReader("file://" + j.TarPath)

		relJob, err := relJobReader.Read()
		if err != nil {
			return rel, nil, bosherr.WrapError(err, "Reading release job '%s'", j.Name)
		}

		defer relJobReader.Close()

		relJobs = append(relJobs, relJob)
	}

	return rel, relJobs, nil
}
開發者ID:pivotalservices,項目名稱:bosh-hub,代碼行數:29,代碼來源:extractor.go

示例11: buildPackageSpecs

func (s JobState) buildPackageSpecs() (map[string]boshas.PackageSpec, error) {
	specs := map[string]boshas.PackageSpec{}

	for _, template := range s.depJob.Templates {
		pkgs, err := s.templatesCompiler.FindPackages(template)
		if err != nil {
			return specs, bosherr.WrapError(err, "Finding packages for template %s", template.Name)
		}

		for _, pkg := range pkgs {
			rec, err := s.packagesCompiler.FindCompiledPackage(pkg)
			if err != nil {
				return specs, bosherr.WrapError(err, "Finding compiled package %s", pkg.Name)
			}

			specs[pkg.Name] = boshas.PackageSpec{
				Name:    pkg.Name,
				Version: pkg.Version,

				Sha1:        rec.SHA1,
				BlobstoreID: rec.BlobID,
			}
		}
	}

	return specs, nil
}
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:27,代碼來源:job_state.go

示例12: Extract

func (e Extractor) Extract(url, tgzPath string) (bhrelsrepo.ReleaseVersionRec, error) {
	e.logger.Debug(e.logTag, "Extracting from '%s' (url '%s')", tgzPath, url)

	var relVerRec bhrelsrepo.ReleaseVersionRec

	rel, relJobs, err := e.extractReleaseAndJobs(tgzPath)
	if err != nil {
		return relVerRec, bosherr.WrapError(err, "Extracting release and jobs")
	}

	relVerRec, err = e.releasesRepo.Find(url, rel.Version)
	if err != nil {
		return relVerRec, bosherr.WrapError(err, "Finding release")
	}

	err = e.jobsRepo.SaveAll(relVerRec, relJobs)
	if err != nil {
		return relVerRec, bosherr.WrapError(err, "Saving release jobs into jobs repository")
	}

	err = e.releaseVersionsRepo.Save(relVerRec, rel)
	if err != nil {
		return relVerRec, bosherr.WrapError(err, "Saving release into releases repository")
	}

	return relVerRec, nil
}
開發者ID:pivotalservices,項目名稱:bosh-hub,代碼行數:27,代碼來源:extractor.go

示例13: Provision

func (p RunitProvisioner) Provision(name string, stopTimeout time.Duration) error {
	p.logger.Info(runitProvisionerLogTag, "Provisioning %s service", name)

	err := p.depsProvisioner.InstallRunit()
	if err != nil {
		return bosherr.WrapError(err, "Installing runit")
	}

	servicePath, enableServicePath := p.buildServicePaths(name)

	err = p.stopRunAndLog(servicePath, enableServicePath, name, stopTimeout)
	if err != nil {
		return bosherr.WrapError(err, "Stopping run and log")
	}

	err = p.setUpRun(servicePath, name)
	if err != nil {
		return bosherr.WrapError(err, "Setting up run")
	}

	err = p.setUpLog(servicePath, name)
	if err != nil {
		return bosherr.WrapError(err, "Setting up log")
	}

	err = p.startRunAndLog(servicePath, enableServicePath, name)
	if err != nil {
		return bosherr.WrapError(err, "Starting run and log")
	}

	return nil
}
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:32,代碼來源:runit_provisioner.go

示例14: buildJobReaders

func (tc ConcreteTemplatesCompiler) buildJobReaders(job bpdep.Job) ([]jobReader, error) {
	var readers []jobReader

	for _, template := range job.Templates {
		rec, found, err := tc.tplToJobRepo.FindByTemplate(template)
		if err != nil {
			return readers, bosherr.WrapError(err, "Finding dep-template -> release-job record %s", template.Name)
		} else if !found {
			return readers, bosherr.New("Expected to find dep-template -> release-job record %s", template.Name)
		}

		jobRec, found, err := tc.jobsRepo.FindByReleaseJob(rec)
		if err != nil {
			return readers, bosherr.WrapError(err, "Finding job source blob %s", template.Name)
		} else if !found {
			return readers, bosherr.New("Expected to find job source blob %s -- %s", template.Name, rec)
		}

		jobURL := fmt.Sprintf("blobstore:///%s?fingerprint=%s", jobRec.BlobID, jobRec.SHA1)

		reader := jobReader{
			rec:       rec,
			tarReader: tc.jobReaderFactory.NewReader(jobURL),
		}

		readers = append(readers, reader)
	}

	return readers, nil
}
開發者ID:keaty,項目名稱:bosh-provisioner,代碼行數:30,代碼來源:concrete_templates_compiler.go

示例15: Import

func (tr TarballRelease) Import(url string) error {
	tr.logger.Debug(tr.logTag, "Importing tarball release from '%s'", url)

	tgzPath, err := tr.builder.Build(tr.manifestPath)
	if err != nil {
		return bosherr.WrapError(err, "Building release tarball from manifest '%s'", tr.manifestPath)
	}

	defer tr.builder.CleanUp(tgzPath)

	relVerRec, err := tr.extractor.Extract(url, tgzPath)
	if err != nil {
		return bosherr.WrapError(err, "Importing release version from tgz '%s'", tgzPath)
	}

	err = tr.uploader.Upload(relVerRec, tgzPath)
	if err != nil {
		return bosherr.WrapError(err, "Uploading release verison '%v'", relVerRec)
	}

	// Save release version only after everything else was successfully imported
	err = tr.releasesRepo.Add(relVerRec)
	if err != nil {
		return bosherr.WrapError(err, "Saving release version into release versions repository")
	}

	return nil
}
開發者ID:pivotalservices,項目名稱:bosh-hub,代碼行數:28,代碼來源:tarball_release.go


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