{"record":{"id":"d9a859f4bfeb71d8","repo":"stride3d/stride","slug":"cannot-read-from-getname","errorCode":null,"errorMessage":"Cannot read from {getName()}","messagePattern":"Cannot read from (.+?)","errorType":"exception","errorClass":"LexerException","httpStatus":null,"severity":"error","filePath":"sources/shaders/Stride.Shaders.Parsers/CppNet/Preprocessor.cs","lineNumber":70,"sourceCode":"\n`1'\n    This indicates the start of a new file.\n`2'\n    This indicates returning to a file (after having included another\n    file).\n`3'\n    This indicates that the following text comes from a system header\n    file, so certain warnings should be suppressed.\n`4'\n    This indicates that the following text should be treated as being\n    wrapped in an implicit extern \"C\" block.\n*/\n\ninternal class Preprocessor : IDisposable {\n    private class InternalSource : Source {\n        public override Token token()\n        {\n\t\t\tthrow new LexerException(\"Cannot read from \" + getName());\n\t\t}\n\n        internal override String getPath()\n        {\n\t\t\treturn \"<internal-data>\";\n\t\t}\n\t\t\n\t\tinternal override String getName() {\n\t\t\treturn \"internal data\";\n\t\t}\n    }\n\n\tprivate static readonly Source\t\tINTERNAL = new InternalSource();\n    private static readonly Macro\t\t__LINE__ = new Macro(INTERNAL, \"__LINE__\");\n\tprivate static readonly Macro\t\t__FILE__ = new Macro(INTERNAL, \"__FILE__\");\n\tprivate static readonly Macro\t\t__COUNTER__ = new Macro(INTERNAL, \"__COUNTER__\");\n\n\tprivate List<Source>\t\t\tinputs;","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/shaders/Stride.Shaders.Parsers/CppNet/Preprocessor.cs#L52-L88","documentation":"Preprocessor's InternalSource.token() always throws LexerException(\"Cannot read from <internal-data>\"): the internal source exists only to supply directives (e.g. pragma/state data) and has no tokens of its own. If the token stream ever tries to pull a token from it, the preprocessor's source stack is in an invalid state.","triggerScenarios":"Calling preprocessor.token()/tok() (or processing a pragma) when the current source on the stack is the InternalSource — i.e. all real input sources have been popped but tokenization continues, or push_source(InternalSource) was used without a subsequent pop before the next token request.","commonSituations":"Unbalanced push_source/pop_source around #include handling or pragma processing; continuing to call tok() after the real lexer source hit EOF; misusing the internal API to feed data without providing a real LexerSource.","solutions":["Ensure every push_source(InternalSource, ...) is paired with pop_source before requesting the next token.","Stop calling token()/tok() once the real source is exhausted (check for end-of-input instead of reading again).","Pass a real LexerSource (backed by the shader file/reader) to the Preprocessor rather than relying on internal data alone.","Install a PreprocessorListener to catch the earlier directive error that left the source stack unbalanced."],"exampleFix":"// before: reading tokens after the internal source was pushed\npp.push_source(new Preprocessor.InternalSource(), false);\n// ... forgot to pop ...\nvar t = pp.token(); // LexerException: Cannot read from <internal-data>\n// after\npp.push_source(new Preprocessor.InternalSource(), false);\n// ... directive work ...\npp.pop_source();\nvar t = pp.token();","handlingStrategy":"try-catch","validationCode":"// Check a real source is active before pulling tokens\nif (preprocessor.getCurrentSource() is Preprocessor.InternalSource)\n    preprocessor.pop_source();","typeGuard":"bool RealSourceActive(Preprocessor pp) => pp.getCurrentSource() is not Preprocessor.InternalSource;","tryCatchPattern":"try\n{\n    var tok = preprocessor.token();\n}\ncatch (LexerException ex) when (ex.Message.Contains(\"Cannot read from\"))\n{\n    throw new InvalidOperationException(\"Token requested with no active input source (unbalanced push_source/pop_source)\", ex);\n}","preventionTips":["Pair every push_source with pop_source, especially around pragma/include handling.","Stop calling tok()/token() once the real source reaches EOF.","Feed the preprocessor a real LexerSource instead of relying on InternalSource for data."],"tags":["preprocessor","lexer","internal-error"],"backgroundTag":"internal-invariant-violation","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}