Skip to content
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

Merged
merged 2 commits into from
Sep 1, 2019
Merged

Lab 7 - Errors #573

merged 2 commits into from
Sep 1, 2019

Conversation

kasunfdo
Copy link
Collaborator

@kasunfdo kasunfdo commented Aug 9, 2019

Fixes #572

Review of colleague's PR #574

Changes proposed in this PR:

  • Implement errors
  • Implement leveldb Storer
  • Add locking for sync.Map

@kasunfdo kasunfdo force-pushed the lab7 branch 2 times, most recently from 7d37597 to 0f76be8 Compare August 9, 2019 06:09
@codecov
Copy link

codecov bot commented Aug 9, 2019

Codecov Report

Merging #573 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master   #573    +/-   ##
======================================
  Coverage     100%   100%            
======================================
  Files         191    156    -35     
  Lines        3611   2841   -770     
======================================
- Hits         3611   2841   -770
Impacted Files Coverage Δ
07_errors/kasunfdo/syncstore.go 100% <100%> (ø)
07_errors/kasunfdo/error.go 100% <100%> (ø)
07_errors/kasunfdo/main.go 100% <100%> (ø)
07_errors/kasunfdo/mapstore.go 100% <100%> (ø)
07_errors/kasunfdo/leveldbstore.go 100% <100%> (ø)
08_project/runnerdave/cmd/puppy-server/main.go
08_project/runnerdave/pkg/puppy/store/map_store.go
11_notify/n0npax/pkg/puppy/store/memStore.go
11_notify/n0npax/pkg/puppy/rest.go
09_json/n0npax/pkg/puppy/store/syncStore.go
... and 40 more

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 d5be3ba...f2a3545. Read the comment docs.

Copy link
Contributor

@juliaogris juliaogris left a 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.

log.Printf("Initialized store with index: %v\n", store.count)
return store, nil
}
logrus.Debug(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Return on error instead?

Copy link
Collaborator Author

@kasunfdo kasunfdo Aug 26, 2019

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.

logrus.Debug(err)

value, err := db.Get([]byte(store.indexName), nil)
logrus.Debug(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

return on error?

logrus.Debug(err)

store.count, err = strconv.ParseUint(string(value), 10, 64)
log.Printf("Initialized store with index: %v", store.count)
Copy link
Contributor

Choose a reason for hiding this comment

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

return 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.

or panic.

}

func NewError(code int, args ...interface{}) *Error {
return &Error{Code: code, Message: fmt.Sprintf(ErrStr[code], args...)}
Copy link
Contributor

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())
}

Copy link
Collaborator

@nicko-lee nicko-lee left a 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-io
Copy link

codecov-io commented Aug 27, 2019

Codecov Report

Merging #573 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #573   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files         204    208    +4     
  Lines        3865   3942   +77     
=====================================
+ Hits         3865   3942   +77
Impacted Files Coverage Δ
07_errors/kasunfdo/error.go 100% <100%> (ø)
07_errors/kasunfdo/syncstore.go 100% <100%> (ø)
07_errors/kasunfdo/main.go 100% <100%> (ø)
07_errors/kasunfdo/mapstore.go 100% <100%> (ø)

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 00b50aa...52e83e6. Read the comment docs.

@kasunfdo kasunfdo force-pushed the lab7 branch 3 times, most recently from 9359085 to 9bb23cf Compare August 27, 2019 23:29
Copy link
Contributor

@juliaogris juliaogris left a comment

Choose a reason for hiding this comment

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

Great work!

@kasunfdo kasunfdo merged commit 14cef3d into anz-bank:master Sep 1, 2019
BaiJieCN pushed a commit to BaiJieCN/go-course that referenced this pull request Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lab 7 - Errors
5 participants