{"record":{"id":"8b5f6c54d3a7ddc7","repo":"transact-rs/sqlx","slug":"query-file-path-cannot-be-represented-as-a-string","errorCode":null,"errorMessage":"query file path cannot be represented as a string","messagePattern":"query file path cannot be represented as a string","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"sqlx-macros-core/src/query/input.rs","lineNumber":130,"sourceCode":"impl QuerySrc {\n    /// If the query source is a file, read it to a string. Otherwise return the query string.\n    fn resolve(self, source_span: Span) -> syn::Result<String> {\n        match self {\n            QuerySrc::String(string) => Ok(string),\n            QuerySrc::File(file) => read_file_src(&file, source_span),\n        }\n    }\n\n    fn file_path(&self, source_span: Span) -> syn::Result<Option<String>> {\n        if let QuerySrc::File(ref file) = *self {\n            let path = crate::common::resolve_path(file, source_span)?\n                .canonicalize()\n                .map_err(|e| syn::Error::new(source_span, e))?;\n\n            Ok(Some(\n                path.to_str()\n                    .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,","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/transact-rs/sqlx/blob/03af8bcc5711a1935580a54bea249c219a0c217d/sqlx-macros-core/src/query/input.rs#L112-L148","documentation":"When a `*_file!` macro canonicalizes the query file path to embed source-location info, the resulting `Path` must be convertible to a UTF-8 `str`. If the canonicalized path contains invalid Unicode (e.g. non-UTF-8 bytes in directory names), `path.to_str()` returns `None` and the macro errors with this message at compile time.","triggerScenarios":"Compiling `query_file!`/`query_as_file!` where the canonicalized query file path includes non-UTF-8 characters — unusual byte sequences in directory names, locale-specific encoded filenames.","commonSituations":"Project checked out in a directory whose name contains non-UTF-8 bytes; filesystems with legacy encodings; CI caches with mangled paths.","solutions":["Rename the offending directories/files so the full path is valid UTF-8 (ASCII is safest)","Move the project (or the .sql files) to a path with only standard characters","Regenerate/restore the path if it was corrupted by a tool or cache"],"exampleFix":"// before: project at /home/usér/pröject → canonicalize() yields non-UTF-8 bytes\n// after: move project to an ASCII path\n// /home/user/project, then:\nlet q = query_file!(\"src/queries/get_user.sql\");","handlingStrategy":"validation","validationCode":"let p = std::path::Path::new(env!(\"CARGO_MANIFEST_DIR\")).join(rel);\nlet canon = p.canonicalize().expect(\"query file must exist\");\nassert!(canon.to_str().is_some(), \"query file path must be valid UTF-8\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep project and query file paths ASCII/UTF-8-safe","Rename non-UTF-8 directories in your workspace","Avoid legacy-locale filesystems for source trees"],"tags":["rust","sqlx","macros","utf-8","paths","encoding"],"backgroundTag":"non-utf8-path","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"}