Skip to content

Commit

Permalink
fix(editor): catch bad document update
Browse files Browse the repository at this point in the history
Sometimes we are failing to update the document content for some reason.
Adding some defensive code.

fixes LATITUDE-LLM-APP-8Q
  • Loading branch information
geclos committed Nov 20, 2024
1 parent af62dbc commit ce6e377
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion apps/web/src/actions/documents/updateContent.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use server'

import { BadRequestError } from '@latitude-data/core/lib/errors'
import {
CommitsRepository,
DocumentVersionsRepository,
Expand Down Expand Up @@ -38,6 +39,14 @@ export const updateDocumentContentAction = withProject
document,
content: input.content,
})
const updatedDocument = result.unwrap()

return result.unwrap()
// This should never happen but it does happen sometimes
if (!updatedDocument) {
throw new BadRequestError(
'Could not update document, if the issue persists please contact support.',
)
}

return updatedDocument
})
1 change: 1 addition & 0 deletions apps/web/src/stores/documentVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export default function useDocumentVersions(
{
onSuccess: ({ data: document }) => {
const prevDocuments = data || []

mutate(
prevDocuments.map((d) =>
d.documentUuid === document.documentUuid ? document : d,
Expand Down

0 comments on commit ce6e377

Please sign in to comment.