Browse Source

Fail documentation generation for invalid examples

Bzero 1 year ago
parent
commit
0d47f95d0b
2 changed files with 24 additions and 16 deletions
  1. 21 15
      book/build.py
  2. 3 1
      numbat/examples/inspect.rs

+ 21 - 15
book/build.py

@@ -2,6 +2,7 @@ import subprocess
 from pathlib import Path
 import urllib.parse
 import os
+import sys
 
 
 SCRIPT_DIR = Path(__file__).parent.resolve()
@@ -122,21 +123,26 @@ def list_of_functions(file_name, document):
                 )
                 env = os.environ.copy()
                 env["TZ"] = "UTC"
-                subprocess.run(
-                    [
-                        "cargo",
-                        "run",
-                        "--release",
-                        "--quiet",
-                        "--example=inspect",
-                        "--",
-                        "functions",
-                        module,
-                    ],
-                    stdout=f,
-                    text=True,
-                    env=env,
-                )
+
+                try:
+                    subprocess.run(
+                        [
+                            "cargo",
+                            "run",
+                            "--release",
+                            "--quiet",
+                            "--example=inspect",
+                            "--",
+                            "functions",
+                            module,
+                        ],
+                        stdout=f,
+                        text=True,
+                        env=env,
+                        check=True
+                    )
+                except subprocess.CalledProcessError as e:
+                    sys.exit(e.returncode)
 
 
 list_of_functions(

+ 3 - 1
numbat/examples/inspect.rs

@@ -5,6 +5,7 @@ use numbat::module_importer::FileSystemImporter;
 use numbat::resolver::CodeSource;
 use numbat::Context;
 use std::path::Path;
+use std::process::exit;
 
 const AUTO_GENERATED_HINT: &str = "<!-- NOTE! This file is auto-generated -->";
 
@@ -148,8 +149,9 @@ fn inspect_functions_in_module(ctx: &Context, prelude_ctx: &Context, module: Str
                     println!();
                 } else {
                     eprintln!(
-                        "Warning: Example \"{example_code}\" of function {fn_name} did not run successfully."
+                        "Error: Example \"{example_code}\" of function {fn_name} did not run successfully."
                     );
+                    exit(1);
                 }
             }
             println!("</details>");