pub fn load_ir_modules_strict<A: Embed>(
manifest: &AssetManifest,
) -> Result<(HashMap<String, RenderMode>, HashMap<String, IrModule>), Vec<IrLoadError>>Expand description
The module loader: every module the manifest declares, parsed and checked, or every failure, so the server can refuse to start.
The default from 0.2.2. Call it at start, before the port binds, and stop
on Err: a module that is missing, corrupt, truncated or from another
format version for a server-rendered route is a failed deploy, and CI and
staging are where it should surface: one bad module refuses start,
for every route. Each IrLoadError names the route, the file and
a code. A route the build declares ssr: false carries no ir in the
manifest and needs no module: it is not an error, and not in the maps.
use forma_server::{assets, load_ir_modules_strict};
fn start<Assets: rust_embed::Embed>() -> Result<(), String> {
let manifest = assets::try_load_manifest::<Assets>()?;
let (render_modes, modules) = load_ir_modules_strict::<Assets>(&manifest).map_err(|errors| {
let names: Vec<String> = errors.iter().map(|e| e.to_string()).collect();
names.join("; ") // e.g. "route /: IR file page.ir: LOAD-103 ..."
})?;
// ...only now bind the port.
Ok(())
}To have a debug build reread a page’s module when the build’s watch mode
rewrites it, load with IrModules::load instead: the same check and
errors.
Verified by: crates/forma-server/tests/strict_loader.rs > “with_a_bad_module_the_fixture_server_binds_no_port”