Skip to content
This repository was archived by the owner on Jul 15, 2018. It is now read-only.

New Error#180

Merged
jaekwon merged 2 commits intodevelopfrom
jae/errors
Mar 24, 2018
Merged

New Error#180
jaekwon merged 2 commits intodevelopfrom
jae/errors

Conversation

@jaekwon
Copy link
Contributor

@jaekwon jaekwon commented Mar 24, 2018

This replaces pkg/errors.
Intent is so we can call cmn.ErrorWrap instead of errors.Wrap.
This should be more performant, as it doesn't require capturing a stacktrace each wrap.

common/errors.go Outdated
TraceAt(n int, format string, a ...interface{}) Error
Cause() interface{}
WithType(t interface{}) Error
Type() interface{}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a better name? Switcher?
switch err.Type().(type) is redundant...
switch err.Switcher().(type) is also redundant...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd vote for the first option (maybe even shorten it to err.T().(type). go is redundant language (obj.(Object).SomeMethod).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like "T" a lot. It differentiates it from the "type" keyword.

@codecov-io
Copy link

codecov-io commented Mar 24, 2018

Codecov Report

Merging #180 into develop will increase coverage by 1.18%.
The diff coverage is 90.9%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #180      +/-   ##
===========================================
+ Coverage    61.25%   62.43%   +1.18%     
===========================================
  Files           60       60              
  Lines         4617     4651      +34     
===========================================
+ Hits          2828     2904      +76     
+ Misses        1563     1524      -39     
+ Partials       226      223       -3
Impacted Files Coverage Δ
common/errors.go 76.92% <90.9%> (+76.92%) ⬆️
common/os.go 21.69% <0%> (+2.65%) ⬆️
common/string.go 78.94% <0%> (+15.78%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c0549ec...9046a07. Read the comment docs.

common/errors.go Outdated
// Convenience methods

// ErrorWrap will just call .TraceAt(), or create a new *cmnError.
func ErrorWrap(cause interface{}, format string, a ...interface{}) Error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

args ... please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

//----------------------------------------
// Error & cmnError

/*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not move this to errors subpackage? then it can be errors.Wrap

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmlibs errors? I'm down for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, because cmn is convenient... if we want to have cmn, then it's more convenient to do cmn.ErrorWrap, than importing another module.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue that Go2 should support Error natively... so I'd want it in cmn.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.. cmn.ErrorWrap is fine too

common/errors.go Outdated
TraceCause(cause error, format string, a ...interface{}) Error
Cause() error
Type() interface{}
TraceAt(n int, format string, a ...interface{}) Error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TraceFrom(level int or TraceFrom(depth int

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k

common/errors.go Outdated
TraceAt(n int, format string, a ...interface{}) Error
Cause() interface{}
WithType(t interface{}) Error
Type() interface{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd vote for the first option (maybe even shorten it to err.T().(type). go is redundant language (obj.(Object).SomeMethod).

common/errors.go Outdated
traces []traceItem
msg string // first msg which also appears in msg
cause interface{} // underlying cause (or panic object)
type_ interface{} // for switching on error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's up with _?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't use "type" as field name

common/errors.go Outdated
// Captures a stacktrace if one was not already captured.
func (err *cmnError) Stacktrace() Error {
if err.stacktrace == nil {
err.stacktrace = captureStacktrace(3, 32)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

magic numbers

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the 3 I think arguably should be magic, though it deserves comments. I'll move the 32 out.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you don't have to move them out, you can do

var offset = 3
const defaultDepth = 32

inside the function

@jaekwon jaekwon merged commit 87c0473 into develop Mar 24, 2018
@jaekwon jaekwon deleted the jae/errors branch March 24, 2018 21:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants