gastownhall/beads · error
parse %s: %w
Error message
parse %s: %w
What it means
schemagen.Parse reads a Go source file with go/parser to extract exported struct types. This error wraps any failure of parser.ParseFile on typesPath, e.g. the file does not exist, is not valid Go, or has syntax errors. It is reported during Generate when reading the user-supplied types file.
Source
Thrown at internal/formula/schemagen/schemagen.go:55
Doc string
}
// Generate parses typesPath and returns gofmt'd source for schema_gen.go.
// The output is deterministic given the same input.
func Generate(typesPath string) ([]byte, error) {
prims, err := Parse(typesPath)
if err != nil {
return nil, err
}
return Render(prims)
}
// Parse extracts every exported struct in typesPath, sorted by name.
func Parse(typesPath string) ([]Primitive, error) {
fset := token.NewFileSet()
file, err := parser.ParseFile(fset, typesPath, nil, parser.ParseComments)
if err != nil {
return nil, fmt.Errorf("parse %s: %w", typesPath, err)
}
var prims []Primitive
for _, decl := range file.Decls {
gen, ok := decl.(*ast.GenDecl)
if !ok || gen.Tok != token.TYPE {
continue
}
for _, spec := range gen.Specs {
ts, ok := spec.(*ast.TypeSpec)
if !ok {
continue
}
if !ts.Name.IsExported() {
continue
}
st, ok := ts.Type.(*ast.StructType)
if !ok {View on GitHub (pinned to 71377f2769)
Solutions
- Verify typesPath exists and is a .go file (run `go build ./...` on it independently).
- Run `gofmt -e <file>` or `go vet` on the file to see the underlying syntax error.
- Correct the syntax error in the types file reported in the wrapped %w error.
- Ensure the path is correct relative to the working directory of the process calling Generate.
Example fix
// before
prims, err := schemagen.Parse("./types.go")
// after
prims, err := schemagen.Parse("internal/types/types.go") // correct, existing path Defensive patterns
Strategy: validation
Validate before calling
if info, err := os.Stat(typesPath); err != nil || info.IsDir() {
return fmt.Errorf("typesPath %q is not a readable file", typesPath)
}
if _, err := parser.ParseFile(token.NewFileSet(), typesPath, nil, parser.AllErrors); err != nil {
return fmt.Errorf("typesPath has syntax errors: %v", err)
} Try / catch
var pe *scanner.ErrorList
if errors.As(err, &pe) { for _, e := range *pe { log.Printf("%s:%d: %s", e.Pos.Filename, e.Pos.Line, e.Msg) } } Prevention
- Run `gofmt -e`/`go build` on generated types files before invoking schemagen.
- Use absolute or repo-root-relative paths for typesPath.
- Generate types files before running schemagen in build pipelines.
When it happens
Trigger: Calling Generate with a typesPath that points to a missing file, a directory, a non-Go file, or Go source containing syntax errors.
Common situations: Wrong path passed to the schema generator (typo or relative vs absolute path), generated code not yet written, or a Go file edited and left with a syntax error.
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/013a22fa1971021f.
Report an issue: GitHub.