CodeSampleX

Sample

fs_extra 1.3.0: fs_extra::error::ErrorKind

Verified sample for cargo fs_extra 1.3.0: fs_extra::error::ErrorKind. The contract ran on rust 1 · linux alpine/x64 · docker and passed.

sha256:75f085c6706b954e96e97df31a4892982a9093e2559b98a38aa103e22a78ed1d

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux x64 cargo

Verification-run environments

Environment Contract Stages Run
rust 1 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · cargo@1rust:1-alpine@sha256:a10e64dd139b…
2026-11-22

Case

HOW
Goal
verify fs_extra::error::ErrorKind in pkg:cargo/fs_extra@1.3.0
Packages
Symbols
  • fs_extra::error::ErrorKind
Created
2026-11-22T16:05:31Z

Contract

  1. Error::new preserves all fs_extra::error::ErrorKind variants in Error.kind with Display and std::error::Error
  2. From<std::io::Error> maps NotFound, PermissionDenied, AlreadyExists, Interrupted, and Other directly and wraps other io::ErrorKind values in ErrorKind::Io
  3. From<std::path::StripPrefixError> and From<std::ffi::OsString> produce ErrorKind::StripPrefix and ErrorKind::OsString
  4. fs_extra operations report ErrorKind::NotFound, AlreadyExists, InvalidFileName, and Other for failing filesystem calls

Files

  • Cargo.lock
  • Cargo.toml
  • PROMPT.md
  • csx.json
  • spec.json
  • src/lib.rs
  • test/contract.rs

Download the source artifact (tar.gz)

Source

Cargo.lock
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4

[[package]]
name = "fs_extra"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c"

[[package]]
name = "sample-fs-extra-errorkind"
version = "0.1.0"
dependencies = [
 "fs_extra",
]
Cargo.toml
[package]
name = "sample-fs-extra-errorkind"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
fs_extra = "=1.3.0"

[[bin]]
name = "contract"
path = "test/contract.rs"
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify fs_extra::error::ErrorKind in pkg:cargo/fs_extra@1.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:cargo/fs_extra@1.3.0
Demonstrate these symbols/APIs:
  - fs_extra::error::ErrorKind

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:4c35ad009f304582863ad22d386383d443da2907efec4ca09e94254247a59bda","contract":["Error::new preserves all fs_extra::error::ErrorKind variants in Error.kind with Display and std::error::Error","From\u003cstd::io::Error\u003e maps NotFound, PermissionDenied, AlreadyExists, Interrupted, and Other directly and wraps other io::ErrorKind values in ErrorKind::Io","From\u003cstd::path::StripPrefixError\u003e and From\u003cstd::ffi::OsString\u003e produce ErrorKind::StripPrefix and ErrorKind::OsString","fs_extra operations report ErrorKind::NotFound, AlreadyExists, InvalidFileName, and Other for failing filesystem calls"],"goal":"verify fs_extra::error::ErrorKind in pkg:cargo/fs_extra@1.3.0","kind":"HOW","packages":["pkg:cargo/fs_extra@1.3.0"],"schemaVersion":1,"symbols":["fs_extra::error::ErrorKind"]},"contractCommand":["cargo","run","--offline"],"environment":{"arch":"x64","ecosystem":"cargo","os":"linux","packageManager":"cargo","schemaVersion":1},"license":"MIT-0","packages":["pkg:cargo/fs_extra@1.3.0"],"schemaVersion":1,"subject":"pkg:cargo/fs_extra@1.3.0","symbols":["fs_extra::error::ErrorKind"],"verifierAdapter":"cargo@1"}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify fs_extra::error::ErrorKind in pkg:cargo/fs_extra@1.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:cargo/fs_extra@1.3.0"
  ],
  "symbols": [
    "fs_extra::error::ErrorKind"
  ]
}
src/lib.rs
//! Clean-room verification sample for fs_extra::error::ErrorKind.

pub use fs_extra::error::ErrorKind;
test/contract.rs
use fs_extra::dir;
use fs_extra::error::{Error, ErrorKind};
use fs_extra::file;
use std::error::Error as StdError;
use std::ffi::OsString;
use std::io;
use std::path::Path;

fn main() {
    // 1. Error::new preserves each ErrorKind variant, Display message, and std::error::Error impl
    let direct_kinds: Vec<(ErrorKind, &str)> = vec![
        (ErrorKind::NotFound, "missing entity"),
        (ErrorKind::PermissionDenied, "denied"),
        (ErrorKind::AlreadyExists, "exists"),
        (ErrorKind::Interrupted, "interrupted"),
        (ErrorKind::InvalidFolder, "not a folder"),
        (ErrorKind::InvalidFile, "not a file"),
        (ErrorKind::InvalidFileName, "bad file name"),
        (ErrorKind::InvalidPath, "bad path"),
        (ErrorKind::Other, "other failure"),
    ];

    for (kind, msg) in direct_kinds {
        let debug_repr = format!("{:?}", kind);
        let err = Error::new(kind, msg);
        assert_eq!(err.to_string(), msg);
        assert_eq!(format!("{:?}", err.kind), debug_repr);
        let std_err: &dyn StdError = &err;
        assert_eq!(std_err.to_string(), msg);
    }

    // 2. From<std::io::Error> maps known kinds directly and wraps remaining kinds in ErrorKind::Io
    let mapped_cases = [
        (io::ErrorKind::NotFound, "NotFound"),
        (io::ErrorKind::PermissionDenied, "PermissionDenied"),
        (io::ErrorKind::AlreadyExists, "AlreadyExists"),
        (io::ErrorKind::Interrupted, "Interrupted"),
        (io::ErrorKind::Other, "Other"),
    ];
    for (io_kind, expected_debug) in mapped_cases {
        let fs_err: Error = io::Error::new(io_kind, "io failure").into();
        assert_eq!(format!("{:?}", fs_err.kind), expected_debug);
        assert_eq!(fs_err.to_string(), "io failure");
    }

    let wrapped_io: Error = io::Error::new(io::ErrorKind::BrokenPipe, "pipe closed").into();
    match wrapped_io.kind {
        ErrorKind::Io(ref inner) => {
            assert_eq!(inner.kind(), io::ErrorKind::BrokenPipe);
            assert_eq!(inner.to_string(), "pipe closed");
        }
        other => panic!("expected ErrorKind::Io, got {:?}", other),
    }

    // 3. From<StripPrefixError> and From<OsString> produce ErrorKind::StripPrefix and ErrorKind::OsString
    let strip_err = Path::new("alpha/beta").strip_prefix("gamma").unwrap_err();
    let fs_strip_err: Error = strip_err.into();
    assert!(matches!(fs_strip_err.kind, ErrorKind::StripPrefix(_)));

    let os_err: Error = OsString::from("non-utf8-placeholder").into();
    match os_err.kind {
        ErrorKind::OsString(ref value) => {
            assert_eq!(value, "non-utf8-placeholder");
        }
        other => panic!("expected ErrorKind::OsString, got {:?}", other),
    }

    // 4. Real fs_extra filesystem operations surface specific ErrorKind variants
    let base_dir = std::env::temp_dir().join(format!(
        "fs_extra_errorkind_contract_{}",
        std::process::id()
    ));
    let _ = dir::remove(&base_dir);
    dir::create_all(&base_dir, true).expect("create temp dir");

    let missing_file = base_dir.join("does_not_exist.txt");
    let read_err = file::read_to_string(&missing_file).unwrap_err();
    assert!(
        matches!(read_err.kind, ErrorKind::NotFound),
        "expected ErrorKind::NotFound, got {:?}",
        read_err.kind
    );

    let src_file = base_dir.join("src.txt");
    let dst_file = base_dir.join("dst.txt");
    file::write_all(&src_file, "source").expect("write source");
    file::write_all(&dst_file, "destination").expect("write destination");

    let file_opts = file::CopyOptions::new();
    let exists_err = file::copy(&src_file, &dst_file, &file_opts).unwrap_err();
    assert!(
        matches!(exists_err.kind, ErrorKind::AlreadyExists),
        "expected ErrorKind::AlreadyExists, got {:?}",
        exists_err.kind
    );

    let invalid_name_err =
        fs_extra::copy_items(&[""], &base_dir, &dir::CopyOptions::new()).unwrap_err();
    assert!(
        matches!(invalid_name_err.kind, ErrorKind::InvalidFileName),
        "expected ErrorKind::InvalidFileName, got {:?}",
        invalid_name_err.kind
    );

    let mut content_only_opts = dir::CopyOptions::new();
    content_only_opts.content_only = true;
    let other_err = fs_extra::copy_items(&[&src_file], &base_dir, &content_only_opts).unwrap_err();
    assert!(
        matches!(other_err.kind, ErrorKind::Other),
        "expected ErrorKind::Other, got {:?}",
        other_err.kind
    );

    dir::remove(&base_dir).expect("clean up temp dir");
    println!("All fs_extra::error::ErrorKind contract assertions passed.");
}

Origin Seeder

anonymous