Skip to content

Commit

Permalink
Merge pull request #267 from moonbitlang/improve-n2-error-message
Browse files Browse the repository at this point in the history
Improve n2 error message
  • Loading branch information
lijunchen authored Sep 6, 2024
2 parents db845e3 + c346c54 commit f1db3a2
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions crates/moon/tests/test_cases/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
"#]],
);
}
6 changes: 2 additions & 4 deletions crates/moonbuild/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions crates/moonbuild/src/gen/gen_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions crates/moonbuild/src/gen/gen_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions crates/moonbuild/src/gen/gen_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions crates/moonbuild/src/gen/gen_runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 3 additions & 6 deletions crates/moonbuild/src/gen/n2_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

0 comments on commit f1db3a2

Please sign in to comment.