{"record":{"id":"2e6e7ae51f000087","repo":"transact-rs/sqlx","slug":"failed-to-read-query-file-at","errorCode":null,"errorMessage":"failed to read query file at {}: {}","messagePattern":"failed to read query file at (.+?): (.+?)","errorType":"exception","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"sqlx-macros-core/src/query/input.rs","lineNumber":147,"sourceCode":"                    .ok_or_else(|| {\n                        syn::Error::new(\n                            source_span,\n                            \"query file path cannot be represented as a string\",\n                        )\n                    })?\n                    .to_string(),\n            ))\n        } else {\n            Ok(None)\n        }\n    }\n}\n\nfn read_file_src(source: &str, source_span: Span) -> syn::Result<String> {\n    let file_path = crate::common::resolve_path(source, source_span)?;\n\n    fs::read_to_string(&file_path).map_err(|e| {\n        syn::Error::new(\n            source_span,\n            format!(\n                \"failed to read query file at {}: {}\",\n                file_path.display(),\n                e\n            ),\n        )\n    })\n}\n","sourceCodeStart":129,"sourceCodeEnd":157,"githubUrl":"https://github.com/transact-rs/sqlx/blob/03af8bcc5711a1935580a54bea249c219a0c217d/sqlx-macros-core/src/query/input.rs#L129-L157","documentation":"`read_file_src` loads the contents of a query file referenced by `*_file!` macros at compile time. After resolving the path, it calls `fs::read_to_string`; if that fails (file missing, permission denied, not valid UTF-8), the error is wrapped with this message including the resolved path and the OS error. This is a compile-time error from the macro expansion.","triggerScenarios":"`query_file!`/`query_as!` referencing a .sql file that does not exist at the resolved location, is unreadable (permissions), or contains invalid UTF-8; path resolved relative to the wrong crate because of workspace layout.","commonSituations":"Typo in the file path in the macro; file deleted or moved after writing the macro; building from a different crate in a workspace where the relative path no longer points at the file; case-sensitivity mismatch on Linux CI after developing on a case-insensitive macOS.","solutions":["Verify the file exists at the path relative to the crate's manifest directory (Cargo.toml); fix the path string","Check file permissions and that the file is valid UTF-8 text","In workspaces, confirm which crate the macro compiles in and adjust the relative path accordingly","Check filename case exactly matches (CI/Linux are case-sensitive)"],"exampleFix":"// before (file not at that location relative to manifest dir)\nlet q = query_file!(\"sql/get_user.SQL\");\n// after\nlet q = query_file!(\"src/queries/get_user.sql\"); // exact, existing path","handlingStrategy":"validation","validationCode":"let p = std::path::Path::new(env!(\"CARGO_MANIFEST_DIR\")).join(\"src/queries/get_user.sql\");\nstd::fs::read_to_string(p.canonicalize().expect(\"query file missing\")).expect(\"query file unreadable or not UTF-8\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add a build-time check (build.rs or test) that all referenced .sql files exist and parse as UTF-8","Verify paths relative to the crate that compiles the macro, especially in workspaces","Match filename case exactly; be wary of macOS/Windows case-insensitivity","Re-check paths after moving or renaming query files"],"tags":["rust","sqlx","macros","compile-time","file-io"],"backgroundTag":"query-file-not-found","analyzedSha":"03af8bcc5711a1935580a54bea249c219a0c217d","analyzedAt":"2026-09-03T15:01:28.752Z","contentChangedAt":"2026-09-03T15:01:28.752Z","schemaVersion":2},"datasetVersion":"2026-09-10T17:17:09.494Z"}