-
-
Notifications
You must be signed in to change notification settings - Fork 148
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 primitive #636
Remove panic from crdt primitive #636
Conversation
@fourjae I think we need to change In #522, we changed Changing |
As we progressed, we encountered this problem. What do you think? I'm trying to fix crdt/primitive marshal(), but I have the following problem.
As a result, all String() methods must be changed to handle errors in marshal(). Do you have any good troubleshooting methods? |
@hackerwins Any ideas on this issue? |
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.
For discussion record: It will be nice to move panic()
to the json
layer so that we can catch errors at the json
level and change types in the crdt
layer to never emit errors on the crdt
layer. This will prevent interface changes on crdt
layer.
5b78e7d
to
bb79fcd
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #636 +/- ##
==========================================
- Coverage 49.47% 49.31% -0.16%
==========================================
Files 69 69
Lines 9951 9973 +22
==========================================
- Hits 4923 4918 -5
- Misses 4512 4532 +20
- Partials 516 523 +7
☔ View full report in Codecov by Sentry. |
There were things I didn't know about, and after analyzing them, I came to the following conclusion and changed it to PR.
Therefore, the (p *Primitive) |
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.
Thank you for your contribution.
I left some comments below.
Changing mismatched code conventions and changing err handling
Thanks for your comment! Fixed code conventions that did not fit. The hard-coded err message has been changed to return an err variable. Please let me know if you need any additional changes. |
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.
Thank you for reflecting my review.
I left just few more comments 😄
pkg/document/json/array.go
Outdated
@@ -194,7 +227,6 @@ func (p *Array) addInternal( | |||
) crdt.Element { | |||
return p.insertAfterInternal(p.Array.LastCreatedAt(), creator) | |||
} | |||
|
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.
It will be nice to have space between functions
@@ -120,34 +124,47 @@ func (p *Object) SetNewTree(k string, initialRoot ...*TreeNode) *Tree { | |||
// SetNull sets the null for the given key. | |||
func (p *Object) SetNull(k string) *Object { | |||
p.setInternal(k, func(ticket *time.Ticket) crdt.Element { | |||
return crdt.NewPrimitive(nil, ticket) |
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.
It will be nice to keep space convention of spacing before return
in this file. I will leave only one comment for this, so check all the return
codes in this file.
pkg/document/crdt/primitive.go
Outdated
} | ||
|
||
// Marshal returns the JSON encoding of the value. | ||
func (p *Primitive) Marshal() string { | ||
switch p.valueType { | ||
case Null: | ||
return "null" | ||
return "" |
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.
Is there any reason for this change? I will be better to keep the previous code.
pkg/document/crdt/primitive_test.go
Outdated
@@ -34,7 +34,7 @@ func TestPrimitive(t *testing.T) { | |||
valueType crdt.ValueType | |||
marshal string | |||
}{ | |||
{nil, crdt.Null, "null"}, | |||
{nil, crdt.Null, ""}, |
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.
Is there any reason for this change? I will be better to keep the previous code.
It will be better to revert this code too.
pkg/document/crdt/primitive.go
Outdated
@@ -213,9 +213,10 @@ func (p *Primitive) Marshal() string { | |||
return fmt.Sprintf(`"%s"`, p.value) | |||
case Date: | |||
return fmt.Sprintf(`"%s"`, p.value.(gotime.Time).Format(gotime.RFC3339)) | |||
// when Null or default |
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.
It will be nice to remove comment.
…rollback to String "null"
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.
Looks good to me.
Could you review this PR @hackerwins?
}) | ||
} | ||
|
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.
Also check all the return
codes for spacing convention in this file.
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.
Thanks for your contribution. 👍
What this PR does / why we need it:
Action to remove panic method from crdt/primitive.go
I am leaving a question because I encountered a problem while uninstalling crdt/primitive.go Panic.
In the case of the func (p *Primitive) Marshal() method inside the crdt/primitive.go package, Marshal() of the type Element interface is implemented and used.
However, if you modify the interface to Marshal() (string, error), the related implementations must be modified.
At this time, Marshal() is called when calling other String() methods, and I am asking because I think it will be difficult to change this part of String().
yorkie/pkg/document/crdt/rga_tree_list.go
Line 89 in 1b557be
Please let me know if I'm missing something or if there's a better way. thank you
Which issue(s) this PR fixes:
Fixes #497
crdt/primitive
Special notes for your reviewer:
Does this PR introduce a user-facing change?:
Additional documentation:
Checklist: