本文整理汇总了Golang中mynewt/apache/org/newt/util.NewNewtError函数的典型用法代码示例。如果您正苦于以下问题:Golang NewNewtError函数的具体用法?Golang NewNewtError怎么用?Golang NewNewtError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewNewtError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: GenDepsForFile
// Generates a dependency Makefile (.d) for the specified source C file.
//
// @param file The name of the source file.
func (c *Compiler) GenDepsForFile(file string) error {
if util.NodeNotExist(c.dstDir) {
os.MkdirAll(c.dstDir, 0755)
}
depFile := c.dstDir + "/" +
strings.TrimSuffix(file, filepath.Ext(file)) + ".d"
depFile = filepath.ToSlash(depFile)
var cmd string
var err error
cmd = c.ccPath + " " + c.cflagsString() + " " + c.includesString() +
" -MM -MG " + file + " > " + depFile
o, err := util.ShellCommand(cmd)
if err != nil {
return util.NewNewtError(string(o))
}
// Append the extra dependencies (.yml files) to the .d file.
f, err := os.OpenFile(depFile, os.O_APPEND|os.O_WRONLY, 0666)
if err != nil {
return util.NewNewtError(err.Error())
}
defer f.Close()
objFile := strings.TrimSuffix(file, filepath.Ext(file)) + ".o"
if _, err := f.WriteString(objFile + ": " + c.depsString()); err != nil {
return util.NewNewtError(err.Error())
}
return nil
}
示例2: ResolveNewTargetName
func ResolveNewTargetName(name string) (string, error) {
repoName, pkgName, err := newtutil.ParsePackageString(name)
if err != nil {
return "", err
}
if repoName != "" {
return "", util.NewNewtError("Target name cannot contain repo; " +
"must be local")
}
if pkgName == TARGET_KEYWORD_ALL {
return "", util.NewNewtError("Target name " + TARGET_KEYWORD_ALL +
" is reserved")
}
// "Naked" target names translate to "targets/<name>".
if !strings.Contains(pkgName, "/") {
pkgName = TARGET_DEFAULT_DIR + "/" + pkgName
}
if target.GetTargets()[pkgName] != nil {
return "", util.NewNewtError("Target already exists: " + pkgName)
}
return pkgName, nil
}
示例3: readTlv
func (cc *CoreConvert) readTlv() (*CoreDumpTlv, error) {
var tlv CoreDumpTlv
tlv_buf := make([]byte, binary.Size(tlv))
if tlv_buf == nil {
return nil, util.NewNewtError("Out of memory")
}
cnt, err := cc.Source.Read(tlv_buf)
if err == io.EOF {
return nil, nil
}
if err != nil {
return nil, util.NewNewtError(fmt.Sprintf("Error reading: %s",
err.Error()))
}
if cnt == 0 {
return nil, nil
}
if cnt != binary.Size(tlv) {
return nil, util.NewNewtError("Short read")
}
tlv.Type = uint8(tlv_buf[0])
tlv.pad = uint8(tlv_buf[1])
tlv.Len = binary.LittleEndian.Uint16(tlv_buf[2:4])
tlv.Off = binary.LittleEndian.Uint32(tlv_buf[4:8])
return &tlv, nil
}
示例4: cleanRunCmd
func cleanRunCmd(cmd *cobra.Command, args []string) {
if len(args) < 1 {
NewtUsage(cmd, util.NewNewtError("Must specify target"))
}
InitProject()
cleanAll := false
targets := []*target.Target{}
for _, arg := range args {
if arg == TARGET_KEYWORD_ALL {
cleanAll = true
} else {
t := ResolveTarget(arg)
if t == nil {
NewtUsage(cmd, util.NewNewtError("invalid target name: "+arg))
}
targets = append(targets, t)
}
}
if cleanAll {
cleanDir(builder.BinRoot())
} else {
for _, t := range targets {
cleanDir(builder.TargetBinDir(t.Name()))
}
}
}
示例5: EnsureWritten
func EnsureWritten(pkgs []*pkg.LocalPackage, srcDir string, targetName string,
isLoader bool) error {
buf := bytes.Buffer{}
write(pkgs, isLoader, &buf)
var path string
if isLoader {
path = fmt.Sprintf("%s/%s-sysinit-loader.c", srcDir, targetName)
} else {
path = fmt.Sprintf("%s/%s-sysinit-app.c", srcDir, targetName)
}
writeReqd, err := writeRequired(buf.Bytes(), path)
if err != nil {
return err
}
if !writeReqd {
log.Debugf("sysinit unchanged; not writing src file (%s).", path)
return nil
}
log.Debugf("sysinit changed; writing src file (%s).", path)
if err := os.MkdirAll(filepath.Dir(path), 0755); err != nil {
return util.NewNewtError(err.Error())
}
if err := ioutil.WriteFile(path, buf.Bytes(), 0644); err != nil {
return util.NewNewtError(err.Error())
}
return nil
}
示例6: DecodeFileDownloadResponse
func DecodeFileDownloadResponse(data []byte) (*FileDownload, error) {
type DownloadResp struct {
Off uint32 `json:"off"`
Size uint32 `json:"len"`
Data []byte `json:"data"`
ReturnCode int `json:"rc"`
}
resp := &DownloadResp{}
dec := codec.NewDecoderBytes(data, new(codec.CborHandle))
err := dec.Decode(&resp)
if err != nil {
return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming cbor: %s",
err.Error()))
}
if resp.ReturnCode != 0 {
return nil, util.NewNewtError(fmt.Sprintf("Target error: %d",
resp.ReturnCode))
}
if err != nil {
return nil, util.NewNewtError(fmt.Sprintf("Invalid incoming json: %s",
err.Error()))
}
f := &FileDownload{
Offset: resp.Off,
Data: resp.Data,
Size: resp.Size,
}
return f, nil
}
示例7: EncodeEchoCtrl
func (e *Echo) EncodeEchoCtrl() (*NmgrReq, error) {
type SerialEchoCtl struct {
Echo int `codec:"echo"`
}
integer, err := strconv.Atoi(e.Message)
if err != nil {
return nil, util.NewNewtError(fmt.Sprintf("Invalid echo ctrl setting %s",
err.Error()))
}
echoCtl := &SerialEchoCtl{
Echo: integer,
}
nmr, err := NewNmgrReq()
if err != nil {
return nil, err
}
nmr.Op = NMGR_OP_WRITE
nmr.Flags = 0
nmr.Group = NMGR_GROUP_ID_DEFAULT
nmr.Id = NMGR_ID_CONS_ECHO_CTRL
data := make([]byte, 0)
enc := codec.NewEncoderBytes(&data, new(codec.CborHandle))
if err := enc.Encode(echoCtl); err != nil {
return nil, util.NewNewtError(fmt.Sprintf("Failed to encode message %s",
err.Error()))
}
nmr.Len = uint16(len(data))
nmr.Data = data
return nmr, nil
}
示例8: 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
}
示例9: SaveSyscfgVals
func (lpkg *LocalPackage) SaveSyscfgVals() error {
dirpath := lpkg.BasePath()
if err := os.MkdirAll(dirpath, 0755); err != nil {
return util.NewNewtError(err.Error())
}
filepath := dirpath + "/" + SYSCFG_YAML_FILENAME
syscfgVals := lpkg.SyscfgV.GetStringMapString("syscfg.vals")
if syscfgVals == nil || len(syscfgVals) == 0 {
os.Remove(filepath)
return nil
}
file, err := os.Create(filepath)
if err != nil {
return util.NewNewtError(err.Error())
}
defer file.Close()
names := make([]string, 0, len(syscfgVals))
for k, _ := range syscfgVals {
names = append(names, k)
}
sort.Strings(names)
fmt.Fprintf(file, "### Package: %s\n", lpkg.Name())
fmt.Fprintf(file, "\n")
fmt.Fprintf(file, "syscfg.vals:\n")
for _, name := range names {
fmt.Fprintf(file, " %s: %s\n", name, syscfgVals[name])
}
return nil
}
示例10: Sync
func (r *Repo) Sync(vers *Version, force bool) (error, bool) {
var exists bool
var err error
if err, exists = r.checkForceInstall(force); err != nil {
return err, exists
}
if exists && !force {
return nil, exists
}
// Update the repo description
if _, updated, err := r.UpdateDesc(); updated != true || err != nil {
return util.NewNewtError("Cannot update repository description."), exists
}
branchName, vers, found := r.rdesc.MatchVersion(vers)
if found == false {
return util.NewNewtError(fmt.Sprintf("Branch description for %s not found",
r.Name())), exists
}
if err := r.downloadRepo(branchName); err != nil {
return err, exists
}
return nil, exists
}
示例11: Install
func (r *Repo) Install(force bool) (*Version, error) {
if err, exists := r.checkForceInstall(force); err != nil || exists {
if err == nil {
if !force {
return nil, util.NewNewtError(fmt.Sprintf(
"Repository %s already exists, provide the -f option "+
"to overwrite", r.Name()))
}
} else {
return nil, err
}
}
branchName, vers, found := r.rdesc.Match(r)
if !found {
return nil, util.NewNewtError(fmt.Sprintf("No repository matching description %s found",
r.rdesc.String()))
}
if err := r.downloadRepo(branchName); err != nil {
return nil, err
}
return vers, nil
}
示例12: createSplitArchiveLinkerFile
/* this create a new library combining all of the other libraries */
func createSplitArchiveLinkerFile(archiveFile string,
archFiles []string) error {
/* create a name for this script */
ar_script_name := linkerScriptFileName(archiveFile)
// open the file and write out the script
f, err := os.OpenFile(ar_script_name, os.O_CREATE|os.O_WRONLY, 0666)
if err != nil {
return util.NewNewtError(err.Error())
}
defer f.Close()
if _, err := f.WriteString("CREATE " + archiveFile + "\n"); err != nil {
return util.NewNewtError(err.Error())
}
for _, arch := range archFiles {
if _, err := f.WriteString("ADDLIB " + arch + "\n"); err != nil {
return util.NewNewtError(err.Error())
}
}
if _, err := f.WriteString("SAVE\n"); err != nil {
return util.NewNewtError(err.Error())
}
if _, err := f.WriteString("END\n"); err != nil {
return util.NewNewtError(err.Error())
}
return nil
}
示例13: loadConfig
func (proj *Project) loadConfig() error {
v, err := util.ReadConfig(proj.BasePath,
strings.TrimSuffix(PROJECT_FILE_NAME, ".yml"))
if err != nil {
return util.NewNewtError(err.Error())
}
// Store configuration object for access to future values,
// this avoids keeping every string around as a project variable when
// we need to process it later.
proj.v = v
proj.projState, err = LoadProjectState()
if err != nil {
return err
}
proj.name = v.GetString("project.name")
// Local repository always included in initialization
r, err := repo.NewLocalRepo(proj.name)
if err != nil {
return err
}
proj.repos[proj.name] = r
proj.localRepo = r
for _, ignDir := range ignoreSearchDirs {
r.AddIgnoreDir(ignDir)
}
rstrs := v.GetStringSlice("project.repositories")
for _, repoName := range rstrs {
if err := proj.loadRepo(repoName, v); err != nil {
return err
}
}
ignoreDirs := v.GetStringSlice("project.ignore_dirs")
for _, ignDir := range ignoreDirs {
repoName, dirName, err := newtutil.ParsePackageString(ignDir)
if err != nil {
return err
}
if repoName == "" {
r = proj.LocalRepo()
} else {
r = proj.FindRepo(repoName)
}
if r == nil {
return util.NewNewtError(
fmt.Sprintf("ignore_dirs: unknown repo %s", repoName))
}
r.AddIgnoreDir(dirName)
}
return nil
}
示例14: Convert
func (cc *CoreConvert) Convert() error {
if cc.Source == nil || cc.Target == nil {
return util.NewNewtError("Missing file parameters")
}
err := cc.readHdr()
if err != nil {
return err
}
for {
tlv, err := cc.readTlv()
if err != nil {
return err
}
if tlv == nil {
break
}
data_buf := make([]byte, tlv.Len)
cnt, err := cc.Source.Read(data_buf)
if err != nil {
return util.NewNewtError(fmt.Sprintf("Error reading: %s",
err.Error()))
}
if cnt != int(tlv.Len) {
return util.NewNewtError("Short file")
}
switch tlv.Type {
case COREDUMP_TLV_MEM:
cc.makeProgHdr(tlv.Off, data_buf)
case COREDUMP_TLV_IMAGE:
cc.ImageHash = data_buf
case COREDUMP_TLV_REGS:
if tlv.Len%4 != 0 {
return util.NewNewtError("Invalid register area size")
}
cc.makeRegInfo(data_buf)
default:
return util.NewNewtError("Unknown TLV type")
}
}
cc.makeElfHdr()
if err != nil {
return err
}
cc.setProgHdrOff()
binary.Write(cc.Target, binary.LittleEndian, cc.elfHdr)
for _, phdr := range cc.phdrs {
binary.Write(cc.Target, binary.LittleEndian, phdr)
}
for _, data := range cc.data {
cc.Target.Write(data)
}
return nil
}
示例15: dateTimeCmd
func dateTimeCmd(cmd *cobra.Command, args []string) {
runner, err := getTargetCmdRunner()
if err != nil {
nmUsage(cmd, err)
}
defer runner.Conn.Close()
dateTime, err := protocol.NewDateTime()
if err != nil {
nmUsage(cmd, err)
}
if len(args) > 0 {
dateTime.DateTime = args[0]
}
nmr, err := dateTime.EncodeRequest()
if err != nil {
nmUsage(cmd, err)
}
if err := runner.WriteReq(nmr); err != nil {
nmUsage(cmd, err)
}
rsp, err := runner.ReadResp()
if err != nil {
nmUsage(cmd, err)
}
iRsp, err := protocol.DecodeDateTimeResponse(rsp.Data)
if err != nil {
nmUsage(cmd, err)
}
err_str := "Command: datetime\n" +
"For writing datetime <argument>\n" +
"Need to specify a datetime in RFC 3339 format\n" +
"2016-03-02T22:44:00 UTC time (implicit)\n" +
"2016-03-02T22:44:00Z UTC time (explicit)\n" +
"2016-03-02T22:44:00-08:00 PST timezone\n" +
"2016-03-02T22:44:00.1 fractional seconds\n" +
"2016-03-02T22:44:00.101+05:30 fractional seconds with timezone\n"
if len(args) > 1 {
nmUsage(cmd, util.NewNewtError(err_str))
} else if len(args) == 1 {
if iRsp.Return != 0 {
nmUsage(cmd, util.NewNewtError(fmt.Sprintf("Return:%d\n%s",
iRsp.Return, err_str)))
} else {
fmt.Println("Return:", iRsp.Return)
}
} else if len(args) == 0 {
fmt.Println("Datetime(RFC 3339 format):", iRsp.DateTime)
}
}