{"record":{"id":"38a786956d446048","repo":"nautechsystems/nautilus_trader","slug":"failed-to-insert-into-signal-table-e","errorCode":null,"errorMessage":"Failed to insert into signal table: {e}","messagePattern":"Failed to insert into signal table: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/queries.rs","lineNumber":1592,"sourceCode":"                name, value, ts_event, ts_init, created_at, updated_at\n            ) VALUES (\n                $1, $2, $3, $4, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP\n            )\n            ON CONFLICT (id)\n            DO UPDATE\n            SET\n                name = $1, value = $2, ts_event = $3, ts_init = $4,\n                updated_at = CURRENT_TIMESTAMP\n        \"#,\n        )\n        .bind(signal.name.to_string())\n        .bind(signal.value.clone())\n        .bind(signal.ts_event.to_string())\n        .bind(signal.ts_init.to_string())\n        .execute(pool)\n        .await\n        .map(|_| ())\n        .map_err(|e| anyhow::anyhow!(\"Failed to insert into signal table: {e}\"))\n    }\n\n    /// Loads all `Signal` entries by `name` via the provided `pool`.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the SQL SELECT or deserialization fails.\n    pub async fn load_signals(pool: &PgPool, name: &str) -> anyhow::Result<Vec<Signal>> {\n        sqlx::query_as::<_, SignalRow>(\n            r#\"SELECT * FROM \"signal\" WHERE name = $1 ORDER BY ts_init ASC\"#,\n        )\n        .bind(name)\n        .fetch_all(pool)\n        .await\n        .map(|rows| rows.into_iter().map(|row| row.0).collect())\n        .map_err(|e| anyhow::anyhow!(\"Failed to load signals: {e}\"))\n    }\n","sourceCodeStart":1574,"sourceCodeEnd":1610,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/queries.rs#L1574-L1610","documentation":"Raised by `add_signal` when the INSERT into the `signal` table fails. The sqlx execute error is converted into an anyhow::Error with this message, so any database-level constraint violation, type mismatch, or connectivity problem surfaces here.","triggerScenarios":"Calling `add_signal(pool, signal)` when the `signal` table is missing, a NOT NULL/constraint is violated, the pool is dead, or a serialization of bound values (name, value, timestamps as strings) is rejected by PostgreSQL.","commonSituations":"Schema drift after upgrading the library without rerunning migrations; writing signals with null name/value; database in read-only mode; connection dropped mid-write.","solutions":["Read the embedded sqlx error to identify constraint/table issues.","Run the library's SQL migrations to ensure the `signal` table exists with expected columns.","Validate the signal fields (name, value, ts_event, ts_init) are non-null before insert.","Check the database is writable and the pool connection is healthy."],"exampleFix":"// before\nadd_signal(&pool, &signal).await?;\n// after\nif signal.name.is_empty() { anyhow::bail!(\"signal name required\"); }\nadd_signal(&pool, &signal).await\n    .map_err(|e| e.context(format!(\"adding signal {}\", signal.name)))?;","handlingStrategy":"try-catch","validationCode":"let exists: bool = sqlx::query_scalar(\n    \"SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name = 'signal')\")\n    .fetch_one(pool).await?;\nanyhow::ensure!(exists, \"signal table missing; run migrations\");\nanyhow::ensure!(!signal.name.is_empty(), \"signal name required\");","typeGuard":null,"tryCatchPattern":"if let Err(e) = add_signal(&pool, &signal).await {\n    tracing::error!(\"signal insert failed: {e:#}\");\n    return Err(e.context(\"signal persistence failed\"));\n}","preventionTips":["Keep migrations in sync with the library version","Validate non-null signal fields before insert","Ensure the DB is not read-only","Log the full error chain ({e:#}) for diagnosis"],"tags":["database","sqlx","insert"],"backgroundTag":"database-write-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}