{"record":{"id":"51085ef10c30ef45","repo":"nautechsystems/nautilus_trader","slug":"label-must-not-be-empty","errorCode":null,"errorMessage":"{label} must not be empty","messagePattern":"(.+?) must not be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/infrastructure/src/sql/pg.rs","lineNumber":28,"sourceCode":"//  distributed under the License is distributed on an \"AS IS\" BASIS,\n//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n//  See the License for the specific language governing permissions and\n//  limitations under the License.\n// -------------------------------------------------------------------------------------------------\n\nuse std::fmt::Debug;\n\nuse derive_builder::Builder;\nuse regex::Regex;\nuse serde::{Deserialize, Serialize};\nuse sqlx::{\n    AssertSqlSafe, ConnectOptions, PgPool,\n    postgres::{PgConnectOptions, PgConnection},\n};\n\nfn validate_sql_identifier(value: &str, label: &str) -> anyhow::Result<()> {\n    if value.is_empty() {\n        anyhow::bail!(\"{label} must not be empty\");\n    }\n\n    if !value.chars().all(|c| c.is_ascii_alphanumeric() || c == '_') {\n        anyhow::bail!(\n            \"{label} contains invalid characters (only alphanumeric and underscore allowed): {value}\"\n        );\n    }\n    Ok(())\n}\n\nfn escape_sql_string(value: &str) -> String {\n    value.replace('\\'', \"''\")\n}\n\n#[derive(Clone, Serialize, Deserialize, Builder)]\n#[serde(deny_unknown_fields)]\n#[builder(default)]\n#[cfg_attr(","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/infrastructure/src/sql/pg.rs#L10-L46","documentation":"validate_sql_identifier() in crates/infrastructure/src/sql/pg.rs rejects an empty string before doing any character validation. init_postgres/drop_postgres call it for SQL identifiers (schema, database/table names, etc.) because empty identifiers would produce invalid or dangerous SQL. The error interpolates the caller-supplied label naming which identifier was empty.","triggerScenarios":"Calling init_postgres or drop_postgres with an empty value for any identifier argument it validates (e.g. empty schema name), typically via connection/config options where a field was left unset.","commonSituations":"Postgres config where schema/database name is an empty string or an unset env var yields \"\"; programmatic construction of ConnectOptions where a default field was never filled; YAML/TOML config with an empty value like schema: \"\".","solutions":["Set the missing identifier explicitly in the Postgres connection/config (e.g. schema: \"public\")","Check the env var or config field feeding the identifier — it is resolving to an empty string; give it a default","Validate the config at startup with the same rules (non-empty, alphanumeric+underscore) before calling init_postgres","Read the {label} in the message to identify exactly which identifier is empty"],"exampleFix":"// before\nlet opts = ConnectOptions::from_uri(&uri)?; // schema left empty\n// after\nlet schema = std::env::var(\"NAUTILUS_PG_SCHEMA\").unwrap_or_else(|_| \"public\".to_string());\nopts.schema(&schema); // non-empty, validated identifier","handlingStrategy":"validation","validationCode":"fn ensure_non_empty(value: &str, label: &str) -> Result<(), String> {\n    if value.is_empty() { Err(format!(\"{label} must not be empty\")) } else { Ok(()) }\n}\nensure_non_empty(&config.schema, \"schema\")?;","typeGuard":"fn is_valid_sql_identifier(v: &str) -> bool {\n    !v.is_empty() && v.chars().all(|c| c.is_ascii_alphanumeric() || c == '_')\n}","tryCatchPattern":"if let Err(e) = init_postgres(&opts) {\n    if e.to_string().contains(\"must not be empty\") {\n        return Err(anyhow::anyhow!(\"Postgres config incomplete: {e}\"));\n    }\n    return Err(e);\n}","preventionTips":["Provide defaults for schema/database identifiers (e.g. schema: \"public\") in config loading","Fail fast at config-parse time when identifier fields are empty strings","Never feed env vars directly into identifier fields without an unwrap_or default and a check"],"tags":["rust","postgresql","validation","identifier","empty-value"],"backgroundTag":"empty-required-field","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"}