{"record":{"id":"9443f2b899164ebc","repo":"bevyengine/bevy","slug":"could-not-parse-shader-0","errorCode":null,"errorMessage":"Could not parse shader: {0}","messagePattern":"Could not parse shader: (.+?)","errorType":"exception","errorClass":"ShaderLoaderError","httpStatus":null,"severity":"error","filePath":"crates/bevy_shader/src/shader.rs","lineNumber":253,"sourceCode":"        match self {\n            Source::Wgsl(s) | Source::Wesl(s) => s,\n            Source::SpirV(_) => panic!(\"spirv not yet implemented\"),\n        }\n    }\n}\n\n/// The [`AssetLoader`] responsible for loading unprocessed shader assets.\n#[derive(Default, TypePath)]\npub struct ShaderLoader;\n\n/// An error encountered while loading a shader's source.\n#[non_exhaustive]\n#[derive(Debug, Error)]\n#[expect(missing_docs, reason = \"The variants are self-explanatory.\")]\npub enum ShaderLoaderError {\n    #[error(\"Could not load shader: {0}\")]\n    Io(#[from] std::io::Error),\n    #[error(\"Could not parse shader: {0}\")]\n    Parse(#[from] alloc::string::FromUtf8Error),\n}\n\n/// Settings for loading shaders.\n#[derive(serde::Serialize, serde::Deserialize, Debug, Default)]\npub struct ShaderSettings {\n    /// The shader defs to apply when this shader is loaded.\n    pub shader_defs: Vec<ShaderDefVal>,\n}\n\nimpl AssetLoader for ShaderLoader {\n    type Asset = Shader;\n    type Settings = ShaderSettings;\n    type Error = ShaderLoaderError;\n    async fn load(\n        &self,\n        reader: &mut dyn Reader,\n        settings: &Self::Settings,","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/bevyengine/bevy/blob/396ca727080776bd313bb892423b7d94e03b81b4/crates/bevy_shader/src/shader.rs#L235-L271","documentation":"ShaderLoaderError::Parse from the ShaderLoader asset loader. The .wgsl/.wesl file's bytes were not valid UTF-8, so String::from_utf8 failed and the FromUtf8Error is wrapped with 'Could not parse shader'. (Despite the name, this is an encoding error, not a syntax error — WESL syntax problems surface later, in shader compilation.)","triggerScenarios":"Loading a .wgsl or .wesl file that contains non-UTF-8 bytes: a binary file with the wrong extension, a non-UTF-8 encoding (latin-1), or corrupted bytes. from_utf8(bytes)? fails during ShaderLoader::load.","commonSituations":"Renaming a binary/compiled artifact to .wgsl; editors or pipelines saving shaders in a legacy encoding; a .spv file mislabeled as .wgsl.","solutions":["Re-save the shader file as UTF-8 (without BOM issues) in your editor","Check the file extension matches the actual content — .spv binaries must use .spv","If the file is generated, fix the generator to emit UTF-8 text"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// fail fast on non-UTF-8 shader sources:\nif let Ok(bytes) = std::fs::read(&path) {\n    if std::str::from_utf8(&bytes).is_err() {\n        // re-encode as UTF-8 before the loader sees it\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Save all .wgsl/.wesl files as UTF-8","Match file extension to content: binary SPIR-V must be .spv, never .wgsl"],"tags":["bevy","shader","utf-8","encoding","asset-loader"],"backgroundTag":"invalid-utf8","analyzedSha":"396ca727080776bd313bb892423b7d94e03b81b4","analyzedAt":"2026-08-20T16:12:39.808Z","contentChangedAt":"2026-08-20T16:12:39.808Z","schemaVersion":2},"datasetVersion":"2026-09-09T01:17:15.007Z"}