{"record":{"id":"a1f9d3eeb39c8921","repo":"transact-rs/sqlx","slug":"absolute-paths-will-only-work-on-the-current-machi","errorCode":null,"errorMessage":"absolute paths will only work on the current machine","messagePattern":"absolute paths will only work on the current machine","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"sqlx-macros-core/src/common.rs","lineNumber":8,"sourceCode":"use proc_macro2::Span;\nuse std::path::{Path, PathBuf};\n\npub(crate) fn resolve_path(path: impl AsRef<Path>, err_span: Span) -> syn::Result<PathBuf> {\n    let path = path.as_ref();\n\n    if path.is_absolute() {\n        return Err(syn::Error::new(\n            err_span,\n            \"absolute paths will only work on the current machine\",\n        ));\n    }\n\n    // requires `proc_macro::SourceFile::path()` to be stable\n    // https://github.com/rust-lang/rust/issues/54725\n    if path.is_relative()\n        && path\n            .parent()\n            .is_none_or(|parent| parent.as_os_str().is_empty())\n    {\n        return Err(syn::Error::new(\n            err_span,\n            \"paths relative to the current file's directory are not currently supported\",\n        ));\n    }\n","sourceCodeStart":1,"sourceCodeEnd":26,"githubUrl":"https://github.com/transact-rs/sqlx/blob/03af8bcc5711a1935580a54bea249c219a0c217d/sqlx-macros-core/src/common.rs#L1-L26","documentation":"sqlx macros resolve `file`/query paths relative to the crate manifest directory so macros work across machines. An absolute path (one starting with `/` or a drive letter) is rejected at compile time because it would only resolve on the machine where it was written and break builds elsewhere (CI, teammates, Docker).","triggerScenarios":"Writing `query_file = \"/home/me/project/src/queries/users.sql\"` (or any absolute path) in `query!`, `query_file!`, `query_as!` etc., then compiling.","commonSituations":"Copy-pasting a path from an IDE's absolute-path copy; generated code that embeds absolute paths; moving code between machines or into CI where the absolute path is invalid anyway.","solutions":["Replace the absolute path with a path relative to the crate's Cargo.toml (manifest directory), e.g. `src/queries/users.sql`","Use the `CARGO_MANIFEST_DIR` convention mentally: the macro resolves relative paths from there","If generating code, emit relative paths instead of absolute ones"],"exampleFix":"// before\nlet q = query_file!(\"/home/alice/app/src/queries/get_user.sql\");\n// after\nlet q = query_file!(\"src/queries/get_user.sql\");","handlingStrategy":"validation","validationCode":"// check before invoking the macro path convention\nlet p = std::path::Path::new(file_arg);\nassert!(!p.is_absolute(), \"use a path relative to the crate manifest dir\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always use manifest-relative paths in *_file! macros","Never copy absolute paths from IDEs into query! macros","Lint generated code for absolute path literals"],"tags":["rust","sqlx","macros","compile-time","paths"],"backgroundTag":"absolute-path-not-portable","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"}