clockworklabs/SpacetimeDB · error · TypeError
Cannot convert to : expected bigint, integer number, or…
Error message
Cannot convert ${typeof value} to ${what}: expected bigint, integer number, or decimal string What it means
Column-attribute validation rejects #[default(...)] on a column that also carries #[auto_inc], #[primary_key], or #[unique]. Those attributes determine the column's value authoritatively (sequence generation, key identity, uniqueness), so a user-supplied default would conflict; the error is spanned to the default expression.
Solutions
- Remove #[default(...)] from the auto_inc/primary_key/unique column.
- If the default genuinely matters, drop the conflicting attribute — but auto-increment ids and primary keys almost always win.
- Put #[default(...)] on plain data columns instead.
Example fix
// before #[primary_key] #[auto_inc] #[default(0)] pub id: u64, // after #[primary_key] #[auto_inc] pub id: u64,
Defensive patterns
Strategy: validation
Prevention
- Never combine #[default(...)] with #[auto_inc], #[primary_key], or #[unique] on one field.
- Reserve #[default(...)] for plain data columns.
- Review column attributes as a set: key/uniqueness attributes own the value; defaults must not fight them.
When it happens
Trigger: A field combining #[default(...)] with any of #[auto_inc], #[primary_key], or #[unique] — e.g. #[unique] #[default(0)] pub id: u64.
Common situations: Adding defaults for not-null convenience on id columns; habits carried over from ORMs where primary keys have defaults.
Related errors
- Invalid UUID: must be between 0 and `MAX_UUID_BIGINT`
- Uint8Array is not 32 bytes long
- UUID v4 requires 16 bytes
- When providing a name, you must also provide the object.
- When providing a name, you must also provide the variants…
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/37df46eb62abb8a3.
Report an issue: GitHub.
Appendix: source
Thrown at crates/bindings-typescript/src/lib/util.ts:115
}
/**
* Coerces a value that should be a `bigint` — but may arrive as a `number`
* or decimal string after passing through JSON — into a `bigint`.
*
* Every other type is rejected up front: bare `BigInt()` would silently
* accept booleans (`true` → `1n`), arrays (`[42]` → `42n`) and empty
* strings (`'' ` → `0n`), turning malformed payloads into valid-looking
* ids instead of failing early.
*
* @param value The value to coerce
* @param what Type name used in the error message (e.g. `'ConnectionId'`)
*/
export function coerceToBigInt(value: unknown, what: string): bigint {
if (typeof value === 'bigint') return value;
if (typeof value === 'number') return BigInt(value);
if (typeof value === 'string' && value.trim() !== '') return BigInt(value);
throw new TypeError(
`Cannot convert ${typeof value} to ${what}: expected bigint, integer number, or decimal string`
);
}
/**
* Converts a string to PascalCase (UpperCamelCase).
* @param str The string to convert
* @returns The converted string
*/
export function toPascalCase(s: string): string {
const str = toCamelCase(s);
return str.charAt(0).toUpperCase() + str.slice(1);
}
/**
* Type safe conversion from a string like "some_identifier-name" to "someIdentifierName".
* @param str The string to convert
* @returns The converted stringView on GitHub (pinned to 6dee26c6ef)