Error Handling & Troubleshooting
This guide covers the common exceptions, error messages, and debugging techniques in OrionORM. Proper error handling ensures robust applications and simplifies troubleshooting.
1. Debugging SQL
Enable Info Logging:
ENV["ORIONORM_LOG_LEVEL"] = "info"Check Logs: Every call to
executeQuerylogs:sql: the prepared SQL stringargs: the parameter vector
Reproduce in MySQL client:
- Copy the logged SQL, replace
?with actual values, and run inmysqlCLI or GUI.
- Copy the logged SQL, replace
Inspect Generated Query:
b = buildSelectQuery(User, qdict) println(b.sql, "\nParams:", b.params)
2. Handling commands out of sync
This error arises when statements remain open or connections are reused improperly. To resolve:
- Ensure every
DBInterface.prepareis paired withDBInterface.close!(stmt)in afinallyblock. - Use the unified
executeQuerywhich guarantees closing statements. - Do not call raw
DBInterface.executeon a connection with unclosed statements.
3. Transaction Rollback
Within a DBInterface.transaction(conn) block, any uncaught exception triggers a rollback:
conn = dbConnection()
try
DBInterface.transaction(conn) do
executeQuery(conn, sql1, params1; useTransaction=false)
error("trigger rollback")
end
catch e
@info "Transaction rolled back due to: $e"
finally
releaseConnection(conn)
end