Repository: denoland/deno
Pull request: fix(compile): error when cannot extract binary section

We were silently failing on failure here.

Part of https://github.com/denoland/deno/issues/28982 -- This does not fix this issue, but maybe makes the error message better in the future.

Changed files:
filename: cli/rt/binary.rs
patch: @@ -57,9 +57,9 @@ pub struct StandaloneData {
 /// the bundle is executed. If not, this function exits with `Ok(None)`.
 pub fn extract_standalone(
   cli_args: Cow<Vec<OsString>>,
-) -> Result<Option<StandaloneData>, AnyError> {
+) -> Result<StandaloneData, AnyError> {
   let Some(data) = libsui::find_section("d3n0l4nd") else {
-    return Ok(None);
+    bail!("Could not find standalone binary section.")
   };
 
   let root_path = {
@@ -80,10 +80,7 @@ pub fn extract_standalone(
     modules_store: remote_modules,
     vfs_root_entries,
     vfs_files_data,
-  } = match deserialize_binary_data_section(&root_url, data)? {
-    Some(data_section) => data_section,
-    None => return Ok(None),
-  };
+  } = deserialize_binary_data_section(&root_url, data)?;
 
   let cli_args = cli_args.into_owned();
   metadata.argv.reserve(cli_args.len() - 1);
@@ -106,7 +103,7 @@ pub fn extract_standalone(
       metadata.vfs_case_sensitivity,
     ))
   };
-  Ok(Some(StandaloneData {
+  Ok(StandaloneData {
     metadata,
     modules: Arc::new(StandaloneModules {
       modules: remote_modules,
@@ -115,7 +112,7 @@ pub fn extract_standalone(
     npm_snapshot,
     root_path,
     vfs,
-  }))
+  })
 }
 
 pub struct DeserializedDataSection {
@@ -129,7 +126,7 @@ pub struct DeserializedDataSection {
 pub fn deserialize_binary_data_section(
   root_dir_url: &Url,
   data: &'static [u8],
-) -> Result<Option<DeserializedDataSection>, AnyError> {
+) -> Result<DeserializedDataSection, AnyError> {
   fn read_magic_bytes(input: &[u8]) -> Result<(&[u8], bool), AnyError> {
     if input.len() < MAGIC_BYTES.len() {
       bail!("Unexpected end of data. Could not find magic bytes.");
@@ -143,7 +140,7 @@ pub fn deserialize_binary_data_section(
 
   let (input, found) = read_magic_bytes(data)?;
   if !found {
-    return Ok(None);
+    bail!("Did not find magic bytes.");
   }
 
   // 1. Metadata
@@ -190,13 +187,13 @@ pub fn deserialize_binary_data_section(
     remote_modules_store,
   );
 
-  Ok(Some(DeserializedDataSection {
+  Ok(DeserializedDataSection {
     metadata,
     npm_snapshot,
     modules_store,
     vfs_root_entries,
     vfs_files_data,
-  }))
+  })
 }
 
 struct SpecifierStore {

filename: cli/rt/main.rs
patch: @@ -71,7 +71,7 @@ fn main() {
   let standalone = extract_standalone(Cow::Owned(args));
   let future = async move {
     match standalone {
-      Ok(Some(data)) => {
+      Ok(data) => {
         deno_runtime::deno_telemetry::init(
           otel_runtime_config(),
           data.metadata.otel_config.clone(),
@@ -85,15 +85,16 @@ fn main() {
         let exit_code = run::run(Arc::new(sys.clone()), sys, data).await?;
         deno_runtime::exit(exit_code);
       }
-      Ok(None) => Ok(()),
       Err(err) => {
         init_logging(None, None);
         Err(err)
       }
     }
   };
 
-  unwrap_or_exit(create_and_run_current_thread_with_maybe_metrics(future));
+  unwrap_or_exit::<()>(create_and_run_current_thread_with_maybe_metrics(
+    future,
+  ));
 }
 
 fn init_logging(