hcengineering/platform · error
Unable to find just created drawing
Error message
Unable to find just created drawing
What it means
AttachmentPreviewPopup.svelte creates a Drawing blob, then immediately findOne's the Drawing attachment by the new id; if the query returns undefined it throws 'Unable to find just created drawing'. This indicates the just-created document was not visible to the client query — usually a client-side index/replication lag or the creation silently failing while still returning an id.
Source
Thrown at plugins/attachment-resources/src/components/AttachmentPreviewPopup.svelte:56
createdOn: SortingOrder.Descending
},
limit: 1
}
)
return Array.from(drawings ?? [])
}
async function createDrawing (data: DrawingData): Promise<DrawingData> {
const client = getClient()
const newId = await client.createDoc(attachment.class.Drawing, value.space, {
parent: value.file,
parentClass: core.class.Blob,
content: data.content
})
const newDrawing = await client.findOne(attachment.class.Drawing, { _id: newId })
if (newDrawing === undefined) {
throw new Error('Unable to find just created drawing')
}
return newDrawing
}
</script>
<FilePreviewPopup
file={value.file}
name={value.name}
metadata={value.metadata}
contentType={value.type}
props={{
drawingAvailable,
loadDrawings,
createDrawing
}}
{fullSize}
{showIcon}
on:openView on GitHub (pinned to 63e28dc964)
Solutions
- Retry the findOne briefly (poll a few times with a small delay) before concluding the object is missing.
- Check the network/sync status — ensure the client is connected and replication caught up after createDoc.
- Verify the createDoc call for the drawing blob actually succeeded (no swallowed errors) before querying.
- Await the creation promise chain fully (e.g. await apply/commit of the transaction) before querying.
Example fix
// before
const newDrawing = await client.findOne(attachment.class.Drawing, { _id: newId })
if (newDrawing === undefined) {
throw new Error('Unable to find just created drawing')
}
// after
let newDrawing: Drawing | undefined
for (let i = 0; i < 5 && newDrawing === undefined; i++) {
newDrawing = await client.findOne(attachment.class.Drawing, { _id: newId })
if (newDrawing === undefined) await new Promise(r => setTimeout(r, 200))
}
if (newDrawing === undefined) throw new Error('Unable to find just created drawing') Defensive patterns
Strategy: retry
Validate before calling
// Poll briefly for the just-created document before failing:
let drawing = await client.findOne(attachment.class.Drawing, { _id: newId })
for (let i = 0; i < 5 && drawing === undefined; i++) {
await new Promise(r => setTimeout(r, 200))
drawing = await client.findOne(attachment.class.Drawing, { _id: newId })
} Type guard
function isDrawing(doc: any | undefined): doc is Drawing {
return doc !== undefined && typeof (doc as Drawing)._id === 'string'
} Try / catch
try {
return await createAndGetDrawing(data)
} catch (err) {
if (err instanceof Error && err.message === 'Unable to find just created drawing') {
showNotification('The drawing could not be loaded. Check your connection and try again.')
return null
}
throw err
} Prevention
- Ensure the client is fully connected and synced before creating drawings.
- Await the full transaction/commit before querying the new object.
- Poll with a short backoff instead of a single immediate findOne.
- Check createDoc errors are not silently swallowed upstream.
When it happens
Trigger: client.findOne(attachment.class.Drawing, { _id: newId }) runs before the newly created object has propagated to the client's query results (offline/sync lag), or the underlying blob/content creation partially failed so no Drawing was persisted despite newId being returned.
Common situations: Slow or offline networks with the collaborative backend, large workspaces where the initial query window hasn't loaded the new object, or transient backend errors during createDoc.
Related errors
- No active recording
- attribute presenter not found for ${JSON.stringify(preserveK
- object presenter not found for class=${_class}, preserve key
- Reaction not found.
- Board not found
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/7529f4a62228588b.
Report an issue: GitHub.