{"record":{"id":"be35477ef9d08235","repo":"BoundaryML/baml","slug":"package-package-name-not-found-in-cargo-metadata","errorCode":null,"errorMessage":"package '{package_name}' not found in cargo metadata","messagePattern":"package '(.+?)' not found in cargo metadata","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/tools_size_gate/src/measure.rs","lineNumber":273,"sourceCode":"            if let Some(targets) = pkg[\"targets\"].as_array() {\n                for target in targets {\n                    let kinds = target[\"kind\"].as_array();\n                    let is_cdylib = kinds\n                        .map(|k| k.iter().any(|v| v.as_str() == Some(\"cdylib\")))\n                        .unwrap_or(false);\n                    if is_cdylib {\n                        if let Some(name) = target[\"name\"].as_str() {\n                            return Ok(name.to_owned());\n                        }\n                    }\n                }\n            }\n            // Fallback: use package name with hyphens replaced\n            return Ok(package_name.replace('-', \"_\"));\n        }\n    }\n\n    bail!(\"package '{package_name}' not found in cargo metadata\");\n}\n\n/// Platform-specific dynamic library filename.\nfn native_lib_filename(lib_name: &str) -> String {\n    if cfg!(target_os = \"macos\") {\n        format!(\"lib{lib_name}.dylib\")\n    } else if cfg!(target_os = \"windows\") {\n        format!(\"{lib_name}.dll\")\n    } else {\n        format!(\"lib{lib_name}.so\")\n    }\n}\n\n/// Measure a built artifact. When `strip` is false (WASM and `pack`\n/// outputs) the file is measured as-is; otherwise it is stripped to a\n/// temp copy first and the stripped size is recorded.\npub(crate) fn measure_artifact(artifact_path: &Path, strip: bool) -> Result<ArtifactMeasurement> {\n    let file_bytes = std::fs::metadata(artifact_path)","sourceCodeStart":255,"sourceCodeEnd":291,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/tools_size_gate/src/measure.rs#L255-L291","documentation":"resolve_lib_name searches cargo metadata packages for the given package name to derive the native library filename. When no package with that name exists in the workspace metadata it cannot even apply the hyphen-to-underscore fallback, so it bails with this message.","triggerScenarios":"locate_artifact is asked for a library artifact whose configured name does not correspond to any [package] name in the workspace's cargo metadata.","commonSituations":"Renaming a crate in Cargo.toml without updating size-gate config; adding a new crate but forgetting to register it in the artifact config; running the gate from a different workspace that doesn't contain the crate; typo in the package name.","solutions":["Check `cargo metadata --no-deps | jq '.packages[].name'` for the exact package name and correct the gate config.","If the crate was renamed, update both Cargo.toml references and the size-gate artifact config.","Ensure you run the gate in the workspace that actually contains the package.","Verify the name isn't confused with the lib target name (package name vs [lib] name can differ)."],"exampleFix":"// before\\nname = \"baml-core-wrong\"\\n// after: must match a [package] name in the workspace\\nname = \"baml-core\"","handlingStrategy":"validation","validationCode":"let names: Vec<String> = serde_json::from_slice::<serde_json::Value>(&metadata_stdout)?[\"packages\"]\\n    .as_array().unwrap().iter()\\n    .filter_map(|p| p[\"name\"].as_str().map(String::from)).collect();\\nassert!(names.contains(\"baml-core\"), \"package missing from workspace metadata\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep size-gate artifact names synchronized with [package] names.","Check `cargo metadata --no-deps` output when adding new crates to the config.","Distinguish package name from [lib] target name in configs.","Run the gate only within the workspace containing all configured packages."],"tags":["rust","cargo","config"],"backgroundTag":"entity-not-found","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"}