-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: improve error messages for opening db failures * update test
- Loading branch information
Showing
8 changed files
with
93 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,13 @@ | |
// | ||
// For inquiries, you can contact us via e-mail at [email protected]. | ||
|
||
use anyhow::{bail, Context, Ok}; | ||
use anyhow::{bail, Ok}; | ||
use moonutil::common::TargetBackend::*; | ||
use moonutil::module::ModuleDB; | ||
use moonutil::package::{JsFormat, Package}; | ||
|
||
use super::cmd_builder::CommandBuilder; | ||
use super::n2_errors::{N2Error, N2ErrorKind}; | ||
use crate::gen::MiAlias; | ||
use std::path::{Path, PathBuf}; | ||
use std::rc::Rc; | ||
|
@@ -444,8 +445,10 @@ 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) | ||
.with_context(|| format!("failed to process n2 db: {}", n2_db_path.display()))?; | ||
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), | ||
})?; | ||
|
||
Ok(State { | ||
graph, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
// | ||
// For inquiries, you can contact us via e-mail at [email protected]. | ||
|
||
use anyhow::{bail, Context}; | ||
use anyhow::bail; | ||
use indexmap::IndexMap; | ||
use moonutil::module::ModuleDB; | ||
use moonutil::package::Package; | ||
|
@@ -29,6 +29,7 @@ use std::rc::Rc; | |
use moonutil::common::{MoonbuildOpt, MooncOpt, MOON_PKG_JSON}; | ||
|
||
use super::cmd_builder::CommandBuilder; | ||
use super::n2_errors::{N2Error, N2ErrorKind}; | ||
use crate::gen::MiAlias; | ||
|
||
#[derive(Debug)] | ||
|
@@ -307,8 +308,10 @@ 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) | ||
.with_context(|| format!("failed to process n2 db: {}", n2_db_path.display()))?; | ||
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), | ||
})?; | ||
|
||
Ok(State { | ||
graph, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,9 @@ | |
// For inquiries, you can contact us via e-mail at [email protected]. | ||
|
||
use super::cmd_builder::CommandBuilder; | ||
use super::n2_errors::{N2Error, N2ErrorKind}; | ||
use crate::gen::MiAlias; | ||
use anyhow::{bail, Context}; | ||
use anyhow::bail; | ||
use indexmap::map::IndexMap; | ||
use moonutil::module::ModuleDB; | ||
use moonutil::package::Package; | ||
|
@@ -368,8 +369,10 @@ 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) | ||
.with_context(|| format!("failed to process n2 db: {}", n2_db_path.display()))?; | ||
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), | ||
})?; | ||
|
||
let default = graph.get_start_nodes(); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
// | ||
// For inquiries, you can contact us via e-mail at [email protected]. | ||
|
||
use anyhow::{bail, Context, Ok}; | ||
use anyhow::{bail, Ok}; | ||
use colored::Colorize; | ||
use moonutil::common::{DriverKind, GeneratedTestDriver, MOONBITLANG_CORE}; | ||
use moonutil::module::ModuleDB; | ||
|
@@ -32,6 +32,7 @@ use n2::graph::{self as n2graph, Build, BuildIns, BuildOuts, FileLoc}; | |
use n2::load::State; | ||
use n2::smallmap::SmallMap; | ||
|
||
use crate::gen::n2_errors::{N2Error, N2ErrorKind}; | ||
use crate::gen::MiAlias; | ||
|
||
#[derive(Debug)] | ||
|
@@ -918,8 +919,10 @@ 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) | ||
.with_context(|| format!("failed to process n2 db: {}", n2_db_path.display()))?; | ||
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), | ||
})?; | ||
|
||
Ok(State { | ||
graph, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// moon: The build system and package manager for MoonBit. | ||
// Copyright (C) 2024 International Digital Economy Academy | ||
// | ||
// This program is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU Affero General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU Affero General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Affero General Public License | ||
// along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
// | ||
// For inquiries, you can contact us via e-mail at [email protected]. | ||
|
||
use std::path::PathBuf; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
#[error("internal build state error: {path}")] | ||
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), | ||
} |