{"record":{"id":"8663918f9cb67378","repo":"apache/beam","slug":"expected-v-to-end-with-v-can-t-generate-valid-code","errorCode":null,"errorMessage":"expected %v to end with %v. can't generate valid code","messagePattern":"expected (.+?) to end with (.+?)\\. can't generate valid code","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/util/shimx/generate.go","lineNumber":68,"sourceCode":"\tTypexImport    = \"github.com/apache/beam/sdks/v2/go/pkg/beam/core/typex\"\n\tReflectxImport = \"github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/reflectx\"\n\tRuntimeImport  = \"github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime\"\n\tSchemaImport   = \"github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/graphx/schema\"\n\tSdfImport      = \"github.com/apache/beam/sdks/v2/go/pkg/beam/core/sdf\"\n)\n\nfunc validateBeamImports() {\n\tcheckImportSuffix(ExecImport, \"exec\")\n\tcheckImportSuffix(TypexImport, \"typex\")\n\tcheckImportSuffix(ReflectxImport, \"reflectx\")\n\tcheckImportSuffix(RuntimeImport, \"runtime\")\n\tcheckImportSuffix(SchemaImport, \"schema\")\n\tcheckImportSuffix(SdfImport, \"sdf\")\n}\n\nfunc checkImportSuffix(path, suffix string) {\n\tif !strings.HasSuffix(path, suffix) {\n\t\tpanic(fmt.Sprintf(\"expected %v to end with %v. can't generate valid code\", path, suffix))\n\t}\n}\n\n// Top is the top level inputs into the template file for generating shims.\ntype Top struct {\n\tFileName, ToolName, Package string\n\n\tImports   []string // the full import paths\n\tFunctions []string // the plain names of the functions to be registered.\n\tTypes     []string // the plain names of the types to be registered.\n\tWraps     []Wrap\n\tEmitters  []Emitter\n\tInputs    []Input\n\tShims     []Func\n}\n\n// sort orders the shims consistently to minimize diffs in the generated code.\nfunc (t *Top) sort() {","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/util/shimx/generate.go#L50-L86","documentation":"checkImportSuffix validates that generated shim code's beam import paths end with an expected package suffix (e.g. SchemaImport ends with \"schema\", SdfImport ends with \"sdf\"); otherwise the generated code would not compile, so it panics with 'can't generate valid code'.","triggerScenarios":"Calling validateBeamImports (or checkImportSuffix directly) with an import path whose final segment doesn't match the required suffix — e.g. after renaming/moving the beam schema or SDF packages or overriding import constants with a wrong path.","commonSituations":"Forking Beam and changing module paths so sdks/go/pkg/beam/x/schema no longer ends in \"schema\"; typos when updating import path constants; vendoring rewrites (e.g. replace directives) altering the path tail.","solutions":["Correct the import path constant so it ends with the required suffix (\"schema\"/\"sdf\")","If the package moved, keep or alias the final path segment to match the expected suffix","Update the suffix expectation in generate.go if the suffix contract legitimately changed","Run the generator's tests to catch suffix mismatches before code generation"],"exampleFix":"// before\nconst SchemaImport = \"github.com/myfork/beam/sdks/go/pkg/beam/x/data\"\n// after\nconst SchemaImport = \"github.com/myfork/beam/sdks/go/pkg/beam/x/schema\"","handlingStrategy":"validation","validationCode":"if !strings.HasSuffix(SchemaImport, \"schema\") {\n\treturn fmt.Errorf(\"SchemaImport %q must end with 'schema'\", SchemaImport)\n}","typeGuard":"func endsWith(path, suffix string) bool { return strings.HasSuffix(path, suffix) }","tryCatchPattern":null,"preventionTips":["Keep beam import path constants in sync when forking/renaming modules","Preserve required package-name suffixes in module path rewrites","Run shim generator unit tests (validateBeamImports) before code generation"],"tags":["go","codegen","panic","imports"],"backgroundTag":"internal-invariant-violation","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}