tracel-ai/burn · error

The database file does not exist

Error message

The database file does not exist

What it means

`SqliteDatasetStorage::reader` panics when the sqlite database file referenced by the storage path does not exist (checked via `self.exists()`), before attempting to open it with `SqliteDataset::from_db_file`. It is a fail-fast guard so users get a clear message instead of a raw sqlite open error.

Source

Thrown at crates/burn-dataset/src/dataset/sqlite.rs:474

    {
        SqliteDatasetWriter::new(self.db_file(), overwrite)
    }

    /// Provides a reader instance for the SQLite dataset.
    ///
    /// # Arguments
    ///
    /// * `split` - A string slice that defines the data split for reading (e.g., "train", "test").
    ///
    /// # Returns
    ///
    /// * A `Result` which is `Ok` if the reader could be created, `Err` otherwise.
    pub fn reader<I>(&self, split: &str) -> Result<SqliteDataset<I>>
    where
        I: Clone + Send + Sync + Serialize + DeserializeOwned,
    {
        if !self.exists() {
            panic!("The database file does not exist");
        }

        SqliteDataset::from_db_file(self.db_file(), split)
    }
}

/// This `SqliteDatasetWriter` struct is a SQLite database writer dedicated to storing datasets.
/// It retains the current writer's state and its database connection.
///
/// Being thread-safe, this writer can be concurrently used across multiple threads.
///
/// Typical applications include:
///
/// - Generation of a new dataset
/// - Storage of preprocessed data or metadata
/// - Enlargement of a dataset's item count post preprocessing
#[derive(Debug)]
pub struct SqliteDatasetWriter<I> {

View on GitHub (pinned to d16f7ba2ed)

Solutions

  1. Check existence first with `storage.exists()` (or `Path::exists()`) and create the database (e.g. `SqliteDataset::from_dataset`, `from_df`, or `writer`) if missing.
  2. Fix the path: use an absolute path or resolve it relative to a known base (`CARGO_MANIFEST_DIR`, env var) instead of relying on cwd.
  3. Ensure the preprocessing/download step that produces the DB runs before the consuming code (CI ordering, feature-gated tasks).
  4. Correct filename typos/extension mismatches (.sqlite, .db).

Example fix

// before
let dataset = SqliteDatasetStorage::new("data/train.db").reader::<Sample>("train"); // panics if missing

// after
let storage = SqliteDatasetStorage::new("data/train.db");
assert!(storage.exists(), "run `cargo run --bin prepare-data` first");
let dataset = storage.reader::<Sample>("train")?;
Defensive patterns

Strategy: validation

Validate before calling

let storage = SqliteDatasetStorage::new(&db_path);
if !storage.exists() {
    return Err(anyhow!("SQLite dataset missing at {}: run the data-prep step first", db_path.display()));
}
let dataset = storage.reader::<Sample>(split)?;

Try / catch

// panic-based; check exists() before calling reader
if std::path::Path::new(&db_path).exists() {
    let ds = storage.reader::<Sample>(split)?;
}

Prevention

When it happens

Trigger: Calling `SqliteDatasetStorage::new(path).reader::<I>(split)` (or from_df/from_dataset then reader) when the file at `path` was never created, was deleted, or the path is relative and the process's working directory differs from expected.

Common situations: Typos in the DB filename; running from a different cwd in a test/binary so a relative path no longer resolves; forgetting to first call `from_dataset`/`writer`/`from_df` to create the database; datasets generated by a separate preprocessing step that was skipped; artifacts cleaned by CI before the test runs.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of tracel-ai/burn@d16f7ba2ed (2026-09-05). Data as JSON: /api/errors/f4b396b404efba61. Report an issue: GitHub.