-
Notifications
You must be signed in to change notification settings - Fork 8
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
Exception calling Get* on top level field without first defining it #85
Comments
I will have a look, but it looks like something went wrong with the transmit, because it could not find the proper type. Therefore 0 |
Thanks! I think it transmitted; if I define the |
Could you ask that in the ycrdt repo. I am actually not sure right now |
Sure! I'll see if I can figure out a reproduction using straight rust. Thanks! |
https://www.bartoszsypytkowski.com/yrs-architecture/
My interpretation of this is that it's by design to get a 0 back from rust. Top level properties are flexibly typed, if you don't declare that it's an Array or whatever it doesn't know how to interpret it. Maybe we should keep throwing here but perhaps special case the 0 and throw a message informing the user to declare the type before trying to read it? Or add an enum element for Undeclared = 0? That might just be an implementation quirk though |
@akatakritos from the update binary format perspective, the only information about root-level type passed is its name. The information about type of that structure is not passed as part of the update. For root-level types, you're expected to create them after initialising the Document. The fact that this is not enforced behaviour is due to compatibility with Yjs API, which allows you to create them at any time for convenience, however it's advised to make it during Doc initialisation as well. |
Thanks for the info! That's basically what I've come to understand. Maybe the only improvement this issue could represent is a slightly clearer exception message that guides the user towards declaring the field at Doc init time. |
@LSViana What shall we do with this issue? |
@SebastianStehle I agree we could have a better exception message, and then we could apply that change and resolve the issue. If we have a proper exception message, future users shouldn't have similar problems, and we won't need to change the code. What do you think? |
Consider this unit test based on the example in the root README.md. Note that on
remoteDoc
I never callremoteDoc.Text("name")
to define the field.I had expected the call to
remoteTransaction.GetText("name")
to return theText
object sinceby virtue of syncing with
localDocument
the property does now exist. Barring that, I expected it to returnnull
per the documentation of theGetText
method: "Returns the Text at the Doc root level, identified by name, or null if no entry was defined under name before."In reality, it threw an exception:
I would love to contribute an improvement if there's a direction you prefer to take!
The text was updated successfully, but these errors were encountered: