{"record":{"id":"63d17bdd44058aab","repo":"vitessio/vitess","slug":"generator-failed-for-type-s-w","errorCode":null,"errorMessage":"generator failed for type %s: %w","messagePattern":"generator failed for type (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/tools/asthelpergen/asthelpergen.go","lineNumber":397,"sourceCode":"\n\tfor _, g := range gen.gens {\n\t\tvar err error\n\t\tswitch underlying := underlying.(type) {\n\t\tcase *types.Interface:\n\t\t\terr = g.interfaceMethod(t, underlying, gen)\n\t\tcase *types.Slice:\n\t\t\terr = g.sliceMethod(t, underlying, gen)\n\t\tcase *types.Struct:\n\t\t\terr = g.structMethod(t, underlying, gen)\n\t\tcase *types.Pointer:\n\t\t\terr = gen.handlePointerType(t, underlying, g)\n\t\tcase *types.Basic:\n\t\t\terr = g.basicMethod(t, underlying, gen)\n\t\tdefault:\n\t\t\treturn fmt.Errorf(\"don't know how to handle type %s %T\", typeName, underlying)\n\t\t}\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"generator failed for type %s: %w\", typeName, err)\n\t\t}\n\t}\n\treturn nil\n}\n\n// handlePointerType handles pointer types by dispatching to the appropriate method\nfunc (gen *astHelperGen) handlePointerType(t types.Type, ptr *types.Pointer, g generator) error {\n\tptrToType := ptr.Elem().Underlying()\n\tswitch ptrToType := ptrToType.(type) {\n\tcase *types.Struct:\n\t\treturn g.ptrToStructMethod(t, ptrToType, gen)\n\tcase *types.Basic:\n\t\treturn g.ptrToBasicMethod(t, ptrToType, gen)\n\tdefault:\n\t\treturn fmt.Errorf(\"unsupported pointer type %T\", ptrToType)\n\t}\n}\n","sourceCodeStart":379,"sourceCodeEnd":415,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/tools/asthelpergen/asthelpergen.go#L379-L415","documentation":"asthelpergen generates helper methods (clone, visit, equals, etc.) for sqlparser AST types. processTypeWithGenerators dispatches each type to its registered generators; if any generator returns an error, the whole generation for that type is abandoned and this wrapped error is returned. The original generator error is preserved via %w so the root cause (e.g. an unsupported type kind) is visible.","triggerScenarios":"Running `go run ./go/tools/asthelpergen` with a generator that fails on a type in the processing queue — most often because the type's underlying kind hits the `default: don't know how to handle type` branch, or a code-writing generator (basicMethod, ptrToStructMethod, etc.) fails to emit code.","commonSituations":"A new AST node type or underlying kind (e.g. a new alias or interface type) was added to sqlparser and no generator handles it; a developer edited generator code and introduced a bug; running codegen after a parser grammar change introduces a type the tool cannot classify.","solutions":["Read the wrapped (%w) cause in the error chain to find which generator failed and why","Check the reported type's `underlying` kind; add a case for it in processTypeWithGenerators or in the relevant generator (e.g. basicMethod/ptrToStructMethod)","If the type is newly added to sqlparser, implement a generator for it or run `make codegen` after updating the tool's type dispatch","Re-run the tool after the fix; the type queue is processed deterministically so the same type will fail again until handled"],"exampleFix":"// before\ndefault:\n    return fmt.Errorf(\"don't know how to handle type %s %T\", typeName, underlying)\n// after\n// add a case for the new kind, e.g.\ncase *types.Interface:\n    err = g.interfaceMethod(t, underlying, gen)\ndefault:\n    return fmt.Errorf(\"don't know how to handle type %s %T\", typeName, underlying)","handlingStrategy":"try-catch","validationCode":"// Pre-scan types before running the tool\n// go run ./go/tools/asthelpergen in a scratch branch after any sqlparser AST change","typeGuard":"switch underlying.(type) {\ncase *types.Basic, *types.Struct, *types.Pointer, *types.Slice, *types.Interface, *types.Map:\n    // handled kinds\ndefault:\n    return fmt.Errorf(\"type %s (%T) has no generator; add one before running codegen\", typeName, underlying)\n}","tryCatchPattern":"err := processTypeQueue(g)\nif err != nil {\n    var genErr *fmt.wrapError\n    if errors.As(err, &genErr) {\n        log.Fatalf(\"asthelpergen: %v (cause: %v)\", err, errors.Unwrap(err))\n    }\n    return err\n}","preventionTips":["Run `make codegen` in CI so a new AST type without a generator fails fast, not locally later","Whenever adding an AST node type, check which underlying kind it resolves to and add generator coverage","Keep the type dispatch switch exhaustive and add tests for each generator"],"tags":["codegen","ast","go","tooling"],"backgroundTag":"codegen-generator-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}