mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
internal: use consistent style for error handling
This commit is contained in:
parent
49318bbae7
commit
6303551cb8
22 changed files with 128 additions and 134 deletions
|
@ -37,7 +37,7 @@ use std::{
|
|||
process::Command,
|
||||
};
|
||||
|
||||
use anyhow::{bail, format_err, Context, Result};
|
||||
use anyhow::{bail, format_err, Context};
|
||||
use paths::{AbsPath, AbsPathBuf};
|
||||
use rustc_hash::FxHashSet;
|
||||
|
||||
|
@ -60,19 +60,19 @@ pub enum ProjectManifest {
|
|||
}
|
||||
|
||||
impl ProjectManifest {
|
||||
pub fn from_manifest_file(path: AbsPathBuf) -> Result<ProjectManifest> {
|
||||
pub fn from_manifest_file(path: AbsPathBuf) -> anyhow::Result<ProjectManifest> {
|
||||
let path = ManifestPath::try_from(path)
|
||||
.map_err(|path| format_err!("bad manifest path: {}", path.display()))?;
|
||||
.map_err(|path| format_err!("bad manifest path: {path}"))?;
|
||||
if path.file_name().unwrap_or_default() == "rust-project.json" {
|
||||
return Ok(ProjectManifest::ProjectJson(path));
|
||||
}
|
||||
if path.file_name().unwrap_or_default() == "Cargo.toml" {
|
||||
return Ok(ProjectManifest::CargoToml(path));
|
||||
}
|
||||
bail!("project root must point to Cargo.toml or rust-project.json: {}", path.display());
|
||||
bail!("project root must point to Cargo.toml or rust-project.json: {path}");
|
||||
}
|
||||
|
||||
pub fn discover_single(path: &AbsPath) -> Result<ProjectManifest> {
|
||||
pub fn discover_single(path: &AbsPath) -> anyhow::Result<ProjectManifest> {
|
||||
let mut candidates = ProjectManifest::discover(path)?;
|
||||
let res = match candidates.pop() {
|
||||
None => bail!("no projects"),
|
||||
|
@ -156,7 +156,7 @@ impl fmt::Display for ProjectManifest {
|
|||
}
|
||||
}
|
||||
|
||||
fn utf8_stdout(mut cmd: Command) -> Result<String> {
|
||||
fn utf8_stdout(mut cmd: Command) -> anyhow::Result<String> {
|
||||
let output = cmd.output().with_context(|| format!("{cmd:?} failed"))?;
|
||||
if !output.status.success() {
|
||||
match String::from_utf8(output.stderr) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue