TanStackT
TanStack5mo ago
2 replies
uncertain-scarlet

unique index does not throw DuplicateKeyError

Maybe I'm misunderstanding how it should work but I'm trying to handle duplicates on the client to faster feedback.
I have added an index to my collection and it correctly deduplicates the data, however my insert just fails silently now

ratelimitOverrides.createIndex((row) => [row.namespaceId, row.identifier], {
  name: 'unique_identifier_per_namespace',
  options: {
    unique: true,
  },
})


and when submitting the form:
try {
  collection.ratelimitOverrides.insert({...});
} catch (error) {
  if (error instanceof DuplicateKeyError) {
     setError("identifier", { type: "custom", message: "Identifier already exists" });
  } else {
    console.error(error)
  }
  
}
      


However this never throws, it just silently deduplicates on insert.


It worked perfectly when I had a duplicate key in the collection, just not for indices
Was this page helpful?