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

Remove panic from crdt.Tree and index.Tree #570

Merged
merged 16 commits into from
Jul 3, 2023
Merged

Conversation

JOOHOJANG
Copy link
Contributor

@JOOHOJANG JOOHOJANG commented Jul 3, 2023

What this PR does / why we need it:

  • Remove panic from crdt/tree, index/tree, element-rht and let them return error when it happens
  • let json/... handle error
    Which issue(s) this PR fixes:

Related to #497

Special notes for your reviewer:

Does this PR introduce a user-facing change?:


Additional documentation:


Checklist:

  • Added relevant tests or not required
  • Didn't break anything

@JOOHOJANG JOOHOJANG requested a review from hackerwins July 3, 2023 06:49
@JOOHOJANG JOOHOJANG removed the request for review from hackerwins July 3, 2023 06:54
@JOOHOJANG JOOHOJANG requested a review from hackerwins July 3, 2023 09:25
Copy link
Member

@hackerwins hackerwins left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution.

I did 3 additional minor code cleanups below.

A. We can omit the error checking if the interface of return of caller and method are the same and called it at the end.

AS-IS

func (n *TreeNode) Append(newNodes ...*TreeNode) error {
        // ...
	err := n.IndexTreeNode.Append(indexNodes...)
	if err != nil {
		return err
	}

	return nil
}

TO-BE

func (n *TreeNode) Append(newNodes ...*TreeNode) error {
        // ...
	return n.IndexTreeNode.Append(indexNodes...)
}

B. We can shorten it by binding the error checking with the method call.

https://www.digitalocean.com/community/tutorials/handling-errors-in-go#handling-errors

C. I removed panic from buildDescendants, because it has an interface with an error return.

api/converter/from_pb.go Outdated Show resolved Hide resolved
pkg/document/crdt/tree.go Outdated Show resolved Hide resolved
pkg/document/json/tree.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jul 3, 2023

Codecov Report

Merging #570 (1fda3a6) into main (aa2f361) will decrease coverage by 0.61%.
The diff coverage is 28.83%.

@@            Coverage Diff             @@
##             main     #570      +/-   ##
==========================================
- Coverage   51.91%   51.31%   -0.61%     
==========================================
  Files          67       67              
  Lines        6851     6949      +98     
==========================================
+ Hits         3557     3566       +9     
- Misses       2855     2915      +60     
- Partials      439      468      +29     
Impacted Files Coverage Δ
api/converter/from_pb.go 48.94% <0.00%> (-0.29%) ⬇️
pkg/document/crdt/text.go 57.84% <ø> (ø)
pkg/document/internal_document.go 21.66% <0.00%> (-0.37%) ⬇️
pkg/index/tree.go 47.90% <25.00%> (-2.27%) ⬇️
pkg/document/crdt/tree.go 53.25% <29.62%> (-11.15%) ⬇️
pkg/document/crdt/root.go 70.49% <33.33%> (-5.38%) ⬇️
pkg/document/document.go 45.12% <33.33%> (-2.32%) ⬇️
pkg/document/crdt/element_rht.go 62.85% <50.00%> (+0.53%) ⬆️
pkg/document/crdt/rga_tree_list.go 62.69% <50.00%> (+0.29%) ⬆️
pkg/document/crdt/array.go 32.07% <100.00%> (ø)
... and 2 more

@hackerwins hackerwins merged commit 3e34fc6 into main Jul 3, 2023
@hackerwins hackerwins deleted the remove-panic-from-code branch July 3, 2023 11:13
@hackerwins hackerwins changed the title Remove panic from code Remove panic from crdt.Tree and index.Tree Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants