{"record":{"id":"fa55a5ef6588b3df","repo":"facebook/relay","slug":"cannot-parse-schema-utf8-from-bytes","errorCode":null,"errorMessage":"Cannot parse schema utf8 from bytes: {}","messagePattern":"Cannot parse schema utf8 from bytes: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/crates/graphql-ir-diff/src/lib.rs","lineNumber":812,"sourceCode":"}\n\npub fn load_schema(schema_paths: Vec<String>) -> Result<Arc<SDLSchema>> {\n    // Collect (content, file_path) pairs for each schema file\n    let schema_files: Vec<(String, String)> = schema_paths\n        .clone()\n        .into_iter()\n        .map(|pattern| {\n            // expand if path contains \"*\"\n            let paths = glob::glob(&pattern)\n                .map_err(|e| anyhow!(\"Invalid glob pattern '{}': {}\", pattern, e))?;\n            let file_entries: Result<Vec<(String, String)>> = paths\n                .map(|entry| {\n                    let file_path =\n                        entry.map_err(|e| anyhow!(\"Failed to read glob entry: {}\", e))?;\n                    let file_path_str = file_path.to_string_lossy().to_string();\n                    let schema_bytes = fs::read(file_path)?;\n                    let content = String::from_utf8(schema_bytes)\n                        .map_err(|e| anyhow!(\"Cannot parse schema utf8 from bytes: {}\", e))?;\n                    Ok((content, file_path_str))\n                })\n                .collect();\n            file_entries\n        })\n        .collect::<Result<Vec<_>>>()?\n        .into_iter()\n        .flatten()\n        .collect();\n\n    if schema_files.is_empty() {\n        return Err(anyhow!(\n            \"No schema loaded for paths: {}\",\n            schema_paths.join(\",\")\n        ));\n    }\n\n    // Build a source map for DiagnosticPrinter","sourceCodeStart":794,"sourceCodeEnd":830,"githubUrl":"https://github.com/facebook/relay/blob/668b1b85e06261aa3b58dabfc51f8b5524a70955/compiler/crates/graphql-ir-diff/src/lib.rs#L794-L830","documentation":"After a glob match is read into bytes, load_schema converts it to UTF-8 via String::from_utf8. Non-UTF-8 content aborts with 'Cannot parse schema utf8 from bytes'. SDL schema files must be valid UTF-8 text, so binary or wrongly-encoded files are rejected here.","triggerScenarios":"Calling load_schema/compare where a file matched by the schema glob is binary (e.g. a compiled artifact), UTF-16/Latin-1 encoded, or corrupted — from_utf8 fails and is wrapped into this anyhow error.","commonSituations":"Editors saving .graphql files with BOM/UTF-16 by misconfiguration; build artifacts accidentally matching '*.graphql' globs; files downloaded or committed with wrong encoding.","solutions":["Identify the offending file from the underlying from_utf8 error and re-save it as UTF-8.","Convert encodings (e.g. iconv -f UTF-16 -t UTF-8) for legacy files.","Exclude non-schema files from the glob (tighten to '*.graphql'/'*.sdl') so binaries never match.","Strip or normalize a UTF-8 BOM if tooling downstream chokes on it."],"exampleFix":"// shell\niconv -f UTF-16 -t UTF-8 schema.graphql > schema.utf8.graphql\n// after\nload_schema(vec![\"schemas/schema.utf8.graphql\".to_string()])?;","handlingStrategy":"validation","validationCode":"fn is_utf8_file(path: &str) -> bool {\n    std::fs::read(path).map(|b| std::str::from_utf8(&b).is_ok()).unwrap_or(false)\n}\n// pre-check all schema files\nfor f in schema_files { assert!(is_utf8_file(&f), \"non-UTF-8 schema file: {f}\"); }","typeGuard":null,"tryCatchPattern":"let schema = load_schema(patterns).map_err(|e| {\n    if e.to_string().contains(\"utf8\") {\n        anyhow!(\"schema files must be UTF-8; re-save the offending file: {e}\")\n    } else { e }\n});","preventionTips":["Configure editors/repos to save .graphql files as UTF-8 (add .gitattributes with *.graphql text).","Keep binaries out of globbed directories or tighten patterns.","Normalize BOMs in a preprocessing step."],"tags":["encoding","utf8","filesystem","schema"],"backgroundTag":"invalid-utf8-encoding","analyzedSha":"668b1b85e06261aa3b58dabfc51f8b5524a70955","analyzedAt":"2026-09-02T19:57:20.783Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}