Skip to content

Commit

Permalink
fix: handle absent body and rust-link as an error
Browse files Browse the repository at this point in the history
If there's neither a body element, nor a link rel="rust" element, then
there's no way to guess a location for inserting the wasm initializer.

Instead of silently ignoring, or adding a body element ourselves, we
raise this as an error.

Closes #791
  • Loading branch information
ctron committed May 10, 2024
1 parent 17d3842 commit 7a484b3
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/pipelines/rust/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{
config::{CrossOrigin, RtcBuild},
pipelines::rust::{sri::SriBuilder, RustAppType},
};
use anyhow::bail;
use std::collections::HashMap;
use std::sync::Arc;

Expand Down Expand Up @@ -102,7 +103,14 @@ impl RustAppOutput {

match self.id {
Some(id) => dom.replace_with_html(&trunk_id_selector(id), &script)?,
None => dom.append_html(body, &script)?,
None => {
if dom.len(&body)? == 0 {
bail!(
r#"Document has neither a <link data-trunk rel="rust"/> nor a <body>. Either one must be present."#
);
}
dom.append_html(body, &script)?
}
}

Ok(())
Expand Down

0 comments on commit 7a484b3

Please # to comment.