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

Improve error logged when there's an exception applying ops #45

Merged
merged 2 commits into from
Feb 27, 2024

Conversation

nickbrowne
Copy link
Contributor

@nickbrowne nickbrowne commented Feb 27, 2024

We're still getting intermittent "Deleted string does not match" errors despite some of the other fixes applied, hoping that just logging the strings attempted to be deleted will reveal the problem.

To test (assuming starting from a blank slate):

npm install && npm run build
createdb sharejs_example
bin/sharejs

Now we need to create a json type document with a text type subdocument, insert a string, then give it a bad delete op:

Create a document
curl -X PUT -H 'Content-Type: application/json' -d '{"type": "json"}' http://localhost:9000/doc/test

Post an object insert op to insert an empty object to create a json document type
curl -X POST -H 'Content-Type: application/json' -d '[{ "p": [], "oi": {} }]' http://localhost:9000/doc/test?v=0

Object insert on the key "test", inserting an empty string to create a text subdocument within the json document
curl -X POST -H 'Content-Type: application/json' -d '[{ "p": ["test"], "oi": "" }]' http://localhost:9000/doc/test?v=1

String insert on the text subdocument
curl -X POST -H 'Content-Type: application/json' -d '[{ "p": ["test", 0], "si": "foo bar" }]' http://localhost:9000/doc/test?v=2

At this point do a GET on the document just to sanity check it's as expected:
curl http://localhost:9000/doc/test

Should return
{"test":"foo bar"}

Now give it a bad delete operation to trigger the exception.

We want to delete from the last 'o' in foo to the 'a' in bar to send up with "for", but give it some bogus delete text
curl -X POST -H 'Content-Type: application/json' -d '[{ "p": ["test", 2], "sd": "xxxx" }]' http://localhost:9000/doc/test?v=3

This should raise an error
test Error: Deleted string does not match (1: "o ba" 2: "xxxx")

Now give it a properly formed delete op
curl -X POST -H 'Content-Type: application/json' -d '[{ "p": ["test", 2], "sd": "o ba" }]' http://localhost:9000/doc/test?v=3

GET the document again
curl http://localhost:9000/doc/test

The subdocument should only contain "for"
{"test":"for"}

Copy link
Contributor

@RohanM RohanM left a comment

Choose a reason for hiding this comment

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

Nice 🚀

@nickbrowne nickbrowne merged commit 982ddaa into master Feb 27, 2024
1 check passed
@nickbrowne nickbrowne deleted the 16389-better-errors branch February 27, 2024 04:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants