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:open

View on GitHub (pinned to 63e28dc964)

Solutions

  1. Retry the findOne briefly (poll a few times with a small delay) before concluding the object is missing.
  2. Check the network/sync status — ensure the client is connected and replication caught up after createDoc.
  3. Verify the createDoc call for the drawing blob actually succeeded (no swallowed errors) before querying.
  4. 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

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


AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29). Data as JSON: /api/errors/7529f4a62228588b. Report an issue: GitHub.