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

refactor: Remove some possible panics from codebase #732

Merged
merged 5 commits into from
Aug 8, 2022

Conversation

AndrewSisley
Copy link
Contributor

@AndrewSisley AndrewSisley commented Aug 8, 2022

Relevant issue(s)

Part of #615

Description

Removes a handful of panics from our codebase. Avoids making breaking changes (see WARN commit - discussion required there as I do not know if this is public). Does not complete the issue as there are two panics listed within it that are not suitable for a patch release removing them would require a public function signature change.

TODO:

  • Resolve WARN commit discussion and squash/drop last commit as appropriate

numDocs property adds no value, and adds a new potential source of failure (if it becomes out of sync with the actual slice length).  Panics add no value as the panic that would otherwise happen (index out of bounds) is plenty clear enough anyway.  Returning error is not desired here as this struct is esentially an extension of a slice, and like slices index validation should be handled by callers - allowing them to determine whether it is safe or not to access elements without additional validation.
@AndrewSisley AndrewSisley added area/errors Related to the internal management or design of our error handling system refactor This issue specific to or requires *notable* refactoring of existing codebases and components action/no-benchmark Skips the action that runs the benchmark. labels Aug 8, 2022
@AndrewSisley AndrewSisley added this to the DefraDB v0.3.1 milestone Aug 8, 2022
@AndrewSisley AndrewSisley requested a review from a team August 8, 2022 12:34
@AndrewSisley AndrewSisley self-assigned this Aug 8, 2022
@AndrewSisley AndrewSisley linked an issue Aug 8, 2022 that may be closed by this pull request
11 tasks
Copy link
Member

@shahzadlone shahzadlone left a comment

Choose a reason for hiding this comment

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

Some non-blocking suggestions. I am not too concerned about the public signature changes, specially as we said we treat these patches like minor releases for now, and also these are very trivial changes IMO.

@@ -196,8 +196,8 @@ func newAllSortStrategy(v *valuesNode) *allSortStrategy {

// Add adds a new document to underlying valueNode
func (s *allSortStrategy) Add(doc core.Doc) error {
Copy link
Member

Choose a reason for hiding this comment

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

suggestion:

Suggested change
func (s *allSortStrategy) Add(doc core.Doc) error {
func (s *allSortStrategy) Add(doc core.Doc) {

Comment on lines 198 to +200
func (s *allSortStrategy) Add(doc core.Doc) error {
err := s.valueNode.docs.AddDoc(doc)
return err
s.valueNode.docs.AddDoc(doc)
return nil
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: don't need to return nil if remove error from signature (obv also need to update orderingStrategy interface signature and remove a check from orderNode.Next() if we do this.

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 wanted to keep the error on the interface in case future implementations wanted to return an err. Having written that out it seems very hypocritical of me, but TBH I don't think this really matters. Give me a shout if you have a strong enough preference for removal for me to bother.

Copy link
Member

Choose a reason for hiding this comment

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

No strong preference.

@AndrewSisley
Copy link
Contributor Author

I am not too concerned about the public signature changes, specially as we said we treat these patches like minor releases for now, and also these are very trivial changes IMO.

Public function signature changes are breaking changes and do not belong in minor releases.

@AndrewSisley AndrewSisley force-pushed the sisley/refactor/I615-panic-reduction branch from e95fdfb to b979f57 Compare August 8, 2022 13:26
@codecov
Copy link

codecov bot commented Aug 8, 2022

Codecov Report

Merging #732 (b979f57) into develop (7281889) will increase coverage by 0.04%.
The diff coverage is 68.42%.

❗ Current head b979f57 differs from pull request most recent head 87a0f61. Consider uploading reports for the commit 87a0f61 to get more accurate results

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #732      +/-   ##
===========================================
+ Coverage    57.44%   57.48%   +0.04%     
===========================================
  Files          143      143              
  Lines        16414    16390      -24     
===========================================
- Hits          9429     9422       -7     
+ Misses        6099     6085      -14     
+ Partials       886      883       -3     
Impacted Files Coverage Δ
cli/serverdump.go 15.78% <0.00%> (+0.40%) ⬆️
core/data.go 91.60% <ø> (+2.49%) ⬆️
net/utils/util.go 26.08% <ø> (+5.39%) ⬆️
api/http/handlerfuncs.go 88.09% <20.00%> (-2.21%) ⬇️
db/db.go 66.37% <80.00%> (+0.55%) ⬆️
db/container/container.go 100.00% <100.00%> (+15.38%) ⬆️
query/graphql/planner/order.go 83.15% <100.00%> (ø)
query/graphql/planner/pipe.go 85.00% <100.00%> (+5.93%) ⬆️
query/graphql/planner/values.go 78.26% <100.00%> (+1.44%) ⬆️
... and 2 more

@shahzadlone
Copy link
Member

I am not too concerned about the public signature changes, specially as we said we treat these patches like minor releases for now, and also these are very trivial changes IMO.

Public function signature changes are breaking changes and do not belong in minor releases.

The changes in this PR is fair game TBH.

@AndrewSisley AndrewSisley force-pushed the sisley/refactor/I615-panic-reduction branch from b979f57 to 87a0f61 Compare August 8, 2022 13:40
@AndrewSisley AndrewSisley merged commit 38613a5 into develop Aug 8, 2022
@AndrewSisley AndrewSisley deleted the sisley/refactor/I615-panic-reduction branch August 8, 2022 13:59
shahzadlone pushed a commit to shahzadlone/defradb that referenced this pull request Feb 23, 2024
* Assert span implements Span

* Remove dead span code

* Handle db.PrintDump errors

* Simplify doc container

numDocs property adds no value, and adds a new potential source of failure (if it becomes out of sync with the actual slice length).  Panics add no value as the panic that would otherwise happen (index out of bounds) is plenty clear enough anyway.  Returning error is not desired here as this struct is esentially an extension of a slice, and like slices index validation should be handled by callers - allowing them to determine whether it is safe or not to access elements without additional validation.

* Remove unused utils function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action/no-benchmark Skips the action that runs the benchmark. area/errors Related to the internal management or design of our error handling system refactor This issue specific to or requires *notable* refactoring of existing codebases and components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Panic reduction
2 participants