{"record":{"id":"65cfa540e867696f","repo":"plandex-ai/plandex","slug":"error-validating-original-file-syntax-v","errorCode":null,"errorMessage":"error validating original file syntax: %v","messagePattern":"error validating original file syntax: (.+?)","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"app/server/model/plan/build_load.go","lineNumber":179,"sourceCode":"\tplanId := state.plan.Id\n\tbranch := state.branch\n\tfilePath := state.filePath\n\n\tactivePlan := GetActivePlan(planId, branch)\n\n\tif activePlan == nil {\n\t\treturn fmt.Errorf(\"active plan not found\")\n\t}\n\n\tconvoMessageId := activeBuild.ReplyId\n\n\tparser, lang, fallbackParser, fallbackLang := syntax.GetParserForPath(filePath)\n\n\tif parser != nil {\n\t\tvalidationRes, err := syntax.ValidateWithParsers(activePlan.Ctx, lang, parser, fallbackLang, fallbackParser, state.preBuildState)\n\t\tif err != nil {\n\t\t\tlog.Printf(\" error validating original file syntax: %v\\n\", err)\n\t\t\treturn fmt.Errorf(\"error validating original file syntax: %v\", err)\n\t\t}\n\n\t\tstate.language = validationRes.Lang\n\t\tstate.parser = validationRes.Parser\n\n\t\tstate.builderRun.Lang = string(validationRes.Lang)\n\n\t\tif validationRes.TimedOut {\n\t\t\tstate.syntaxCheckTimedOut = true\n\t\t} else if !validationRes.Valid {\n\t\t\tstate.preBuildStateSyntaxInvalid = true\n\t\t}\n\t}\n\n\tbuild := &db.PlanBuild{\n\t\tOrgId:          currentOrgId,\n\t\tPlanId:         planId,\n\t\tConvoMessageId: convoMessageId,","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/model/plan/build_load.go#L161-L197","documentation":"When a parser exists for the target file path, loadBuildFile validates the file's original (pre-build) syntax with syntax.ValidateWithParsers using the active plan context and the pre-build state. If that validation call itself errors (as opposed to reporting invalid syntax via validationRes.Valid), this error wraps and returns it. It indicates the syntax-validation machinery failed, not that the file is syntactically wrong.","triggerScenarios":"syntax.ValidateWithParsers returns an error: the tree-sitter/AST parser fails to initialize or load grammar for the language, the file cannot be read or encoded, the pre-build state is nil/corrupt, the validation context (activePlan.Ctx) is cancelled/timed out, or the parser panics/crashes on malformed input.","commonSituations":"Unsupported or mis-detected language for the file extension; very large or binary files choking the parser; cancelled context after a long build; tree-sitter grammar version mismatch after a dependency upgrade; file deleted on disk between build scheduling and validation.","solutions":["Read the underlying error logged just before this message to see whether it is a grammar load, file read, or context-cancel error.","Verify syntax.GetParserForPath returns the right parser for the file extension and that the grammar for that language is bundled/loaded.","Check the file exists and is readable (not deleted, not binary) before the build runs.","Increase the validation timeout / ensure activePlan.Ctx is not cancelled before validation completes.","Retry the build; if it reproduces on one file, isolate that file and report/fix the parser crash for that input."],"exampleFix":"// before\nvalidationRes, err := syntax.ValidateWithParsers(activePlan.Ctx, lang, parser, fallbackLang, fallbackParser, state.preBuildState)\nif err != nil {\n    return fmt.Errorf(\"error validating original file syntax: %v\", err)\n}\n// after\nif _, statErr := os.Stat(filePath); statErr != nil {\n    return fmt.Errorf(\"file missing before syntax validation: %v\", statErr)\n}\nvalidationRes, err := syntax.ValidateWithParsers(activePlan.Ctx, lang, parser, fallbackLang, fallbackParser, state.preBuildState)\nif err != nil {\n    log.Printf(\"syntax validation failed, continuing without validation: %v\", err)\n    validationRes = &syntax.ValidationResult{Valid: true, TimedOut: true}\n}","handlingStrategy":"fallback","validationCode":"parser, lang, fp, fl := syntax.GetParserForPath(filePath)\nif parser == nil {\n    return fmt.Errorf(\"no parser available for %s — syntax validation will be skipped\", filePath)\n}\nif _, err := os.Stat(filePath); err != nil {\n    return fmt.Errorf(\"file not readable before validation: %v\", err)\n}","typeGuard":"func syntaxValidatable(parser syntax.Parser, ctx context.Context, preBuild *types.PreBuildState) bool {\n    return parser != nil && ctx.Err() == nil && preBuild != nil\n}","tryCatchPattern":"err := runPlanBuild(...)\nif err != nil && strings.Contains(err.Error(), \"error validating original file syntax\") {\n    log.Printf(\"syntax validation infrastructure failed (%v); proceeding without AST checks\", err)\n    // fall back to a build without syntax validation or surface a warning\n}","preventionTips":["Confirm a grammar exists for every file extension your builds touch.","Keep files on disk (not deleted/moved) between scheduling and validation of a build.","Give validation a fresh, non-cancelled context with adequate timeout.","Pin tree-sitter grammar versions and test after upgrades.","Skip validation gracefully (parser == nil path) for unsupported languages instead of letting it error."],"tags":["syntax","parser","tree-sitter","validation"],"backgroundTag":"syntax-validation-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}