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:
Micah Kendall 2022-11-27 08:52:20 +11:00 committed by KtorZ
parent a3591cc7dc
commit bd816615d7
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
3 changed files with 14 additions and 8 deletions

View File

@ -1,9 +1,7 @@
use std::collections::BTreeMap;
use std::{env, path::PathBuf, process};
use aiken_project::{pretty, script::EvalInfo, telemetry, Project};
use miette::IntoDiagnostic;
use owo_colors::OwoColorize;
use std::{collections::BTreeMap, env, path::PathBuf, process};
use uplc::machine::cost_model::ExBudget;
pub mod cmd;

View File

@ -1,10 +1,8 @@
use std::{fmt::Display, fs, path::PathBuf};
use crate::error::Error;
use aiken_lang::ast::Span;
use miette::NamedSource;
use serde::{de::Visitor, Deserialize, Serialize};
use crate::error::Error;
use std::{fmt::Display, fs, path::PathBuf};
#[derive(Deserialize)]
pub struct Config {
@ -112,7 +110,8 @@ impl Display for Platform {
impl Config {
pub fn load(dir: PathBuf) -> Result<Config, Error> {
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 {
path: config_path.clone(),

View File

@ -52,6 +52,9 @@ pub enum Error {
help: String,
},
#[error("Missing 'aiken.toml' manifest in {path}")]
MissingManifest { path: PathBuf },
#[error("Cyclical module imports")]
ImportCycle { modules: Vec<String> },
@ -175,6 +178,7 @@ impl Error {
Error::FileIo { .. } => None,
Error::Format { .. } => None,
Error::StandardIo(_) => None,
Error::MissingManifest { path } => Some(path.to_path_buf()),
Error::TomlLoading { path, .. } => Some(path.to_path_buf()),
Error::ImportCycle { .. } => None,
Error::List(_) => None,
@ -195,6 +199,7 @@ impl Error {
Error::FileIo { .. } => None,
Error::Format { .. } => None,
Error::StandardIo(_) => None,
Error::MissingManifest { .. } => None,
Error::TomlLoading { src, .. } => Some(src.to_string()),
Error::ImportCycle { .. } => None,
Error::List(_) => None,
@ -243,6 +248,7 @@ impl Diagnostic for Error {
Error::Parse { .. } => Some(Box::new("aiken::parser")),
Error::Type { .. } => Some(Box::new("aiken::check")),
Error::StandardIo(_) => None,
Error::MissingManifest { .. } => None,
Error::TomlLoading { .. } => Some(Box::new("aiken::loading::toml")),
Error::Format { .. } => None,
Error::ValidatorMustReturnBool { .. } => Some(Box::new("aiken::scripts")),
@ -270,6 +276,7 @@ impl Diagnostic for Error {
Error::Parse { error, .. } => error.kind.help(),
Error::Type { error, .. } => error.help(),
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::Format { .. } => None,
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::List(_) => None,
Error::Parse { error, .. } => error.labels(),
Error::MissingManifest { .. } => None,
Error::Type { error, .. } => error.labels(),
Error::StandardIo(_) => None,
Error::TomlLoading { location, .. } => {
@ -349,6 +357,7 @@ impl Diagnostic for Error {
Error::Parse { named, .. } => Some(named),
Error::Type { named, .. } => Some(named),
Error::StandardIo(_) => None,
Error::MissingManifest { .. } => None,
Error::TomlLoading { named, .. } => Some(named),
Error::Format { .. } => None,
Error::ValidatorMustReturnBool { named, .. } => Some(named),