{"record":{"id":"0d35caa619b9d329","repo":"stride3d/stride","slug":"string-join-environment-newline-loggerresult-messages-where","errorCode":null,"errorMessage":"string.Join(Environment.NewLine, loggerResult.Messages.Where(m => m.Type >= LogMessageType.Error).Select(m => m.ToString()))","messagePattern":"string\\.Join\\(Environment\\.NewLine, loggerResult\\.Messages\\.Where\\(m => m\\.Type >= LogMessageType\\.Error\\)\\.Select\\(m => m\\.ToString\\(\\)\\)\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Compilers/ShaderLoaderBase.cs","lineNumber":183,"sourceCode":"\n    protected virtual bool LoadFromCode(string? filename, string code, ObjectId hash, ReadOnlySpan<ShaderMacro> macros, out ShaderBuffers buffer, bool registerInCache = true, bool emitSourceHash = true)\n    {\n        var defines = new (string Name, string Definition)[macros.Length];\n        for (int i = 0; i < macros.Length; ++i)\n            defines[i] = (macros[i].Name, macros[i].Definition);\n\n        var text = MonoGamePreProcessor.Run(code, filename, defines);\n        var sdslc = new SDSLC\n        {\n            ShaderLoader = this,\n        };\n\n        // Use provided logger, or a temporary one that throws on errors\n        var log = Log ?? new LoggerResult();\n        if (!sdslc.Compile(filename, text, hash, macros, log, out buffer, new() { RegisterInCache = registerInCache, EmitSourceHash = emitSourceHash, OriginalCode = code }))\n        {\n            if (log is LoggerResult loggerResult && loggerResult.HasErrors)\n                throw new InvalidOperationException(string.Join(Environment.NewLine, loggerResult.Messages.Where(m => m.Type >= LogMessageType.Error).Select(m => m.ToString())));\n            return false;\n        }\n        return true;\n    }\n}\n","sourceCodeStart":165,"sourceCodeEnd":189,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Compilers/ShaderLoaderBase.cs#L165-L189","documentation":"In ShaderLoaderBase.LoadFromCode, the SDSLC compile is invoked with a caller-provided or temporary LoggerResult. When compilation fails and that logger actually recorded error-level messages, the loader throws InvalidOperationException whose message is the newline-joined text of all messages with Type >= LogMessageType.Error — i.e. the real compiler diagnostics. If the logger has no recorded errors it returns false instead, so this throw always carries concrete compile output.","triggerScenarios":"sdslc.Compile returns false with RegisterInCache/EmitSourceHash options and the loggerResult.HasErrors is true — i.e. any SDSL compile error (parse, semantic, macro expansion) during LoadFromCode.","commonSituations":"Editing .sdsl files with syntax errors; invalid keyword/annotation usage; shader referencing missing mixins or types; macro combinations that generate invalid code.","solutions":["Read the exception message: it contains each compiler error line; fix the offending .sdsl source at the reported positions.","Check for recent edits to the shader and its included/composed sources.","Verify macros/defines passed in don't enable conflicting code paths that fail to compile.","Re-run compilation after fixing; clear the shader cache so a failed buffer is not reused."],"exampleFix":"// before (SDSL)\nstage float4 main() { return float4(1,0,0; } // missing ')' -> compile error\n// after\nstage float4 main() { return float4(1,0,0); }","handlingStrategy":"try-catch","validationCode":"// pre-lint the SDSL source with the same macros in a scratch LoggerResult\nvar pre = new LoggerResult();\nsdslc.Compile(filename, text, hash, macros, pre, out _, new() { RegisterInCache = false });\nbool compiles = !pre.HasErrors;","typeGuard":null,"tryCatchPattern":"try { loader.LoadFromCode(filename, text, hash, macros, out var buffer); }\ncatch (InvalidOperationException ex)\n{\n    // message contains joined compiler errors\n    foreach (var line in ex.Message.Split(Environment.NewLine))\n        Console.Error.WriteLine(line);\n}","preventionTips":["Parse the exception message — it lists every error with file/line.","Keep a compile-check step in CI for all .sdsl sources.","Clear the shader cache after compiler upgrades so stale failures don't persist."],"tags":["shader","compilation-failed","compiler-diagnostics"],"backgroundTag":"compilation-failed","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}