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

Gracefully handling non-existing fork room #420

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions projects/jupyter-server-ydoc/jupyter_server_ydoc/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,12 @@ async def put(self, root_roomid):
Optionally keeps the fork in sync with the root.
"""
fork_roomid = uuid4().hex
root_room = await self._websocket_server.get_room(root_roomid)
try:
root_room = await self._websocket_server.get_room(root_roomid)
except RoomNotFound:
self.set_status(404)
return self.finish({"code": 404, "error": "Room not found"})
trungleduc marked this conversation as resolved.
Show resolved Hide resolved

update = root_room.ydoc.get_update()
fork_ydoc = Doc()
fork_ydoc.apply_update(update)
Expand Down Expand Up @@ -676,7 +681,10 @@ async def delete(self, fork_roomid):
"""
Deletes a forked document, and optionally merges it back in the root document.
"""
fork_info = FORK_ROOMS[fork_roomid]
fork_info = FORK_ROOMS.get(fork_roomid, None)
if fork_info is None:
self.set_status(404)
return self.finish({"code": 404, "error": "Fork room does not exist"})
trungleduc marked this conversation as resolved.
Show resolved Hide resolved
root_roomid = fork_info["root_roomid"]
del FORK_ROOMS[fork_roomid]
if self.get_query_argument("merge") == "true":
Expand Down
Loading