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

Lab7- Errors #536

Merged
merged 4 commits into from
Sep 13, 2019
Merged

Lab7- Errors #536

merged 4 commits into from
Sep 13, 2019

Conversation

mohitnag
Copy link
Collaborator

@mohitnag mohitnag commented Jul 4, 2019

Fixes #535

Review of colleague's PR #534

Changes proposed in this PR:

  • Add Errors in Puppy Store.
  • Add mutex in sync store

@patrickmarabeas
Copy link
Collaborator

patrickmarabeas commented Jul 4, 2019

Don't forget to apply the correct labels on your PR. Also look at the PR markdown formatting - it's a little all over the place.

You could be more descriptive in the error handling that's been applied.

You have also included your lab 06 commit within this PR. This should be removed.

It would also be handy to split the initial c+p from Lab 06 into a separate commit so Lab 07's additions can be seen explicitly.

}

// MemStore stores Puppy details with Puppy Id as Key and Puppy as value
type MemStore map[uint32]Puppy
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be called MapStore

Copy link
Collaborator

Choose a reason for hiding this comment

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

This will need to be updated in Lab 07 as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

although naming is subjective. Still i will rename it as MapStore to make it more consistent with SyncStore

@mohitnag
Copy link
Collaborator Author

mohitnag commented Jul 5, 2019

I didnt add the label because i put the PR with 'WIP' tag. I will put the labels now. after doing the suggested changes

@codecov
Copy link

codecov bot commented Jul 5, 2019

Codecov Report

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

Impacted file tree graph

@@          Coverage Diff          @@
##           master   #536   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files         226    230    +4     
  Lines        4389   4460   +71     
=====================================
+ Hits         4389   4460   +71
Impacted Files Coverage Δ
07_errors/mohitnag/syncstore.go 100% <100%> (ø)
07_errors/mohitnag/mapstore.go 100% <100%> (ø)
07_errors/mohitnag/main.go 100% <100%> (ø)
07_errors/mohitnag/error.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 906e514...6efd14e. Read the comment docs.

@mohitnag mohitnag changed the title WIP- Lab7- Errors Lab7- Errors Aug 15, 2019
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.

Fix pr description markdown please.


const (
// InvalidValue is used when the puppy value is below 0
InvalidValue = "invalid input"
Copy link
Contributor

Choose a reason for hiding this comment

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

Invalid value sounds odd.
How about just invalid or invalidinput?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

m[p.ID] = p
return nil
}
return ErrorF(Duplicate, "puppy with Id %d already exists", p.ID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Imo invert logic: if ok... Then error.
It's more consistent with the ifs usually containing the error case and "bail early on error"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Completely agree.

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't look like this has been applied yet. Can you please do so?

}

// MapStore stores Puppy details with Puppy Id as Key and Puppy as value
type MapStore map[uint32]Puppy
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to mapstore.go
Same below

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

rokane
rokane previously requested changes Aug 26, 2019
Copy link
Member

@rokane rokane left a comment

Choose a reason for hiding this comment

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

Looking really good @mohitnag. I have left a couple of comments throughout, the main one which I thing should be addressed is the format of the messages, I feel that the code should be an int code. But please let me know if you think otherwise.

Duplicate = "puppy already exists"
)

// Error is the authorisationservice package error with a code for comparison
Copy link
Member

Choose a reason for hiding this comment

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

I think this comment should be updated. Reference to the authorisationservice package is external to this project and should not be assumed knowledge. Just provide a description of what the struct is.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done .


// ErrorF is a utility function creating an error with given code and message
func ErrorF(code, format string, args ...interface{}) *Error {
message := fmt.Sprintf(format, args...)
Copy link
Member

Choose a reason for hiding this comment

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

No need to declare a separate message variable if we can return straight away.

return &Error{Code: code, Message: fmt.Sprintf(format, args...)}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done

err := ErrorF(NotFound, "test error message")
assert.Equal(NotFound, err.Code)
assert.Equal("test error message", err.Message)
assert.Equal("test error message :(code: puppy not found)", err.Error())
Copy link
Member

Choose a reason for hiding this comment

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

I find this error message to be a bit misleading, and I think it comes from the fact that a string type is being used to store the code of the error. In my opinion I think a message format like below would be more appropriate:

assert.Equal("puppy not found (404)", err.Error())

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think error code in string type are more readable and easy to understand. However i do understand that int code like 404 is conventional. I would prefer keeping as it is, but let me know your thoughts and I will update accordingly.

m[p.ID] = p
return nil
}
return ErrorF(Duplicate, "puppy with Id %d already exists", p.ID)
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't look like this has been applied yet. Can you please do so?

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.

one final nit, feel free to ignore.

if _, ok := s.Load(p.ID); ok {
return ErrorF(Duplicate, "puppy with Id %d already exists", p.ID)
}
val, _ := strconv.Atoi(p.Value)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: might be dangerous to ignore the error here.

@mohitnag mohitnag merged commit 5b6045c into anz-bank:master Sep 13, 2019
@mohitnag mohitnag deleted the lab7 branch September 13, 2019 06:54
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
4 participants