stride3d/stride · error · LexerException

Error at

Error message

Error at {line}:{column}: {msg}

What it means

Source.error() reports a preprocessing error: with a PreprocessorListener installed it calls listener.handleError(); otherwise it throws LexerException("Error at line:column: msg"). It is the base-class error channel used by all Lexer/Source implementations.

Solutions

  1. Install a PreprocessorListener to collect errors without exceptions
  2. Fix the shader source at the reported line:column
  3. Catch LexerException around preprocessing and surface the message
  4. Disable werror if a warning was escalated unintentionally

Example fix

// before
try { pp.process(); }
catch (LexerException e) { throw e; }
// after
pp.setListener(new CollectingListener());
try { pp.process(); }
catch (LexerException e) { log(e.Message); }
Defensive patterns

Strategy: try-catch

Validate before calling

if (source.getListener() == null) source.setListener(new DefaultPreprocessorListener());

Try / catch

try { RunPreprocessor(source); } catch (LexerException e) when (e.Message.StartsWith("Error at ")) { log.Error($"Shader preprocessing failed: {e.Message}"); }

Prevention

When it happens

Trigger: Any error diagnosed in a Source-derived lexer (bad tokens, unterminated constructs, #error directives) while no listener is attached — including warnings escalated via werror from warning().

Common situations: Running the preprocessor headlessly without a listener on malformed shader code; enabling warnings-as-errors so a mere warning surfaces here.

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/8b93a601421adc41. Report an issue: GitHub.

Appendix: source

Thrown at sources/shaders/Stride.Shaders.Parsers/CppNet/Source.cs:283

                    case Token.CPPCOMMENT:
                    case Token.WHITESPACE:
                        break;
                    default:
                        /* XXX Check white, if required. */
                        if(white)
                            warning(tok.getLine(), tok.getColumn(),
                                            "Unexpected nonwhite token");
                        break;
                }
            }
        }

        protected void error(int line, int column, String msg)
        {
            if(listener != null)
                listener.handleError(this, line, column, msg);
            else
                throw new LexerException("Error at " + line + ":" + column + ": " + msg);
        }

        protected void warning(int line, int column, String msg)
        {
            if(werror)
                error(line, column, msg);
            else if(listener != null)
                listener.handleWarning(this, line, column, msg);
            else
                throw new LexerException("Warning at " + line + ":" + column + ": " + msg);
        }

        public virtual void close()
        {
        }
    }

}

View on GitHub (pinned to 96fad776d2)