stride3d/stride · warning · LexerException
Warning at
Error message
Warning at {line}:{column}: {msg} What it means
The C preprocessor emits warnings via Preprocessor.warning(). If a PreprocessorListener is installed, the warning is handed to listener.handleWarning(); if no listener exists, the warning is fatal and thrown as a LexerException. Additionally, if the Warning.ERROR flag is set, warnings are escalated to errors.
Solutions
- Install a PreprocessorListener (with handleWarning) on the Preprocessor so warnings are reported instead of thrown
- Remove or fix the offending #warning/construct in the shader source
- Unset the Warning.ERROR feature flag if warnings should not be fatal
- Catch LexerException around Preprocessor.process()/token() calls
Example fix
// before var pp = new Preprocessor(); pp.addInput(new FileLexer(sourceFile)); // after var pp = new Preprocessor(); pp.setListener(new MyPreprocessorListener()); pp.addInput(new FileLexer(sourceFile));
Defensive patterns
Strategy: try-catch
Validate before calling
if (pp.Listener == null) pp.setListener(new DefaultPreprocessorListener());
Type guard
bool hasListener = preprocessor.getListener() != null;
Try / catch
try { pp.addInput(lexer); pp.process(); } catch (LexerException e) { log.Warn($"Preprocessor warning escalated: {e.Message}"); } Prevention
- Always install a PreprocessorListener before processing
- Decide explicitly whether warnings should be fatal (Warning.ERROR)
When it happens
Trigger: Preprocessing shader source that triggers a preprocessor warning (e.g. #warning directive or questionable token handling) while no PreprocessorListener is attached to the Preprocessor, or while Warning.ERROR is set.
Common situations: Developers running the SDSL/CppNet preprocessor over shader files directly (console tools) without installing a listener; CI pipelines that enable warnings-as-errors and hit a #warning in shader code.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/37ebf196ffd3577e.
Report an issue: GitHub.
Appendix: source
Thrown at sources/shaders/Stride.Shaders.Parsers/CppNet/Preprocessor.cs:305
* @see #error(int, int, String)
*/
protected void error(Token tok, String msg) {
error(tok.getLine(), tok.getColumn(), msg);
}
/**
* Handles a warning.
*
* If a PreprocessorListener is installed, it receives the
* warning. Otherwise, an exception is thrown.
*/
protected void warning(int line, int column, String msg) {
if (warnings.HasFlag(Warning.ERROR))
error(line, column, msg);
else if (listener != null)
listener.handleWarning(source, line, column, msg);
else
throw new LexerException("Warning at " + line + ":" + column + ": " + msg);
}
/**
* Handles a warning.
*
* If a PreprocessorListener is installed, it receives the
* warning. Otherwise, an exception is thrown.
*
* @see #warning(int, int, String)
*/
protected void warning(Token tok, String msg) {
warning(tok.getLine(), tok.getColumn(), msg);
}
/**
* Adds a Macro to this Preprocessor.
*
* The given {@link Macro} object encapsulates both the nameView on GitHub (pinned to 96fad776d2)