Display more descriptive error on missing manifest
Before: ``` ❯ aiken check Error: × No such file or directory (os error 2) ``` After: ``` ❯ aiken check Error: × Missing 'aiken.toml' manifest in /Users/ktorz/Documents/Projects/aiken-lang/aiken help: Try running `aiken new <REPOSITORY/PROJECT>` to initialise a project with an example manifest. ``` Co-authored-by: KtorZ <matthias.benkort@gmail.com>
This commit is contained in:
parent
a3591cc7dc
commit
bd816615d7
|
@ -1,9 +1,7 @@
|
||||||
use std::collections::BTreeMap;
|
|
||||||
use std::{env, path::PathBuf, process};
|
|
||||||
|
|
||||||
use aiken_project::{pretty, script::EvalInfo, telemetry, Project};
|
use aiken_project::{pretty, script::EvalInfo, telemetry, Project};
|
||||||
use miette::IntoDiagnostic;
|
use miette::IntoDiagnostic;
|
||||||
use owo_colors::OwoColorize;
|
use owo_colors::OwoColorize;
|
||||||
|
use std::{collections::BTreeMap, env, path::PathBuf, process};
|
||||||
use uplc::machine::cost_model::ExBudget;
|
use uplc::machine::cost_model::ExBudget;
|
||||||
|
|
||||||
pub mod cmd;
|
pub mod cmd;
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
use std::{fmt::Display, fs, path::PathBuf};
|
use crate::error::Error;
|
||||||
|
|
||||||
use aiken_lang::ast::Span;
|
use aiken_lang::ast::Span;
|
||||||
use miette::NamedSource;
|
use miette::NamedSource;
|
||||||
use serde::{de::Visitor, Deserialize, Serialize};
|
use serde::{de::Visitor, Deserialize, Serialize};
|
||||||
|
use std::{fmt::Display, fs, path::PathBuf};
|
||||||
use crate::error::Error;
|
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
@ -112,7 +110,8 @@ impl Display for Platform {
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn load(dir: PathBuf) -> Result<Config, Error> {
|
pub fn load(dir: PathBuf) -> Result<Config, Error> {
|
||||||
let config_path = dir.join("aiken.toml");
|
let config_path = dir.join("aiken.toml");
|
||||||
let raw_config = fs::read_to_string(&config_path)?;
|
let raw_config = fs::read_to_string(&config_path)
|
||||||
|
.map_err(|_| Error::MissingManifest { path: dir.clone() })?;
|
||||||
|
|
||||||
let result: Self = toml::from_str(&raw_config).map_err(|e| Error::TomlLoading {
|
let result: Self = toml::from_str(&raw_config).map_err(|e| Error::TomlLoading {
|
||||||
path: config_path.clone(),
|
path: config_path.clone(),
|
||||||
|
|
|
@ -52,6 +52,9 @@ pub enum Error {
|
||||||
help: String,
|
help: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
#[error("Missing 'aiken.toml' manifest in {path}")]
|
||||||
|
MissingManifest { path: PathBuf },
|
||||||
|
|
||||||
#[error("Cyclical module imports")]
|
#[error("Cyclical module imports")]
|
||||||
ImportCycle { modules: Vec<String> },
|
ImportCycle { modules: Vec<String> },
|
||||||
|
|
||||||
|
@ -175,6 +178,7 @@ impl Error {
|
||||||
Error::FileIo { .. } => None,
|
Error::FileIo { .. } => None,
|
||||||
Error::Format { .. } => None,
|
Error::Format { .. } => None,
|
||||||
Error::StandardIo(_) => None,
|
Error::StandardIo(_) => None,
|
||||||
|
Error::MissingManifest { path } => Some(path.to_path_buf()),
|
||||||
Error::TomlLoading { path, .. } => Some(path.to_path_buf()),
|
Error::TomlLoading { path, .. } => Some(path.to_path_buf()),
|
||||||
Error::ImportCycle { .. } => None,
|
Error::ImportCycle { .. } => None,
|
||||||
Error::List(_) => None,
|
Error::List(_) => None,
|
||||||
|
@ -195,6 +199,7 @@ impl Error {
|
||||||
Error::FileIo { .. } => None,
|
Error::FileIo { .. } => None,
|
||||||
Error::Format { .. } => None,
|
Error::Format { .. } => None,
|
||||||
Error::StandardIo(_) => None,
|
Error::StandardIo(_) => None,
|
||||||
|
Error::MissingManifest { .. } => None,
|
||||||
Error::TomlLoading { src, .. } => Some(src.to_string()),
|
Error::TomlLoading { src, .. } => Some(src.to_string()),
|
||||||
Error::ImportCycle { .. } => None,
|
Error::ImportCycle { .. } => None,
|
||||||
Error::List(_) => None,
|
Error::List(_) => None,
|
||||||
|
@ -243,6 +248,7 @@ impl Diagnostic for Error {
|
||||||
Error::Parse { .. } => Some(Box::new("aiken::parser")),
|
Error::Parse { .. } => Some(Box::new("aiken::parser")),
|
||||||
Error::Type { .. } => Some(Box::new("aiken::check")),
|
Error::Type { .. } => Some(Box::new("aiken::check")),
|
||||||
Error::StandardIo(_) => None,
|
Error::StandardIo(_) => None,
|
||||||
|
Error::MissingManifest { .. } => None,
|
||||||
Error::TomlLoading { .. } => Some(Box::new("aiken::loading::toml")),
|
Error::TomlLoading { .. } => Some(Box::new("aiken::loading::toml")),
|
||||||
Error::Format { .. } => None,
|
Error::Format { .. } => None,
|
||||||
Error::ValidatorMustReturnBool { .. } => Some(Box::new("aiken::scripts")),
|
Error::ValidatorMustReturnBool { .. } => Some(Box::new("aiken::scripts")),
|
||||||
|
@ -270,6 +276,7 @@ impl Diagnostic for Error {
|
||||||
Error::Parse { error, .. } => error.kind.help(),
|
Error::Parse { error, .. } => error.kind.help(),
|
||||||
Error::Type { error, .. } => error.help(),
|
Error::Type { error, .. } => error.help(),
|
||||||
Error::StandardIo(_) => None,
|
Error::StandardIo(_) => None,
|
||||||
|
Error::MissingManifest { .. } => Some(Box::new("Try running `aiken new <REPOSITORY/PROJECT>` to initialise a project with an example manifest.")),
|
||||||
Error::TomlLoading { .. } => None,
|
Error::TomlLoading { .. } => None,
|
||||||
Error::Format { .. } => None,
|
Error::Format { .. } => None,
|
||||||
Error::ValidatorMustReturnBool { .. } => Some(Box::new("Try annotating the validator's return type with Bool")),
|
Error::ValidatorMustReturnBool { .. } => Some(Box::new("Try annotating the validator's return type with Bool")),
|
||||||
|
@ -315,6 +322,7 @@ impl Diagnostic for Error {
|
||||||
Error::ImportCycle { .. } => None,
|
Error::ImportCycle { .. } => None,
|
||||||
Error::List(_) => None,
|
Error::List(_) => None,
|
||||||
Error::Parse { error, .. } => error.labels(),
|
Error::Parse { error, .. } => error.labels(),
|
||||||
|
Error::MissingManifest { .. } => None,
|
||||||
Error::Type { error, .. } => error.labels(),
|
Error::Type { error, .. } => error.labels(),
|
||||||
Error::StandardIo(_) => None,
|
Error::StandardIo(_) => None,
|
||||||
Error::TomlLoading { location, .. } => {
|
Error::TomlLoading { location, .. } => {
|
||||||
|
@ -349,6 +357,7 @@ impl Diagnostic for Error {
|
||||||
Error::Parse { named, .. } => Some(named),
|
Error::Parse { named, .. } => Some(named),
|
||||||
Error::Type { named, .. } => Some(named),
|
Error::Type { named, .. } => Some(named),
|
||||||
Error::StandardIo(_) => None,
|
Error::StandardIo(_) => None,
|
||||||
|
Error::MissingManifest { .. } => None,
|
||||||
Error::TomlLoading { named, .. } => Some(named),
|
Error::TomlLoading { named, .. } => Some(named),
|
||||||
Error::Format { .. } => None,
|
Error::Format { .. } => None,
|
||||||
Error::ValidatorMustReturnBool { named, .. } => Some(named),
|
Error::ValidatorMustReturnBool { named, .. } => Some(named),
|
||||||
|
|
Loading…
Reference in New Issue