{"record":{"id":"864f9a5b3c5de033","repo":"BoundaryML/baml","slug":"failed-to-generate-go-sdk-error","errorCode":null,"errorMessage":"failed to generate Go SDK: {error}","messagePattern":"failed to generate Go SDK: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_cli/src/generate.rs","lineNumber":492,"sourceCode":"                        .files\n                        .into_iter()\n                        .map(|(path, content)| (path, content.into_bytes()))\n                        .collect()\n                }\n                OutputType::Go => sdkgen_go::try_to_source_code_with_bytecode_and_metadata_and_options(\n                    &pool,\n                    &baml_bytecode,\n                    &embedded_baml_toml,\n                    &sdkgen_go::GoGenOptions {\n                        naming_convention: generator.naming_convention,\n                        sdk_import_path: generator\n                            .sdk_import_path\n                            .as_deref()\n                            .expect(\"validated Go generator must have sdk_import_path\"),\n                        max_typed_union_arity: generator.max_typed_union_arity,\n                    },\n                )\n                .map_err(|error| anyhow!(\"failed to generate Go SDK: {error}\"))?\n                .into_iter()\n                .map(|(path, content)| (path, content.into_bytes()))\n                .collect(),\n                OutputType::Cpp => {\n                    // The C++ emitter embeds source paths (reference\n                    // comments only); the runtime payload is the bytecode.\n                    let source_paths: Vec<PathBuf> = source_files\n                        .iter()\n                        .map(|sf| {\n                            let path = sf.path(&db);\n                            path.strip_prefix(&from).unwrap_or(&path).to_path_buf()\n                        })\n                        .collect();\n                    sdkgen_cpp::to_source_code_with_bytecode_and_metadata(\n                        &pool,\n                        &source_paths,\n                        &baml_bytecode,\n                        &embedded_baml_toml,","sourceCodeStart":474,"sourceCodeEnd":510,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_cli/src/generate.rs#L474-L510","documentation":"`baml generate` wraps the Go SDK code emitter and converts any failure from it into this anyhow error at generate.rs:492. It means the Go code generator failed while producing the SDK for a `generator go` block; the inner `{error}` carries the underlying cause. The error surfaces only after the config has been validated (e.g. sdk_import_path was already checked via expect).","triggerScenarios":"Running `baml generate` with a Go generator whose emitter fails: invalid or conflicting Go module/import path settings, unreadable output directory, or an internal emitter bug while rendering Go source files.","commonSituations":"Misconfigured `sdk_import_path` or `output_dir` in baml.generators, filesystem permission problems, or version drift between the CLI and the Go emitter.","solutions":["Read the inner `{error}` text to identify the underlying emitter failure","Verify the Go generator block in baml.generators: sdk_import_path, output_dir, and module settings are correct","Ensure the output directory exists and is writable","Update the BAML CLI/toolchain to the latest version"],"exampleFix":"// before\ngenerator go Client {\n  output_dir \"../go\"\n  sdk_import_path \"\"\n}\n// after\ngenerator go Client {\n  output_dir \"../go/gen\"\n  sdk_import_path \"github.com/myorg/myrepo/gen\"\n}","handlingStrategy":"try-catch","validationCode":"// before generating, validate the generator config\ntoml::from_str::<Config>(&std::fs::read_to_string(\"baml.toml\")?)?;\nassert!(!gen.sdk_import_path.is_empty(), \"sdk_import_path required for Go generator\");\nassert!(Path::new(&gen.output_dir).is_dir() || std::fs::create_dir_all(&gen.output_dir).is_ok());","typeGuard":null,"tryCatchPattern":"match baml_cli::generate() {\n    Err(e) if e.to_string().contains(\"failed to generate Go SDK\") => {\n        eprintln!(\"Go emitter failed: {e:#}\"); // inspect chained cause\n    }\n    Err(e) => return Err(e),\n    Ok(files) => write_files(files)?,\n}","preventionTips":["Validate sdk_import_path and output_dir in CI before running baml generate","Pin the BAML CLI version in CI to avoid emitter regressions","Keep generated directories clean and writable"],"tags":["go","codegen","cli"],"backgroundTag":"code-generation-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}