本文整理汇总了Golang中github.com/cloudfoundry/bosh-init/internal/github.com/cloudfoundry/bosh-utils/errors.WrapError函数的典型用法代码示例。如果您正苦于以下问题:Golang WrapError函数的具体用法?Golang WrapError怎么用?Golang WrapError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了WrapError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: partitionEphemeralDisk
func (p linux) partitionEphemeralDisk(realPath string) (string, string, error) {
p.logger.Info(logTag, "Creating swap & ephemeral partitions on ephemeral disk...")
p.logger.Debug(logTag, "Getting device size of `%s'", realPath)
diskSizeInBytes, err := p.diskManager.GetPartitioner().GetDeviceSizeInBytes(realPath)
if err != nil {
return "", "", bosherr.WrapError(err, "Getting device size")
}
p.logger.Debug(logTag, "Calculating ephemeral disk partition sizes of `%s' with total disk size %dB", realPath, diskSizeInBytes)
swapSizeInBytes, linuxSizeInBytes, err := p.calculateEphemeralDiskPartitionSizes(diskSizeInBytes)
if err != nil {
return "", "", bosherr.WrapError(err, "Calculating partition sizes")
}
partitions := []boshdisk.Partition{
{SizeInBytes: swapSizeInBytes, Type: boshdisk.PartitionTypeSwap},
{SizeInBytes: linuxSizeInBytes, Type: boshdisk.PartitionTypeLinux},
}
p.logger.Info(logTag, "Partitioning ephemeral disk `%s' with %s", realPath, partitions)
err = p.diskManager.GetPartitioner().Partition(realPath, partitions)
if err != nil {
return "", "", bosherr.WrapErrorf(err, "Partitioning ephemeral disk `%s'", realPath)
}
swapPartitionPath := realPath + "1"
dataPartitionPath := realPath + "2"
return swapPartitionPath, dataPartitionPath, nil
}
示例2: Chown
func (fs *osFileSystem) Chown(path, username string) error {
fs.logger.Debug(fs.logTag, "Chown %s to user %s", path, username)
uid, err := fs.runCommand(fmt.Sprintf("id -u %s", username))
if err != nil {
return bosherr.WrapErrorf(err, "Getting user id for '%s'", username)
}
uidAsInt, err := strconv.Atoi(uid)
if err != nil {
return bosherr.WrapError(err, "Converting UID to integer")
}
gid, err := fs.runCommand(fmt.Sprintf("id -g %s", username))
if err != nil {
return bosherr.WrapErrorf(err, "Getting group id for '%s'", username)
}
gidAsInt, err := strconv.Atoi(gid)
if err != nil {
return bosherr.WrapError(err, "Converting GID to integer")
}
err = os.Chown(path, uidAsInt, gidAsInt)
if err != nil {
return bosherr.WrapError(err, "Doing Chown")
}
return nil
}
示例3: findRootDevicePath
func (p linux) findRootDevicePath() (string, error) {
mounts, err := p.diskManager.GetMountsSearcher().SearchMounts()
if err != nil {
return "", bosherr.WrapError(err, "Searching mounts")
}
for _, mount := range mounts {
if mount.MountPoint == "/" && strings.HasPrefix(mount.PartitionPath, "/dev/") {
p.logger.Debug(logTag, "Found root partition: `%s'", mount.PartitionPath)
stdout, _, _, err := p.cmdRunner.RunCommand("readlink", "-f", mount.PartitionPath)
if err != nil {
return "", bosherr.WrapError(err, "Shelling out to readlink")
}
rootPartition := strings.Trim(stdout, "\n")
p.logger.Debug(logTag, "Symlink is: `%s'", rootPartition)
validRootPartition := regexp.MustCompile(`^/dev/[a-z]+1$`)
if !validRootPartition.MatchString(rootPartition) {
return "", bosherr.Error("Root partition is not the first partition")
}
return strings.Trim(rootPartition, "1"), nil
}
}
return "", bosherr.Error("Getting root partition device")
}
示例4: detectMacAddresses
func (net centosNetManager) detectMacAddresses() (map[string]string, error) {
addresses := map[string]string{}
filePaths, err := net.fs.Glob("/sys/class/net/*")
if err != nil {
return addresses, bosherr.WrapError(err, "Getting file list from /sys/class/net")
}
var macAddress string
for _, filePath := range filePaths {
isPhysicalDevice := net.fs.FileExists(filepath.Join(filePath, "device"))
if isPhysicalDevice {
macAddress, err = net.fs.ReadFileString(filepath.Join(filePath, "address"))
if err != nil {
return addresses, bosherr.WrapError(err, "Reading mac address from file")
}
macAddress = strings.Trim(macAddress, "\n")
interfaceName := filepath.Base(filePath)
addresses[macAddress] = interfaceName
}
}
return addresses, nil
}
示例5: Save
func (r diskRepo) Save(cid string, size int, cloudProperties biproperty.Map) (DiskRecord, error) {
config, records, err := r.load()
if err != nil {
return DiskRecord{}, err
}
oldRecord, found := r.find(records, cid)
if found {
return DiskRecord{}, bosherr.Errorf("Failed to save disk cid '%s', existing record found '%#v'", cid, oldRecord)
}
newRecord := DiskRecord{
CID: cid,
Size: size,
CloudProperties: cloudProperties,
}
newRecord.ID, err = r.uuidGenerator.Generate()
if err != nil {
return newRecord, bosherr.WrapError(err, "Generating disk id")
}
records = append(records, newRecord)
config.Disks = records
err = r.deploymentStateService.Save(config)
if err != nil {
return newRecord, bosherr.WrapError(err, "Saving new config")
}
return newRecord, nil
}
示例6: Update
func (r releaseRepo) Update(releases []release.Release) error {
newRecordIDs := []string{}
newRecords := []ReleaseRecord{}
deploymentState, err := r.deploymentStateService.Load()
if err != nil {
return bosherr.WrapError(err, "Loading existing config")
}
for _, release := range releases {
newRecord := ReleaseRecord{
Name: release.Name(),
Version: release.Version(),
}
newRecord.ID, err = r.uuidGenerator.Generate()
if err != nil {
return bosherr.WrapError(err, "Generating release id")
}
newRecords = append(newRecords, newRecord)
newRecordIDs = append(newRecordIDs, newRecord.ID)
}
deploymentState.CurrentReleaseIDs = newRecordIDs
deploymentState.Releases = newRecords
err = r.deploymentStateService.Save(deploymentState)
if err != nil {
return bosherr.WrapError(err, "Updating current release record")
}
return nil
}
示例7: Delete
func (s *cloudStemcell) Delete() error {
deleteErr := s.cloud.DeleteStemcell(s.cid)
if deleteErr != nil {
// allow StemcellNotFoundError for idempotency
cloudErr, ok := deleteErr.(bicloud.Error)
if !ok || cloudErr.Type() != bicloud.StemcellNotFoundError {
return bosherr.WrapError(deleteErr, "Deleting stemcell from cloud")
}
}
stemcellRecord, found, err := s.repo.Find(s.name, s.version)
if err != nil {
return bosherr.WrapErrorf(err, "Finding stemcell record (name=%s, version=%s)", s.name, s.version)
}
if !found {
return nil
}
err = s.repo.Delete(stemcellRecord)
if err != nil {
return bosherr.WrapError(err, "Deleting stemcell record")
}
return deleteErr
}
示例8: SetupNetworking
func (net UbuntuNetManager) SetupNetworking(networks boshsettings.Networks, errCh chan error) error {
staticConfigs, dhcpConfigs, dnsServers, err := net.ComputeNetworkConfig(networks)
if err != nil {
return bosherr.WrapError(err, "Computing network configuration")
}
interfacesChanged, err := net.writeNetworkInterfaces(dhcpConfigs, staticConfigs, dnsServers)
if err != nil {
return bosherr.WrapError(err, "Writing network configuration")
}
dhcpChanged := false
if len(dhcpConfigs) > 0 {
dhcpChanged, err = net.writeDHCPConfiguration(dnsServers)
if err != nil {
return err
}
}
if interfacesChanged || dhcpChanged {
err = net.removeDhcpDNSConfiguration()
if err != nil {
return err
}
net.restartNetworkingInterfaces()
}
net.broadcastIps(staticConfigs, dhcpConfigs, errCh)
return nil
}
示例9: Parse
func (p *parser) Parse(path string) (Manifest, error) {
contents, err := p.fs.ReadFile(path)
if err != nil {
return Manifest{}, bosherr.WrapErrorf(err, "Reading file %s", path)
}
comboManifest := manifest{}
err = yaml.Unmarshal(contents, &comboManifest)
if err != nil {
return Manifest{}, bosherr.WrapError(err, "Unmarshalling release set manifest")
}
p.logger.Debug(p.logTag, "Parsed release set manifest: %#v", comboManifest)
for i, releaseRef := range comboManifest.Releases {
comboManifest.Releases[i].URL, err = biutil.AbsolutifyPath(path, releaseRef.URL, p.fs)
if err != nil {
return Manifest{}, bosherr.WrapErrorf(err, "Resolving release path '%s", releaseRef.URL)
}
}
releaseSetManifest := Manifest{
Releases: comboManifest.Releases,
}
err = p.validator.Validate(releaseSetManifest)
if err != nil {
return Manifest{}, bosherr.WrapError(err, "Validating release set manifest")
}
return releaseSetManifest, nil
}
示例10: SetupHostname
func (p linux) SetupHostname(hostname string) (err error) {
_, _, _, err = p.cmdRunner.RunCommand("hostname", hostname)
if err != nil {
err = bosherr.WrapError(err, "Shelling out to hostname")
return
}
err = p.fs.WriteFileString("/etc/hostname", hostname)
if err != nil {
err = bosherr.WrapError(err, "Writing /etc/hostname")
return
}
buffer := bytes.NewBuffer([]byte{})
t := template.Must(template.New("etc-hosts").Parse(etcHostsTemplate))
err = t.Execute(buffer, hostname)
if err != nil {
err = bosherr.WrapError(err, "Generating config from template")
return
}
err = p.fs.WriteFile("/etc/hosts", buffer.Bytes())
if err != nil {
err = bosherr.WrapError(err, "Writing to /etc/hosts")
}
return
}
示例11: Delete
func (d *disk) Delete() error {
deleteErr := d.cloud.DeleteDisk(d.cid)
if deleteErr != nil {
// allow DiskNotFoundError for idempotency
cloudErr, ok := deleteErr.(bicloud.Error)
if !ok || cloudErr.Type() != bicloud.DiskNotFoundError {
return bosherr.WrapError(deleteErr, "Deleting disk in the cloud")
}
}
diskRecord, found, err := d.repo.Find(d.cid)
if err != nil {
return bosherr.WrapErrorf(err, "Finding disk record (cid=%s)", d.cid)
}
if !found {
return nil
}
err = d.repo.Delete(diskRecord)
if err != nil {
return bosherr.WrapError(err, "Deleting disk record")
}
// returns bicloud.Error only if it is a DiskNotFoundError
return deleteErr
}
示例12: loadFromDiskPath
func (ms *configDriveMetadataService) loadFromDiskPath(diskPath string) error {
contentPaths := []string{ms.metaDataFilePath, ms.userDataFilePath}
contents, err := ms.platform.GetFilesContentsFromDisk(diskPath, contentPaths)
if err != nil {
return bosherr.WrapError(err, "Reading files on config drive")
}
var metadata MetadataContentsType
err = json.Unmarshal(contents[0], &metadata)
if err != nil {
return bosherr.WrapError(err, "Parsing config drive metadata from meta_data.json")
}
ms.metaDataContents = metadata
var userdata UserDataContentsType
err = json.Unmarshal(contents[1], &userdata)
if err != nil {
return bosherr.WrapError(err, "Parsing config drive metadata from user_data")
}
ms.userDataContents = userdata
return nil
}
示例13: describeMultilineError
func describeMultilineError() {
var err error
It("returns a simple single-line message string (depth=0)", func() {
err = bosherr.Error("omg")
Expect(MultilineError(err)).To(Equal("omg"))
})
Context("when given a composite error", func() {
It("returns a multi-line, indented message string (depth=1)", func() {
err = bosherr.WrapError(bosherr.Error("inner omg"), "omg")
Expect(MultilineError(err)).To(Equal("omg:\n inner omg"))
})
It("returns a multi-line, indented message string (depth=2)", func() {
err = bosherr.WrapError(bosherr.WrapError(bosherr.Error("inner omg"), "omg"), "outer omg")
Expect(MultilineError(err)).To(Equal("outer omg:\n omg:\n inner omg"))
})
It("returns a multi-line, indented message string (depth=3)", func() {
err = bosherr.WrapError(bosherr.WrapError(bosherr.WrapError(bosherr.Error("inner omg"), "almost inner omg"), "almost outer omg"), "outer omg")
Expect(MultilineError(err)).To(Equal("outer omg:\n almost outer omg:\n almost inner omg:\n inner omg"))
})
})
Context("when given an explainable error", func() {
It("returns a multi-line message string with sibling errors at the same indentation", func() {
err = bosherr.NewMultiError(bosherr.Error("a"), bosherr.Error("b"))
Expect(MultilineError(err)).To(Equal("a\nb"))
})
It("returns a multi-line message string with sibling errors at the same indentation", func() {
complex := bosherr.WrapError(bosherr.Error("inner a"), "outer a")
err = bosherr.NewMultiError(complex, bosherr.Error("b"))
Expect(MultilineError(err)).To(Equal("outer a:\n inner a\nb"))
})
It("returns a multi-line message string with sibling errors at the same indentation", func() {
complex := bosherr.WrapError(bosherr.Error("inner b"), "outer b")
err = bosherr.NewMultiError(bosherr.Error("a"), complex)
Expect(MultilineError(err)).To(Equal("a\nouter b:\n inner b"))
})
})
Context("when given a composite err with explainable errors", func() {
It("returns a multi-line message string with sibling errors at the same indentation", func() {
multi := bosherr.NewMultiError(bosherr.Error("inner a"), bosherr.Error("inner b"))
err = bosherr.WrapError(multi, "outer omg")
Expect(MultilineError(err)).To(Equal("outer omg:\n inner a\n inner b"))
})
})
Context("when given an ExecError", func() {
It("returns a multi-line message string with the command, stdout, & stderr at the same indentation", func() {
execErr := boshsys.NewExecError("fake-cmd --flag with some args", "some\nmultiline\nstdout", "some\nmultiline\nstderr")
err = bosherr.WrapError(execErr, "outer omg")
Expect(MultilineError(err)).To(Equal("outer omg:\n Error Executing Command:\n fake-cmd --flag with some args\n StdOut:\n some\n multiline\n stdout\n StdErr:\n some\n multiline\n stderr"))
})
})
}
示例14: UpdateJobs
func (i *instance) UpdateJobs(
deploymentManifest bideplmanifest.Manifest,
stage biui.Stage,
) error {
newState, err := i.stateBuilder.Build(i.jobName, i.id, deploymentManifest, stage)
if err != nil {
return bosherr.WrapErrorf(err, "Building state for instance '%s/%d'", i.jobName, i.id)
}
stepName := fmt.Sprintf("Updating instance '%s/%d'", i.jobName, i.id)
err = stage.Perform(stepName, func() error {
err := i.vm.Stop()
if err != nil {
return bosherr.WrapError(err, "Stopping the agent")
}
err = i.vm.Apply(newState.ToApplySpec())
if err != nil {
return bosherr.WrapError(err, "Applying the agent state")
}
err = i.vm.Start()
if err != nil {
return bosherr.WrapError(err, "Starting the agent")
}
return nil
})
if err != nil {
return err
}
return i.waitUntilJobsAreRunning(deploymentManifest.Update.UpdateWatchTime, stage)
}
示例15: Read
func (r *reader) Read() (Release, error) {
err := r.extractor.DecompressFileToDir(r.tarFilePath, r.extractedReleasePath, boshcmd.CompressorOptions{})
if err != nil {
return nil, bosherr.WrapError(err, "Extracting release")
}
releaseManifestPath := path.Join(r.extractedReleasePath, "release.MF")
releaseManifestBytes, err := r.fs.ReadFile(releaseManifestPath)
if err != nil {
return nil, bosherr.WrapErrorf(err, "Reading release manifest '%s'", releaseManifestPath)
}
var manifest birelmanifest.Manifest
err = yaml.Unmarshal(releaseManifestBytes, &manifest)
if err != nil {
return nil, bosherr.WrapError(err, "Parsing release manifest")
}
release, err := r.newReleaseFromManifest(manifest)
if err != nil {
return nil, bosherr.WrapError(err, "Constructing release from manifest")
}
return release, nil
}