Skip to content

Commit

Permalink
internal: add error context for n2 db processing (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
Young-Flash authored Sep 5, 2024
1 parent 36b7672 commit 95c6fb2
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 22 deletions.
16 changes: 6 additions & 10 deletions crates/moonbuild/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,9 @@ pub fn gen_n2_fmt_state(
default.push(inplace_format_action);

let mut hashes = n2graph::Hashes::default();
let db = n2::db::open(
&moonbuild_opt.target_dir.join("format.db"),
&mut graph,
&mut hashes,
)?;
let n2_db_path = &moonbuild_opt.target_dir.join("format.db");
let db = n2::db::open(n2_db_path, &mut graph, &mut hashes)
.with_context(|| format!("failed to process n2 db: {}", n2_db_path.display()))?;

Ok(State {
graph,
Expand Down Expand Up @@ -311,11 +309,9 @@ pub fn gen_n2_fmt_check_state(
default.push(format_to_action);

let mut hashes = n2graph::Hashes::default();
let db = n2::db::open(
&moonbuild_opt.target_dir.join("format.db"),
&mut graph,
&mut hashes,
)?;
let n2_db_path = &moonbuild_opt.target_dir.join("format.db");
let db = n2::db::open(n2_db_path, &mut graph, &mut hashes)
.with_context(|| format!("failed to process n2 db: {}", n2_db_path.display()))?;

Ok(State {
graph,
Expand Down
6 changes: 4 additions & 2 deletions crates/moonbuild/src/gen/gen_build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
// For inquiries, you can contact us via e-mail at [email protected].

use anyhow::{bail, Ok};
use anyhow::{bail, Context, Ok};
use moonutil::common::TargetBackend::*;
use moonutil::module::ModuleDB;
use moonutil::package::{JsFormat, Package};
Expand Down Expand Up @@ -443,7 +443,9 @@ pub fn gen_n2_build_state(
}

let mut hashes = n2graph::Hashes::default();
let db = n2::db::open(&target_dir.join("build.moon_db"), &mut graph, &mut hashes)?;
let n2_db_path = &target_dir.join("build.moon_db");
let db = n2::db::open(n2_db_path, &mut graph, &mut hashes)
.with_context(|| format!("failed to process n2 db: {}", n2_db_path.display()))?;

Ok(State {
graph,
Expand Down
6 changes: 4 additions & 2 deletions crates/moonbuild/src/gen/gen_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
// For inquiries, you can contact us via e-mail at [email protected].

use anyhow::bail;
use anyhow::{bail, Context};
use indexmap::IndexMap;
use moonutil::module::ModuleDB;
use moonutil::package::Package;
Expand Down Expand Up @@ -306,7 +306,9 @@ pub fn gen_n2_bundle_state(
let default = graph.get_start_nodes();

let mut hashes = n2graph::Hashes::default();
let db = n2::db::open(&target_dir.join("build.moon_db"), &mut graph, &mut hashes)?;
let n2_db_path = &target_dir.join("build.moon_db");
let db = n2::db::open(n2_db_path, &mut graph, &mut hashes)
.with_context(|| format!("failed to process n2 db: {}", n2_db_path.display()))?;

Ok(State {
graph,
Expand Down
6 changes: 4 additions & 2 deletions crates/moonbuild/src/gen/gen_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

use super::cmd_builder::CommandBuilder;
use crate::gen::MiAlias;
use anyhow::bail;
use anyhow::{bail, Context};
use indexmap::map::IndexMap;
use moonutil::module::ModuleDB;
use moonutil::package::Package;
Expand Down Expand Up @@ -367,7 +367,9 @@ pub fn gen_n2_check_state(
}

let mut hashes = n2graph::Hashes::default();
let db = n2::db::open(&target_dir.join("check.moon_db"), &mut graph, &mut hashes)?;
let n2_db_path = &target_dir.join("check.moon_db");
let db = n2::db::open(n2_db_path, &mut graph, &mut hashes)
.with_context(|| format!("failed to process n2 db: {}", n2_db_path.display()))?;

let default = graph.get_start_nodes();

Expand Down
10 changes: 4 additions & 6 deletions crates/moonbuild/src/gen/gen_runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
//
// For inquiries, you can contact us via e-mail at [email protected].

use anyhow::{bail, Ok};
use anyhow::{bail, Context, Ok};
use colored::Colorize;
use moonutil::common::{DriverKind, GeneratedTestDriver, MOONBITLANG_CORE};
use moonutil::module::ModuleDB;
Expand Down Expand Up @@ -917,11 +917,9 @@ pub fn gen_n2_runtest_state(
}

let mut hashes = n2graph::Hashes::default();
let db = n2::db::open(
&moonbuild_opt.target_dir.join("build.moon_db"),
&mut graph,
&mut hashes,
)?;
let n2_db_path = &moonbuild_opt.target_dir.join("build.moon_db");
let db = n2::db::open(n2_db_path, &mut graph, &mut hashes)
.with_context(|| format!("failed to process n2 db: {}", n2_db_path.display()))?;

Ok(State {
graph,
Expand Down

0 comments on commit 95c6fb2

Please sign in to comment.