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


Golang util.FmtNewtError函数代码示例

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


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

示例1: ResolvePackage

func (proj *Project) ResolvePackage(
	dfltRepo interfaces.RepoInterface, name string) (*pkg.LocalPackage, error) {
	// Trim trailing slash from name.  This is necessary when tab
	// completion is used to specify the name.
	name = strings.TrimSuffix(name, "/")

	repoName, pkgName, err := newtutil.ParsePackageString(name)
	if err != nil {
		return nil, util.FmtNewtError("invalid package name: %s (%s)", name,
			err.Error())
	}

	var repo interfaces.RepoInterface
	if repoName == "" {
		repo = dfltRepo
	} else {
		repo = proj.repos[repoName]
	}

	dep, err := pkg.NewDependency(repo, pkgName)
	if err != nil {
		return nil, util.FmtNewtError("invalid package name: %s (%s)", name,
			err.Error())
	}
	if dep == nil {
		return nil, util.NewNewtError("invalid package name: " + name)
	}
	pack := proj.ResolveDependency(dep)
	if pack == nil {
		return nil, util.NewNewtError("unknown package: " + name)
	}

	return pack.(*pkg.LocalPackage), nil
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:34,代码来源:project.go

示例2: ConvertFilenames

func ConvertFilenames(srcFilename string,
	dstFilename string) (*CoreConvert, error) {

	coreConvert := NewCoreConvert()

	var err error

	coreConvert.Source, err = os.OpenFile(srcFilename, os.O_RDONLY, 0)
	if err != nil {
		return coreConvert, util.FmtNewtError("Cannot open file %s - %s",
			srcFilename, err.Error())
	}
	defer coreConvert.Source.Close()

	coreConvert.Target, err = os.OpenFile(dstFilename,
		os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0660)
	if err != nil {
		return coreConvert, util.FmtNewtError("Cannot open file %s - %s",
			dstFilename, err.Error())
	}
	defer coreConvert.Target.Close()

	if err := coreConvert.Convert(); err != nil {
		return coreConvert, err
	}

	return coreConvert, nil
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:28,代码来源:core_convert.go

示例3: readDefsOnce

func (cfg *Cfg) readDefsOnce(lpkg *pkg.LocalPackage,
	features map[string]bool) error {
	v := lpkg.SyscfgV

	lfeatures := cfg.FeaturesForLpkg(lpkg)
	for k, _ := range features {
		lfeatures[k] = true
	}

	settings := newtutil.GetStringMapFeatures(v, lfeatures, "syscfg.defs")
	if settings != nil {
		for k, v := range settings {
			vals := v.(map[interface{}]interface{})
			entry, err := readSetting(k, lpkg, vals)
			if err != nil {
				return util.FmtNewtError("Config for package %s: %s",
					lpkg.Name(), err.Error())
			}

			if _, exists := cfg.Settings[k]; exists {
				// XXX: Better error message.
				return util.FmtNewtError("setting %s redefined", k)
			}
			cfg.Settings[k] = entry
		}
	}

	return nil
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:29,代码来源:syscfg.go

示例4: collectDepsAux

// Recursively iterates through an pkg's dependencies, adding each pkg
// encountered to the supplied set.
func (bpkg *BuildPackage) collectDepsAux(b *Builder,
	set *map[*BuildPackage]bool) error {

	if (*set)[bpkg] {
		return nil
	}

	(*set)[bpkg] = true

	for _, dep := range bpkg.Deps() {
		if dep.Name == "" {
			break
		}

		// Get pkg structure
		p := project.GetProject().ResolveDependency(dep)
		if p == nil {
			return util.FmtNewtError("Cannot resolve dependency %+v", dep)
		}
		dpkg := p.(*pkg.LocalPackage)

		dbpkg := b.PkgMap[dpkg]
		if dbpkg == nil {
			return util.FmtNewtError("Package not found %s; required by %s",
				dpkg.Name(), bpkg.Name())
		}

		if err := dbpkg.collectDepsAux(b, set); err != nil {
			return err
		}
	}

	return nil
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:36,代码来源:buildpackage.go

示例5: insertMeta

// @return						meta-offset, hash-offset, error
func insertMeta(section0Data []byte, flashMap flash.FlashMap) (
	int, int, error) {

	buf := &bytes.Buffer{}

	if err := writeHeader(buf); err != nil {
		return 0, 0, err
	}

	for _, area := range flashMap.SortedAreas() {
		if err := writeFlashMapEntry(area, buf); err != nil {
			return 0, 0, err
		}
	}

	if err := writeZeroHash(buf); err != nil {
		return 0, 0, err
	}
	hashSubOff := buf.Len() - META_HASH_SZ

	if err := writeFooter(buf); err != nil {
		return 0, 0, err
	}

	// The meta region gets placed at the very end of the boot loader slot.
	bootArea, ok := flashMap.Areas[flash.FLASH_AREA_NAME_BOOTLOADER]
	if !ok {
		return 0, 0,
			util.NewNewtError("Required boot loader flash area missing")
	}

	if bootArea.Size < buf.Len() {
		return 0, 0, util.FmtNewtError(
			"Boot loader flash area too small to accommodate meta region; "+
				"boot=%d meta=%d", bootArea.Size, buf.Len())
	}

	metaOff := bootArea.Offset + bootArea.Size - buf.Len()
	for i := metaOff; i < bootArea.Size; i++ {
		if section0Data[i] != 0xff {
			return 0, 0, util.FmtNewtError(
				"Boot loader extends into meta region; "+
					"meta region starts at offset %d", metaOff)
		}
	}

	// Copy the meta region into the manufacturing image.  The meta hash is
	// still zeroed.
	copy(section0Data[metaOff:], buf.Bytes())

	return metaOff, metaOff + hashSubOff, nil
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:53,代码来源:meta.go

示例6: createManifest

func (t *TargetBuilder) createManifest() error {
	manifest := &image.ImageManifest{
		Date: time.Now().Format(time.RFC3339),
	}

	rm := image.NewRepoManager()
	for _, lpkg := range t.AppBuilder.sortedLocalPackages() {
		manifest.Pkgs = append(manifest.Pkgs,
			rm.GetImageManifestPkg(lpkg))
	}

	if t.LoaderBuilder != nil {
		for _, lpkg := range t.LoaderBuilder.sortedLocalPackages() {
			manifest.LoaderPkgs = append(manifest.LoaderPkgs,
				rm.GetImageManifestPkg(lpkg))
		}
	}

	manifest.Repos = rm.AllRepos()

	vars := t.GetTarget().Vars
	keys := make([]string, 0, len(vars))
	for k := range vars {
		keys = append(keys, k)
	}
	sort.Strings(keys)
	for _, k := range keys {
		manifest.TgtVars = append(manifest.TgtVars, k+"="+vars[k])
	}
	file, err := os.Create(t.AppBuilder.ManifestPath())
	if err != nil {
		return util.FmtNewtError("Cannot create manifest file %s: %s",
			t.AppBuilder.ManifestPath(), err.Error())
	}
	defer file.Close()

	buffer, err := json.MarshalIndent(manifest, "", "  ")
	if err != nil {
		return util.FmtNewtError("Cannot encode manifest: %s", err.Error())
	}
	_, err = file.Write(buffer)
	if err != nil {
		return util.FmtNewtError("Cannot write manifest file: %s",
			err.Error())
	}

	return nil
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:48,代码来源:targetbuild.go

示例7: detectInvalidDevices

func (mi *MfgImage) detectInvalidDevices() error {
	sectionIds := mi.sectionIds()
	deviceIds := mi.bsp.FlashMap.DeviceIds()

	deviceMap := map[int]struct{}{}
	for _, device := range deviceIds {
		deviceMap[device] = struct{}{}
	}

	invalidIds := []int{}
	for _, sectionId := range sectionIds {
		if _, ok := deviceMap[sectionId]; !ok {
			invalidIds = append(invalidIds, sectionId)
		}
	}

	if len(invalidIds) == 0 {
		return nil
	}

	listStr := ""
	for i, id := range invalidIds {
		if i != 0 {
			listStr += ", "
		}
		listStr += strconv.Itoa(id)
	}

	return util.FmtNewtError(
		"image specifies flash devices that are not present in the BSP's "+
			"flash map: %s", listStr)
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:32,代码来源:load.go

示例8: ResolvePkgs

func ResolvePkgs(cfgResolution CfgResolution,
	seedPkgs []*pkg.LocalPackage) ([]*pkg.LocalPackage, error) {

	r := newResolver()
	r.cfg = cfgResolution.Cfg
	for _, lpkg := range seedPkgs {
		r.addPkg(lpkg)
	}

	if _, err := r.loadDepsOnce(); err != nil {
		return nil, err
	}

	// Satisfy API requirements.
	for _, rpkg := range r.pkgMap {
		for api, _ := range rpkg.reqApiMap {
			apiPkg := cfgResolution.ApiMap[api]
			if apiPkg == nil {
				return nil, util.FmtNewtError(
					"Unsatisfied API at unexpected time: %s", api)
			}

			r.addPkg(apiPkg)
		}
	}

	lpkgs := make([]*pkg.LocalPackage, len(r.pkgMap))
	i := 0
	for lpkg, _ := range r.pkgMap {
		lpkgs[i] = lpkg
		i++
	}

	return lpkgs, nil
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:35,代码来源:resolve.go

示例9: readSetting

func readSetting(name string, lpkg *pkg.LocalPackage,
	vals map[interface{}]interface{}) (CfgEntry, error) {

	entry := CfgEntry{}

	entry.Name = name
	entry.Description = stringValue(vals["description"])
	entry.Value = stringValue(vals["value"])
	if vals["type"] == nil {
		entry.SettingType = CFG_SETTING_TYPE_RAW
	} else {
		var ok bool
		typename := stringValue(vals["type"])
		entry.SettingType, ok = cfgSettingNameTypeMap[typename]
		if !ok {
			return entry, util.FmtNewtError(
				"setting %s specifies invalid type: %s", name, typename)
		}
	}
	entry.appendValue(lpkg, entry.Value)

	entry.Restrictions = []CfgRestriction{}
	restrictionStrings := cast.ToStringSlice(vals["restrictions"])
	for _, rstring := range restrictionStrings {
		r, err := readRestriction(name, rstring)
		if err != nil {
			return entry,
				util.PreNewtError(err, "error parsing setting %s", name)
		}
		entry.Restrictions = append(entry.Restrictions, r)
	}

	return entry, nil
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:34,代码来源:syscfg.go

示例10: Init

func (cpm *ConnProfileMgr) Init() error {
	filename, err := connProfileCfgFilename()
	if err != nil {
		return err
	}

	// XXX: Should determine whether file exists by attempting to read it.
	if util.NodeExist(filename) {
		blob, err := ioutil.ReadFile(filename)
		if err != nil {
			return util.NewNewtError(err.Error())
		}

		var profiles []*ConnProfile
		err = json.Unmarshal(blob, &profiles)
		if err != nil {
			return util.FmtNewtError("error reading connection profile "+
				"config (%s): %s", filename, err.Error())
		}

		for _, p := range profiles {
			cpm.profiles[p.MyName] = p
		}
	}

	return nil
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:27,代码来源:connprofile.go

示例11: loadError

func (mi *MfgImage) loadError(
	msg string, args ...interface{}) *util.NewtError {

	return util.FmtNewtError("Error in %s mfg: %s", mi.basePkg.Name(),
		fmt.Sprintf(msg, args...))

}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:7,代码来源:load.go

示例12: CreateMfgImage

// @return                      [paths-of-artifacts], error
func (mi *MfgImage) CreateMfgImage() ([]string, error) {
	cs, err := mi.build()
	if err != nil {
		return nil, err
	}

	sectionDir := MfgSectionBinDir(mi.basePkg.Name())
	if err := os.MkdirAll(sectionDir, 0755); err != nil {
		return nil, util.ChildNewtError(err)
	}

	for device, section := range cs.dsMap {
		sectionPath := MfgSectionBinPath(mi.basePkg.Name(), device)
		if err := ioutil.WriteFile(sectionPath, section, 0644); err != nil {
			return nil, util.ChildNewtError(err)
		}
	}

	manifest, err := mi.createManifest(cs)
	if err != nil {
		return nil, err
	}

	manifestPath := mi.ManifestPath()
	if err := ioutil.WriteFile(manifestPath, manifest, 0644); err != nil {
		return nil, util.FmtNewtError("Failed to write mfg manifest file: %s",
			err.Error())
	}

	return mi.ToPaths(), nil
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:32,代码来源:create.go

示例13: targetSyscfgKVFromStr

func targetSyscfgKVFromStr(str string) (map[string]string, error) {
	vals := map[string]string{}

	if strings.TrimSpace(str) == "" {
		return vals, nil
	}

	// Separate syscfg vals are delimited by ':'.
	fields := strings.Split(str, ":")

	// Key-value pairs are delimited by '='.  If no '=' is present, assume the
	// string is the key name and the value is 1.
	for _, f := range fields {
		if _, err := util.AtoiNoOct(f); err == nil {
			return nil, util.FmtNewtError(
				"Invalid setting name \"%s\"; must not be a number", f)
		}

		kv := strings.SplitN(f, "=", 2)
		switch len(kv) {
		case 1:
			vals[f] = "1"
		case 2:
			vals[kv[0]] = kv[1]
		}
	}

	return vals, nil
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:29,代码来源:target_cmds.go

示例14: areaNameFromImgIdx

func areaNameFromImgIdx(imgIdx int) (string, error) {
	switch imgIdx {
	case 0:
		return flash.FLASH_AREA_NAME_IMAGE_0, nil
	case 1:
		return flash.FLASH_AREA_NAME_IMAGE_1, nil
	default:
		return "", util.FmtNewtError("invalid image index: %d", imgIdx)
	}
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:10,代码来源:create.go

示例15: partFromImage

func (mi *MfgImage) partFromImage(
	imgPath string, flashAreaName string) (mfgPart, error) {

	part := mfgPart{
		// Boot loader and images always go in device 0.
		device: 0,
	}

	area, ok := mi.bsp.FlashMap.Areas[flashAreaName]
	if !ok {
		return part, util.FmtNewtError(
			"Image at \"%s\" requires undefined flash area \"%s\"",
			imgPath, flashAreaName)
	}

	part.name = fmt.Sprintf("%s (%s)", flashAreaName, filepath.Base(imgPath))
	part.offset = area.Offset

	var err error

	part.data, err = ioutil.ReadFile(imgPath)
	if err != nil {
		return part, util.ChildNewtError(err)
	}

	overflow := len(part.data) - area.Size
	if overflow > 0 {
		return part, util.FmtNewtError(
			"Image \"%s\" is too large to fit in flash area \"%s\"; "+
				"image-size=%d flash-area-size=%d overflow=%d",
			imgPath, flashAreaName, len(part.data), area.Size, overflow)
	}

	// If an image slot is used, the entire flash area is unwritable.  This
	// restriction comes from the boot loader's need to write status at the end
	// of an area.  Pad out part with unwriten flash (0xff).  This probably
	// isn't terribly efficient...
	for i := 0; i < -overflow; i++ {
		part.data = append(part.data, 0xff)
	}

	return part, nil
}
开发者ID:apache,项目名称:incubator-mynewt-newt,代码行数:43,代码来源:create.go


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