• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang errors.ErrorClass类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/spacemonkeygo/errors.ErrorClass的典型用法代码示例。如果您正苦于以下问题:Golang ErrorClass类的具体用法?Golang ErrorClass怎么用?Golang ErrorClass使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: ShouldBeErrorClass

/*
	'actual' should be an `*errors.Error`; 'expected' should be an `*errors.ErrorClass`;
	we'll check that the error is under the umbrella of the error class.
*/
func ShouldBeErrorClass(actual interface{}, expected ...interface{}) string {
	err, ok := actual.(error)
	if !ok {
		return fmt.Sprintf("You must provide an `error` as the first argument to this assertion; got `%T`", actual)
	}

	var class *errors.ErrorClass
	switch len(expected) {
	case 0:
		return "You must provide a spacemonkey `ErrorClass` as the expectation parameter to this assertion."
	case 1:
		cls, ok := expected[0].(*errors.ErrorClass)
		if !ok {
			return "You must provide a spacemonkey `ErrorClass` as the expectation parameter to this assertion."
		}
		class = cls
	default:
		return "You must provide one parameter as an expectation to this assertion."
	}

	// checking if this is nil is surprisingly complicated due to https://golang.org/doc/faq#nil_error
	if reflect.ValueOf(err).IsNil() {
		return fmt.Sprintf("Expected error to be of class %q but it was nil!", class.String())
	}

	spaceClass := errors.GetClass(err)
	if spaceClass.Is(class) {
		return ""
	}
	return fmt.Sprintf("Expected error to be of class %q but it had %q instead!  (Full message: %s)", class.String(), spaceClass.String(), err.Error())
}
开发者ID:kkroening,项目名称:repeatr,代码行数:35,代码来源:assertions.go


示例2: ShouldPanicWith

/*
	'actual' should be a `func()`; 'expected' should be an `*errors.ErrorClass`;
	we'll run the function, and check that it panics, and that the error is under the umbrella of the error class.
*/
func ShouldPanicWith(actual interface{}, expected ...interface{}) string {
	fn, ok := actual.(func())
	if !ok {
		return fmt.Sprintf("You must provide a `func()` as the first argument to this assertion; got `%T`", actual)
	}

	var errClass *errors.ErrorClass
	switch len(expected) {
	case 0:
		return "You must provide a spacemonkey `ErrorClass` as the expectation parameter to this assertion."
	case 1:
		cls, ok := expected[0].(*errors.ErrorClass)
		if !ok {
			return "You must provide a spacemonkey `ErrorClass` as the expectation parameter to this assertion."
		}
		errClass = cls
	default:
		return "You must provide one parameter as an expectation to this assertion."
	}

	var caught error
	try.Do(
		fn,
	).CatchAll(func(err error) {
		caught = err
	}).Done()

	if caught == nil {
		return fmt.Sprintf("Expected error to be of class %q but no error was raised!", errClass.String())
	}
	spaceClass := errors.GetClass(caught)
	if spaceClass.Is(errClass) {
		return ""
	}
	return fmt.Sprintf("Expected error to be of class %q but it had %q instead!  (Full message: %s)", errClass.String(), spaceClass.String(), caught.Error())
}
开发者ID:kkroening,项目名称:repeatr,代码行数:40,代码来源:assertions.go


示例3: SetExitCode

	EXIT_JOB          = ExitCode(10) // used to indicate a job reported a nonzero exit code (from cli commands that execute a single job).
)

var ExitCodeKey = errors.GenSym()

/*
	CLI errors are the last line: they should be formatted to be user-facing.
	The main method will convert a CLIError into a short and well-formatted
	message, and will *not* include stack traces unless the user is running
	with debug mode enabled.

	CLI errors are an appropriate wrapping for anything where we can map a
	problem onto something the user can understand and fix.  Errors that are
	a repeatr bug or unknown territory should *not* be mapped into a CLIError.
*/
var Error *errors.ErrorClass = errors.NewClass("CLIError")

/*
	Use this to set a specific error code the process should exit with
	when producing a `cli.Error`.

	Example: `cli.Error.NewWith("something terrible!", SetExitCode(EXIT_BADARGS))`
*/
func SetExitCode(code ExitCode) errors.ErrorOption {
	return errors.SetData(ExitCodeKey, code)
}

/*
	Exit errors may be raised to immediately transition to we're done (and
	specify an `ExitCode`), but generate slightly less of a sadface than
	`cli.Error`: use them for graceful exits.
开发者ID:kkroening,项目名称:repeatr,代码行数:31,代码来源:errors.go


示例4:

package scheduler

import (
	"github.com/spacemonkeygo/errors"
)

// grouping, do not instantiate
var Error *errors.ErrorClass = errors.NewClass("SchedulerError")

// error when a scheduler's queue was full and could not enqueue a forumla.
var QueueFullError *errors.ErrorClass = Error.NewClass("QueueFullError")
开发者ID:kkroening,项目名称:repeatr,代码行数:11,代码来源:errors.go


示例5:

}

/*
	RecordIterator is used for walking Bucket contents in hash-ready order.
	It's specified separately from Record for three reasons: There will be many
	Record objects, and so they should be small (the iterators tend to require
	at least another two words of memory); and the Record objects are
	serializable the same way for all implementations of Bucket (the iterators
	may work differently depending on how data is heaped in the Bucket impl).
*/
type RecordIterator interface {
	treewalk.Node
	Record() Record
}

var InvalidFilesystem *errors.ErrorClass = errors.NewClass("InvalidFilesystem")

/*
	PathCollision is reported when the same file path is submitted to a `Bucket`
	more than once.  (Some formats, for example tarballs, allow the same filename
	to be recorded twice.  We consider this poor behavior since most actual
	filesystems of course will not tolerate this, and also because it begs the
	question of which should be sorted first when creating a deterministic
	hash of the whole tree.)
*/
var PathCollision *errors.ErrorClass = InvalidFilesystem.NewClass("PathCollision")

/*
	MissingTree is reported when iteration over a filled bucket encounters
	a file that has no parent nodes.  I.e., if there's a file path "./a/b",
	and there's no entries for "./a", it's a MissingTree error.
开发者ID:kkroening,项目名称:repeatr,代码行数:31,代码来源:bucket.go


示例6: ioError

package fs

import (
	"github.com/spacemonkeygo/errors"
)

var Error *errors.ErrorClass = errors.NewClass("FSError") // grouping, do not instantiate

/*
	`BreakoutError` is raised when processing a filesystem description where links
	(symlinks, hardlinks) are constructed in such a way that they would reach
	out of the base directory.  Encountering these in a well-formed filesystem
	description is basically an attempted attack.
*/
var BreakoutError *errors.ErrorClass = Error.NewClass("FSBreakoutError")

func ioError(err error) {
	panic(Error.Wrap(errors.IOError.Wrap(err)))
}
开发者ID:kkroening,项目名称:repeatr,代码行数:19,代码来源:errors.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang utils.ErrorGroup类代码示例发布时间:2022-05-28
下一篇:
Golang key.Key类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap