{"record":{"id":"7a64d753c49c2461","repo":"pydantic/monty","slug":"failed-to-write-e","errorCode":null,"errorMessage":"failed to write {}: {e}","messagePattern":"failed to write (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/monty-python/build.rs","lineNumber":95,"sourceCode":"    // which would otherwise leave the metapackage frozen at an old release.\n    for (dist, found) in PINNED_DISTS.iter().zip(pins) {\n        assert_eq!(\n            found,\n            1,\n            \"expected exactly one `{dist}` pin in [project].dependencies of {}, found {found}\",\n            path.display()\n        );\n    }\n    assert_eq!(\n        versions,\n        1,\n        \"expected exactly one `version = \\\"...\\\"` line in {}, found {versions}\",\n        path.display()\n    );\n\n    if changed {\n        eprintln!(\"Updating {} to {pin_version}\", path.display());\n        fs::write(path, &result).unwrap_or_else(|e| panic!(\"failed to write {}: {e}\", path.display()));\n    }\n}\n\n/// The PyPI distributions the metapackage pins exactly; see [`sync_meta_pyproject`].\nconst PINNED_DISTS: [&str; 2] = [\"pydantic-monty-client\", \"pydantic-monty-runtime\"];\n\n/// The metapackage's pyproject.toml, which owns the `pydantic-monty` name on\n/// PyPI, or `None` when there is nothing to sync.\n///\n/// The metapackage has no Cargo package of its own to carry the version, so\n/// this build script — the one belonging to the distribution it pins —\n/// maintains it. It lives outside this crate, and maturin's sdist ships only\n/// the crate and its Rust path dependencies, so a source install legitimately\n/// has no metapackage and must not panic over that.\nfn meta_pyproject_path() -> Option<PathBuf> {\n    let path = PathBuf::from(env::var(\"CARGO_MANIFEST_DIR\").expect(\"CARGO_MANIFEST_DIR not set\"))\n        .join(\"../../packages/pydantic-monty/pyproject.toml\");\n    if path.is_file() {","sourceCodeStart":77,"sourceCodeEnd":113,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty-python/build.rs#L77-L113","documentation":"After rewriting version pins in packages/pydantic-monty/pyproject.toml, the build script writes the updated contents back. This panic means the fs::write failed — typically a permissions problem, a read-only filesystem, or the target path being a directory. The version sync cannot complete, so the build aborts.","triggerScenarios":"Cargo version changed (so `changed == true`) and the build script attempts to write packages/pydantic-monty/pyproject.toml while it is read-only, owned by another user, or lives on a read-only mount (e.g. packaged sources mounted ro in a container).","commonSituations":"Building inside a Docker container with the repo mounted read-only; bumping the workspace version locally when the file is owned by root; running a build as a non-privileged user in a shared checkout.","solutions":["Check and fix file permissions: chmod u+w packages/pydantic-monty/pyproject.toml (or chown to your user)","If the source tree is mounted read-only, copy the workspace to a writable location or run the build with the sources writable","If you did not intend a version change, ensure CARGO_PKG_VERSION matches the pins already in pyproject.toml so no write is needed"],"exampleFix":"// before\n$ cargo build  # after bumping version\npanicked: failed to write packages/pydantic-monty/pyproject.toml: Permission denied\n\n// after\nchmod u+w packages/pydantic-monty/pyproject.toml\ncargo build  # version synced, succeeds","handlingStrategy":"try-catch","validationCode":"[ -w packages/pydantic-monty/pyproject.toml ] && echo writable || echo 'not writable'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bump versions only in a writable checkout","Avoid read-only source mounts for builds; copy the tree to a writable dir","Ensure the build user owns the source files"],"tags":["build-script","cargo","file-write","permissions"],"backgroundTag":"file-write-failed","analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}