From 8c4b4c11c084f17bde46a4e8583f0a5e9f1c6828 Mon Sep 17 00:00:00 2001 From: Li Junchen Date: Fri, 6 Sep 2024 17:57:45 +0800 Subject: [PATCH 1/2] improve n2 error message --- Cargo.lock | 2 +- crates/moonbuild/src/fmt.rs | 6 ++---- crates/moonbuild/src/gen/gen_build.rs | 3 +-- crates/moonbuild/src/gen/gen_bundle.rs | 3 +-- crates/moonbuild/src/gen/gen_check.rs | 3 +-- crates/moonbuild/src/gen/gen_runtest.rs | 3 +-- crates/moonbuild/src/gen/n2_errors.rs | 9 +++------ 7 files changed, 10 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b0ad29a9..3ccc5524 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1443,7 +1443,7 @@ dependencies = [ [[package]] name = "n2" version = "0.1.4" -source = "git+https://github.com/moonbitlang/n2.git#d5bc0ccafbfb4b76eab7d1036746ad93bff59e45" +source = "git+https://github.com/moonbitlang/n2.git#57092cd9bb9c16670052a5ef8a2dc58c2f622078" dependencies = [ "anyhow", "argh", diff --git a/crates/moonbuild/src/fmt.rs b/crates/moonbuild/src/fmt.rs index 4a3dd92d..e2afc71c 100644 --- a/crates/moonbuild/src/fmt.rs +++ b/crates/moonbuild/src/fmt.rs @@ -215,8 +215,7 @@ pub fn gen_n2_fmt_state( let mut hashes = n2graph::Hashes::default(); let n2_db_path = &moonbuild_opt.target_dir.join("format.db"); let db = n2::db::open(n2_db_path, &mut graph, &mut hashes).map_err(|e| N2Error { - path: n2_db_path.to_path_buf(), - source: N2ErrorKind::OpenDataBaseError(e), + source: N2ErrorKind::DBOpenError(e), })?; Ok(State { @@ -314,8 +313,7 @@ pub fn gen_n2_fmt_check_state( let mut hashes = n2graph::Hashes::default(); let n2_db_path = &moonbuild_opt.target_dir.join("format.db"); let db = n2::db::open(n2_db_path, &mut graph, &mut hashes).map_err(|e| N2Error { - path: n2_db_path.to_path_buf(), - source: N2ErrorKind::OpenDataBaseError(e), + source: N2ErrorKind::DBOpenError(e), })?; Ok(State { diff --git a/crates/moonbuild/src/gen/gen_build.rs b/crates/moonbuild/src/gen/gen_build.rs index 5f16096f..b9ae1f79 100644 --- a/crates/moonbuild/src/gen/gen_build.rs +++ b/crates/moonbuild/src/gen/gen_build.rs @@ -446,8 +446,7 @@ pub fn gen_n2_build_state( let mut hashes = n2graph::Hashes::default(); let n2_db_path = &target_dir.join("build.moon_db"); let db = n2::db::open(n2_db_path, &mut graph, &mut hashes).map_err(|e| N2Error { - path: n2_db_path.to_path_buf(), - source: N2ErrorKind::OpenDataBaseError(e), + source: N2ErrorKind::DBOpenError(e), })?; Ok(State { diff --git a/crates/moonbuild/src/gen/gen_bundle.rs b/crates/moonbuild/src/gen/gen_bundle.rs index cd586ad2..927a1858 100644 --- a/crates/moonbuild/src/gen/gen_bundle.rs +++ b/crates/moonbuild/src/gen/gen_bundle.rs @@ -309,8 +309,7 @@ pub fn gen_n2_bundle_state( let mut hashes = n2graph::Hashes::default(); let n2_db_path = &target_dir.join("build.moon_db"); let db = n2::db::open(n2_db_path, &mut graph, &mut hashes).map_err(|e| N2Error { - path: n2_db_path.to_path_buf(), - source: N2ErrorKind::OpenDataBaseError(e), + source: N2ErrorKind::DBOpenError(e), })?; Ok(State { diff --git a/crates/moonbuild/src/gen/gen_check.rs b/crates/moonbuild/src/gen/gen_check.rs index b416ec0e..893a782b 100644 --- a/crates/moonbuild/src/gen/gen_check.rs +++ b/crates/moonbuild/src/gen/gen_check.rs @@ -370,8 +370,7 @@ pub fn gen_n2_check_state( let mut hashes = n2graph::Hashes::default(); let n2_db_path = &target_dir.join("check.moon_db"); let db = n2::db::open(n2_db_path, &mut graph, &mut hashes).map_err(|e| N2Error { - path: n2_db_path.to_path_buf(), - source: N2ErrorKind::OpenDataBaseError(e), + source: N2ErrorKind::DBOpenError(e), })?; let default = graph.get_start_nodes(); diff --git a/crates/moonbuild/src/gen/gen_runtest.rs b/crates/moonbuild/src/gen/gen_runtest.rs index 7397c282..7d9a81c8 100644 --- a/crates/moonbuild/src/gen/gen_runtest.rs +++ b/crates/moonbuild/src/gen/gen_runtest.rs @@ -920,8 +920,7 @@ pub fn gen_n2_runtest_state( let mut hashes = n2graph::Hashes::default(); let n2_db_path = &moonbuild_opt.target_dir.join("build.moon_db"); let db = n2::db::open(n2_db_path, &mut graph, &mut hashes).map_err(|e| N2Error { - path: n2_db_path.to_path_buf(), - source: N2ErrorKind::OpenDataBaseError(e), + source: N2ErrorKind::DBOpenError(e), })?; Ok(State { diff --git a/crates/moonbuild/src/gen/n2_errors.rs b/crates/moonbuild/src/gen/n2_errors.rs index cc032569..fbe07bd7 100644 --- a/crates/moonbuild/src/gen/n2_errors.rs +++ b/crates/moonbuild/src/gen/n2_errors.rs @@ -16,18 +16,15 @@ // // For inquiries, you can contact us via e-mail at jichuruanjian@idea.edu.cn. -use std::path::PathBuf; - #[derive(Debug, thiserror::Error)] -#[error("internal build state error: {path}")] +#[error("internal error")] pub struct N2Error { - pub path: PathBuf, #[source] pub(crate) source: N2ErrorKind, } #[derive(Debug, thiserror::Error)] pub enum N2ErrorKind { - #[error("failed to open build database")] - OpenDataBaseError(#[from] anyhow::Error), + #[error("failed to open n2 database")] + DBOpenError(#[from] n2::db::OpenError), } From c346c54d7befeba5927203165a8d9af76b028b68 Mon Sep 17 00:00:00 2001 From: Li Junchen Date: Fri, 6 Sep 2024 17:57:50 +0800 Subject: [PATCH 2/2] update tests --- crates/moon/tests/test_cases/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/moon/tests/test_cases/mod.rs b/crates/moon/tests/test_cases/mod.rs index 89e541c2..008b2068 100644 --- a/crates/moon/tests/test_cases/mod.rs +++ b/crates/moon/tests/test_cases/mod.rs @@ -6220,11 +6220,13 @@ fn test_failed_to_fill_whole_buffer() { check( &get_stderr_with_args_and_replace_dir(&dir, ["check"]), expect![[r#" - error: internal build state error: $ROOT/target/wasm-gc/release/check/check.moon_db + error: internal error Caused by: - 0: failed to open build database - 1: failed to fill whole buffer + 0: failed to open n2 database + 1: failed to open $ROOT/target/wasm-gc/release/check/check.moon_db + 2: failed to read + 3: failed to fill whole buffer "#]], ); }