Error code reference
Overview
monSQLize uses a unified error code system to identify different types of errors, helping developers accurately identify and handle exceptions. All error objects contain the code attribute, through which the error type can be determined and corresponding processing logic executed.
Common user paths such as configuration, cache, SSH, connection pools, query chains, collection management, transactions, and expression compilation throw error objects with code; error message remains human-readable.
The core runtime uses MonSQLizeError together with the exported ErrorCodes constants. Data Tasks form a separate domain contract: they throw DataTaskJobError, whose discriminated code, phase, and optional collection describe validation, approval, locking, apply, backup, and restore failures. Do not compare Data Task codes with ErrorCodes; handle the two error families explicitly at the boundary.
Data Task error contract
See Data Tasks for the preview, approval, apply, backup, and restore workflow.
Core runtime error object structure
Error handling best practices
User action quick check
When you're not sure where to start troubleshooting, start by printing error.code, error.message, error.details, and error.cause.
1. Capture specific errors
2. Unified error handling
3. Detailed error information
Error code list
Validation related errors (Validation)
VALIDATION_ERROR
Explanation: Parameter verification failed
Trigger scenario:
- The parameters provided do not meet the requirements
- Missing required parameters
- Wrong parameter type
Example:
Handling Suggestions:
- Check
error.detailsfor detailed verification errors - Verify input parameters meet API requirements
- Refer to the API documentation to confirm the correct parameter format
INVALID_ARGUMENT
Explanation: The parameter is invalid
Trigger scenario:
- The parameter value exceeds the allowed range
- Illegal parameter combination
- Incorrect parameter format
Example:
Handling Suggestions:
- Check the type and value range of parameters
- Confirm whether the parameter combination is legal
- Refer to the API documentation for parameter constraints
INVALID_COLLECTION_NAME
Explanation: The collection name is invalid
Trigger scenario:
- Collection name is empty
- Collection name contains illegal characters
- The collection name does not comply with MongoDB naming conventions
Example:
Handling Suggestions:
- Use legal collection names (letters, numbers, underscores)
- Avoid using reserved characters ($, .)
- Refer to MongoDB collection naming convention
INVALID_DATABASE_NAME
Explanation: The database name is invalid
Trigger scenario:
- Database name is empty
- Database name contains illegal characters
- The database name does not comply with MongoDB naming conventions
Example:
Handling Suggestions:
- Use a valid database name
- Avoid using special characters
- Refer to MongoDB database naming convention
Cursor related errors (Cursor)
INVALID_CURSOR
Explanation: The cursor is invalid
Trigger scenario:
- The cursor has expired or been closed
- Cursor configuration error
- Inconsistent cursor status
Example:
Handling Suggestions:
- Make sure the cursor is not closed or expired
- Check the cursor life cycle
- Consider using
toArray()or streaming
CURSOR_SORT_MISMATCH
Description: Cursor sorting does not match
Trigger scenario:
- Sorting fields are inconsistent when cursor is paging
- Different sorting conditions are used when jumping to the page
Example:
Handling Suggestions:
- Ensure that the sorting conditions are consistent when paginating
- Use the same
sortparameters - Consider maintaining sorting state at the application layer
Pagination related errors (Pagination)
JUMP_TOO_FAR
Description: Page jump distance is too far
Trigger scenario:
- Attempt to jump to a page beyond the reasonable range
- Skipping too many pages at once
Example:
Handling Suggestions:
- Reduce page jump distance
- Use progressive page jumps
- Consider using normal queries instead of cursors
STREAM_NO_JUMP
Note: Streaming mode does not support page jumps
Trigger scenario:
- Try page skipping in streaming mode
Example:
Handling Suggestions:
- Can only be read sequentially in streaming mode
- If you need to jump to another page, use cursor mode
STREAM_NO_TOTALS
Note: Streaming mode does not support getting the total number
Trigger scenario:
- Try to get the total number of records in streaming mode
Example:
Handling Suggestions:
- For total number, use
findAndCount()orcount() - Streaming mode is only used for data processing and does not calculate totals
STREAM_NO_EXPLAIN
Note: Streaming mode does not support query plans
Trigger scenario:
- Try to get execution plan in streaming mode
Example:
Handling Suggestions:
- Use the
.explain()method of the chained API - Get the execution plan before creating the stream
Connection related errors (Connection)
CONNECTION_TIMEOUT
Description: Connection timeout
Trigger scenario:
- Database server response timeout
- Network latency is too high
- Connection pool wait timeout
Example:
Handling Suggestions:
- Check network connection
- Add timeout configuration
- Check database server status
- Check connection pool configuration
CONNECTION_FAILED
Explanation: Database connection failed
Trigger scenario:
- The database server is unreachable
- Connection string error
- Authentication failed
- Network error
Example:
Handling Suggestions:
- Verify connection string format
- Check database server status
- Check network connection
- Verify username and password
- See
error.causefor detailed errors
NOT_CONNECTED
Description: The database is not connected (v1.3.0+)
Trigger scenario:
- Use
pool()/use()/scopedCollection()/scopedModel()before callingconnect()
Example:
Handling Suggestions:
- Make sure to call
await msq.connect()before using any data access method
NO_POOL_MANAGER
Note: Multiple connection pool manager (v1.3.0+) is not configured
Trigger scenario:
- The MonSQLize constructor did not pass in the
poolsconfiguration when callingpool()
Example:
Handling Suggestions:
- Configure the
poolsoption in the constructor, or useuse()to switch databases (single pool and multiple database scenarios)
POOL_NOT_FOUND
Description: The specified connection pool does not exist (v1.3.0+)
Trigger scenario:
poolNameofpool(poolName)is not registered inConnectionPoolManager
Example:
Handling Suggestions:
- Check the
error.availablefield to confirm available connection pool names - Confirm that
poolNameis exactly the same as the name when initialized (case sensitive)
MODEL_NOT_DEFINED
Description: The specified Model is not registered (v1.3.0+)
Trigger scenario:
pool().model(key)orkeyofscopedModel(key)is not registered to the Model registry
Example:
Handling Suggestions:
- Confirm that the Model file has been loaded correctly (check
models.pathconfiguration) - Confirm that the key string is consistent with
key(orname) in the Model definition
CONNECTION_CLOSED
Description: The connection has been closed
Trigger scenario:
- Perform operations on a closed connection
- Connection pool is closed
- The server actively closes the connection
Example:
Handling Suggestions:
- Check connection status
- Re-establish connection
- Avoid performing actions after shutdown
Database operation error (Database)
DATABASE_ERROR
Explanation: Generic database error
Trigger scenario:
- Uncategorized error returned by MongoDB driver
- Database internal error
- Other database related issues
Example:
Handling Suggestions:
- See
error.causefor the original error - Check query syntax
- Check out the MongoDB documentation
QUERY_TIMEOUT
Description: Query timeout
Trigger scenario:
- Query execution time exceeds
maxTimeMSconfiguration - Slow queries result in timeouts
Example:
Handling Suggestions:
- Optimize query conditions
- Create appropriate indexes
- Increase
maxTimeMSvalue - Analyze performance using query plans
Cache related errors (Cache)
CACHE_ERROR
Description: Cache operation error
Trigger scenario:
- Cache read and write failed
- Cache serialization/deserialization errors
- Cache configuration error
Example:
Handling Suggestions:
- Check cache configuration
- View cache service status (such as Redis)
- Consider downgrading to not using caching
- Check if the data is serializable
CACHE_TIMEOUT
Description: Cache operation timed out
Trigger scenario:
- Cache read timeout
- cache write timeout
- The cache service responds slowly
Example:
Handling Suggestions:
- Check cache service status
- Add timeout configuration
- Consider downgrading to not using caching
Configuration related errors (Configuration)
INVALID_CONFIG
Explanation: Invalid configuration
Trigger scenario:
- Configuration parameter error
- Missing required configuration items
- Configuration format is incorrect
- Model
schemaDslruntime cannot resolveschema-dsl/runtime, exposes an incompatible API shape, or receives invalid runtime options
Example:
Handling Suggestions:
- Check configuration parameters
- Refer to documentation to confirm required configuration
- Verify configuration format
- For Model schema validation, check bundled dependency installation, package-manager pruning, runtime module resolution, and the
schemaDslruntime/options/extensions configuration
UNSUPPORTED_DATABASE
Description: Unsupported database type
Trigger scenario:
- An unsupported database type was specified
- Database version is incompatible
Example:
Handling Suggestions:
- Use supported database types (currently MongoDB only)
- Check database version compatibility
Write Operations Error (Write Operations)
WRITE_ERROR
Explanation: Generic write operation error
Trigger scenario:
- The write operation failed to execute
- Server refuses write
- Other write related errors
Example:
Handling Suggestions:
- See
error.causefor detailed errors - Check write permission
- Verify data format
DOCUMENT_REQUIRED
Explanation: Missing document parameter
Trigger scenario:
insertOneNo documentation provided- The document provided is
nullorundefined
Example:
Handling Suggestions:
- Provide a valid document object
- Check if the document parameter is
nullorundefined
DOCUMENTS_REQUIRED
Explanation: Missing document array parameter
Trigger scenario:
insertManyNo document array provided- The provided document array is empty
Example:
Handling Suggestions:
- Provide at least one document
- Verify that the document array is not empty
DUPLICATE_KEY
Description: Unique key conflict
Trigger scenario:
- Insert duplicate
_id - Violation of unique index constraint
Example:
Handling Suggestions:
- Check unique index fields
- Use the
upsertoption ofupdateOne - Catch and handle duplicate errors
WRITE_CONFLICT
Description: Write conflict
Trigger scenario:
- Concurrent write conflicts
- Transaction conflicts
- Optimistic lock conflict
Example:
Handling Suggestions:
- Retry the write operation
- Use transaction isolation levels
- Implement optimistic locking mechanism
Lock related errors (Locking) 🆕 v1.4.0
LOCK_ACQUIRE_FAILED
Explanation: Lock acquisition failed
Trigger scenario:
- The distributed lock is already held by another process
- Lock service is unavailable
- Lock configuration error
Example:
Handling Suggestions:
- Wait for the lock to be released and try again
- Check lock service status (such as Redis)
- Implement lock timeout and retry mechanism
- Consider using a shorter lock timeout
LOCK_TIMEOUT
Description: Lock wait timeout
Trigger scenario:
- Waiting for lock for longer than configured timeout
- Other processes hold locks for a long time
Example:
Handling Suggestions:
- Increase wait timeout
- Check lock holder status
- Implement the forced release mechanism of locks
- Optimize business logic to reduce lock holding time