-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lab 7 - Errors #573
Lab 7 - Errors #573
Conversation
7d37597
to
0f76be8
Compare
Codecov Report
@@ Coverage Diff @@
## master #573 +/- ##
======================================
Coverage 100% 100%
======================================
Files 191 156 -35
Lines 3611 2841 -770
======================================
- Hits 3611 2841 -770
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few generic comments:
- Rework errors a little please
- Handle errors, at least return them. Don't just log them (of if so only on the very top level).
- Doc strings on public types and functions
- Please add comments from lab 6 here too.
07_errors/kasunfdo/leveldbstore.go
Outdated
log.Printf("Initialized store with index: %v\n", store.count) | ||
return store, nil | ||
} | ||
logrus.Debug(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return on error instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @juliaogris ,
Any hint on testing error paths? I couldn't hit some of the error paths and that causes the build failure due to lack of code coverage.
07_errors/kasunfdo/leveldbstore.go
Outdated
logrus.Debug(err) | ||
|
||
value, err := db.Get([]byte(store.indexName), nil) | ||
logrus.Debug(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return on error?
07_errors/kasunfdo/leveldbstore.go
Outdated
logrus.Debug(err) | ||
|
||
store.count, err = strconv.ParseUint(string(value), 10, 64) | ||
log.Printf("Initialized store with index: %v", store.count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return on error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or panic.
07_errors/kasunfdo/error.go
Outdated
} | ||
|
||
func NewError(code int, args ...interface{}) *Error { | ||
return &Error{Code: code, Message: fmt.Sprintf(ErrStr[code], args...)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this should be something like the following (doesn't compile as Cause is only partially folded in)/.
type ErrCode uint8
const (
ErrInvalidInput ErrCode = 400
// ...
)
func (e ErrCode) String() string {
switch e {
case ErrInvalidInput:
return "invalid input"
// ....
}
}
NewError(code int, msg string, args ...interface{}) *Error {
return &Error{
Message: fmt.Sprintf(format, args...),
Code: code,
}
}
type Error struct {
Message string
Code ErrCode
Cause error // can be useful if wrapping underlying error
}
func (e *Error) Error() string {
msg := fmt.Sprintf("%s: %s", e.Code.String(), e.Message)
if e.Cause == nil {
return msg
}
return fmt.Sprintf("%s\n\t%s", msg, e.Cause.Error())
}
eb3db45
to
43bb19c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice work doing the bonus requirement for LevelDB!
Codecov Report
@@ Coverage Diff @@
## master #573 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 204 208 +4
Lines 3865 3942 +77
=====================================
+ Hits 3865 3942 +77
Continue to review full report at Codecov.
|
9359085
to
9bb23cf
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work!
Fixes #572
Review of colleague's PR #574
Changes proposed in this PR: