diesel-rs/diesel · error
Failed to read migration literals
Error message
Failed to read migration literals
What it means
The migration embedding macro failed while reading the SQL literals from the discovered migration directory. The offending input is the directory contents, such as unreadable files or malformed migration entries.
Solutions
- Ensure migration files exist and are readable
- Verify each migration file contains valid SQL
- Check directory permissions and file naming
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at diesel_migrations/migrations_macros/src/embed_migrations.rs:19 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of diesel-rs/diesel@6fa6ed01b2 (2026-09-07).
Data as JSON: /api/errors/5815901e8278c753.
Report an issue: GitHub.
Appendix: source
Thrown at diesel_migrations/migrations_macros/src/embed_migrations.rs:19
use crate::migrations::migration_directory_from_given_path;
use migrations_internals::{TomlMetadata, migrations_directories, version_from_string};
use quote::quote;
use std::error::Error;
use std::fs::DirEntry;
use std::path::Path;
pub fn expand(path: String) -> proc_macro2::TokenStream {
let migrations_path_opt = if path.is_empty() {
None
} else {
Some(path.replace('"', ""))
};
let migrations_expr = migration_directory_from_given_path(migrations_path_opt.as_deref())
.unwrap_or_else(|_| {
panic!("Failed to receive migrations dir from {migrations_path_opt:?}")
});
let embedded_migrations =
migration_literals_from_path(&migrations_expr).expect("Failed to read migration literals");
quote! {
diesel_migrations::EmbeddedMigrations::new(&[#(#embedded_migrations,)*])
}
}
fn migration_literals_from_path(
path: &Path,
) -> Result<Vec<proc_macro2::TokenStream>, Box<dyn Error>> {
let mut migrations = migrations_directories(path)?.collect::<Result<Vec<_>, _>>()?;
migrations.sort_by_key(DirEntry::path);
Ok(migrations
.into_iter()
.map(|e| migration_literal_from_path(&e.path()))
.collect())
}View on GitHub (pinned to 6fa6ed01b2)