apache/beam · error
expected to end with . can't generate valid code
Error message
expected %v to end with %v. can't generate valid code
What it means
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'.
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
Example fix
// before const SchemaImport = "github.com/myfork/beam/sdks/go/pkg/beam/x/data" // after const SchemaImport = "github.com/myfork/beam/sdks/go/pkg/beam/x/schema"
Defensive patterns
Strategy: validation
Validate before calling
if !strings.HasSuffix(SchemaImport, "schema") {
return fmt.Errorf("SchemaImport %q must end with 'schema'", SchemaImport)
} Type guard
func endsWith(path, suffix string) bool { return strings.HasSuffix(path, suffix) } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- AfterProcessingTime trigger set without a delay or…
- At least one subtrigger required for composite triggers.
- attempted to add namespace to missing coder id
- attempted to add namespace to missing windowing strategy id
- batch: failed to marshal worker UUID
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/8663918f9cb67378.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/util/shimx/generate.go:68
TypexImport = "github.com/apache/beam/sdks/v2/go/pkg/beam/core/typex"
ReflectxImport = "github.com/apache/beam/sdks/v2/go/pkg/beam/core/util/reflectx"
RuntimeImport = "github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime"
SchemaImport = "github.com/apache/beam/sdks/v2/go/pkg/beam/core/runtime/graphx/schema"
SdfImport = "github.com/apache/beam/sdks/v2/go/pkg/beam/core/sdf"
)
func validateBeamImports() {
checkImportSuffix(ExecImport, "exec")
checkImportSuffix(TypexImport, "typex")
checkImportSuffix(ReflectxImport, "reflectx")
checkImportSuffix(RuntimeImport, "runtime")
checkImportSuffix(SchemaImport, "schema")
checkImportSuffix(SdfImport, "sdf")
}
func checkImportSuffix(path, suffix string) {
if !strings.HasSuffix(path, suffix) {
panic(fmt.Sprintf("expected %v to end with %v. can't generate valid code", path, suffix))
}
}
// Top is the top level inputs into the template file for generating shims.
type Top struct {
FileName, ToolName, Package string
Imports []string // the full import paths
Functions []string // the plain names of the functions to be registered.
Types []string // the plain names of the types to be registered.
Wraps []Wrap
Emitters []Emitter
Inputs []Input
Shims []Func
}
// sort orders the shims consistently to minimize diffs in the generated code.
func (t *Top) sort() {View on GitHub (pinned to 12126d8942)