Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add loader and refactor errors #917

Merged
merged 52 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
b295446
Starting to refactor
casey Jul 24, 2021
c47ecaf
Lifetime issues
casey Jul 24, 2021
69f857f
Fixed lifetimes
casey Jul 24, 2021
aabb43e
Remove i32 → JustError conversion
casey Jul 24, 2021
02f078f
Get rid of eprint
casey Jul 24, 2021
1debdab
JustError → Error
casey Jul 24, 2021
cbf8c4d
IoError → Io
casey Jul 24, 2021
46bdbf8
Start getting rid of Error::Code
casey Jul 24, 2021
0511899
Sort runtime errors
casey Jul 24, 2021
900fa3a
Add NoChoosableRecipes error
casey Jul 24, 2021
ee3e54a
Working on show error
casey Jul 24, 2021
797e209
Going to fix error newlines
casey Jul 24, 2021
0e8b700
Move printing into Error
casey Jul 24, 2021
c8b36cb
Paint `error:` separately
casey Jul 24, 2021
4805786
Move newline printing after message into Error
casey Jul 24, 2021
05981ce
Remove message formatting out of Display implementation
casey Jul 24, 2021
97b365b
cleanup
casey Jul 24, 2021
a0c6853
Return UnknownRecipes error from show
casey Jul 24, 2021
4c7e898
More code removal
casey Jul 24, 2021
f67cea1
Refactoring edit command errors
casey Jul 24, 2021
2263b3e
Working on editor status test
casey Jul 25, 2021
075ae42
Fix status test
casey Jul 25, 2021
36bf3a2
Got rid of Error::Code
casey Jul 25, 2021
533eab6
Git rid of random process::exit
casey Jul 25, 2021
aacbb64
Remove extra write_context function
casey Jul 25, 2021
dd4cbab
About to move everything into Error
casey Jul 25, 2021
fff1301
Got rid of runtime error
casey Jul 25, 2021
26e7fd3
Use struct variants
casey Jul 25, 2021
7c3cd25
CompilationError → CompileError
casey Jul 25, 2021
6993adc
CompilationResult → CompileResult
casey Jul 25, 2021
d707226
Tweak
casey Jul 25, 2021
6d7b135
Format
casey Jul 25, 2021
04f5071
Sort Error variants
casey Jul 25, 2021
37b2b72
Sort compileerror variants
casey Jul 25, 2021
1983200
Sort other error enums
casey Jul 25, 2021
fd7c2b4
Remove todos
casey Jul 25, 2021
93069b7
Placate clippy
casey Jul 25, 2021
8d889f8
Fix fmt issue
casey Jul 25, 2021
60d440f
Fix long lines
casey Jul 25, 2021
7a14d65
Fix invoke error test on windows
casey Jul 25, 2021
14fb6b8
(sic)
casey Jul 25, 2021
b367f89
Improve tests
casey Jul 25, 2021
b3e4cdb
Placate clippy
casey Jul 25, 2021
5dd875d
Convert test construction to method style
casey Jul 26, 2021
d79a0a6
Add Test::stderr_regex
casey Jul 26, 2021
b1fd273
Fix tests
casey Jul 26, 2021
f92f912
Placate clippy
casey Jul 26, 2021
3e7c53b
Fix tests harder
casey Jul 26, 2021
cdd933e
More fixing
casey Jul 26, 2021
2e0f38f
Align cargo.toml
casey Jul 26, 2021
cfefced
Make Config::dump return ()
casey Jul 26, 2021
fc9dee2
rename loader arena
casey Jul 26, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ snafu = "0.6.0"
strum_macros = "0.21.1"
target = "1.0.0"
tempfile = "3.0.0"
typed-arena = "2.0.1"
unicode-width = "0.1.0"

[dependencies.ctrlc]
Expand All @@ -44,8 +45,10 @@ version = "0.21.0"
features = ["derive"]

[dev-dependencies]
cradle = "0.0.13"
executable-path = "1.0.0"
pretty_assertions = "0.7.0"
regex = "1.5.4"
temptree = "0.1.0"
which = "4.0.0"
yaml-rust = "0.4.5"
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ build:
fmt:
cargo +nightly fmt --all

watch +COMMAND='test':
watch +COMMAND='ltest':
cargo watch --clear --exec "{{COMMAND}}"

man:
Expand All @@ -61,7 +61,7 @@ version := `sed -En 's/version[[:space:]]*=[[:space:]]*"([^"]+)"/\1/p' Cargo.tom
changes:
git log --pretty=format:%s >> CHANGELOG.md

check: clippy test forbid
check: clippy fmt test forbid
git diff --no-ext-diff --quiet --exit-code
grep '^\[{{ version }}\]' CHANGELOG.md
cargo +nightly generate-lockfile -Z minimal-versions
Expand Down
16 changes: 8 additions & 8 deletions src/analyzer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::common::*;

use CompilationErrorKind::*;
use CompileErrorKind::*;

#[derive(Default)]
pub(crate) struct Analyzer<'src> {
Expand All @@ -11,11 +11,11 @@ pub(crate) struct Analyzer<'src> {
}

impl<'src> Analyzer<'src> {
pub(crate) fn analyze(ast: Ast<'src>) -> CompilationResult<'src, Justfile> {
pub(crate) fn analyze(ast: Ast<'src>) -> CompileResult<'src, Justfile> {
Analyzer::default().justfile(ast)
}

pub(crate) fn justfile(mut self, ast: Ast<'src>) -> CompilationResult<'src, Justfile<'src>> {
pub(crate) fn justfile(mut self, ast: Ast<'src>) -> CompileResult<'src, Justfile<'src>> {
for item in ast.items {
match item {
Item::Alias(alias) => {
Expand Down Expand Up @@ -88,7 +88,7 @@ impl<'src> Analyzer<'src> {
})
}

fn analyze_recipe(&self, recipe: &UnresolvedRecipe<'src>) -> CompilationResult<'src, ()> {
fn analyze_recipe(&self, recipe: &UnresolvedRecipe<'src>) -> CompileResult<'src, ()> {
if let Some(original) = self.recipes.get(recipe.name.lexeme()) {
return Err(recipe.name.token().error(DuplicateRecipe {
recipe: original.name(),
Expand Down Expand Up @@ -140,7 +140,7 @@ impl<'src> Analyzer<'src> {
Ok(())
}

fn analyze_assignment(&self, assignment: &Assignment<'src>) -> CompilationResult<'src, ()> {
fn analyze_assignment(&self, assignment: &Assignment<'src>) -> CompileResult<'src, ()> {
if self.assignments.contains_key(assignment.name.lexeme()) {
return Err(assignment.name.token().error(DuplicateVariable {
variable: assignment.name.lexeme(),
Expand All @@ -149,7 +149,7 @@ impl<'src> Analyzer<'src> {
Ok(())
}

fn analyze_alias(&self, alias: &Alias<'src, Name<'src>>) -> CompilationResult<'src, ()> {
fn analyze_alias(&self, alias: &Alias<'src, Name<'src>>) -> CompileResult<'src, ()> {
let name = alias.name.lexeme();

if let Some(original) = self.aliases.get(name) {
Expand All @@ -162,7 +162,7 @@ impl<'src> Analyzer<'src> {
Ok(())
}

fn analyze_set(&self, set: &Set<'src>) -> CompilationResult<'src, ()> {
fn analyze_set(&self, set: &Set<'src>) -> CompileResult<'src, ()> {
if let Some(original) = self.sets.get(set.name.lexeme()) {
return Err(set.name.error(DuplicateSet {
setting: original.name.lexeme(),
Expand All @@ -176,7 +176,7 @@ impl<'src> Analyzer<'src> {
fn resolve_alias(
recipes: &Table<'src, Rc<Recipe<'src>>>,
alias: Alias<'src, Name<'src>>,
) -> CompilationResult<'src, Alias<'src>> {
) -> CompileResult<'src, Alias<'src>> {
let token = alias.name.token();
// Make sure the alias doesn't conflict with any recipe
if let Some(recipe) = recipes.get(alias.name.lexeme()) {
Expand Down
10 changes: 5 additions & 5 deletions src/assignment_resolver.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::common::*;

use CompilationErrorKind::*;
use CompileErrorKind::*;

pub(crate) struct AssignmentResolver<'src: 'run, 'run> {
assignments: &'run Table<'src, Assignment<'src>>,
Expand All @@ -11,7 +11,7 @@ pub(crate) struct AssignmentResolver<'src: 'run, 'run> {
impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> {
pub(crate) fn resolve_assignments(
assignments: &Table<'src, Assignment<'src>>,
) -> CompilationResult<'src, ()> {
) -> CompileResult<'src, ()> {
let mut resolver = AssignmentResolver {
stack: Vec::new(),
evaluated: BTreeSet::new(),
Expand All @@ -25,7 +25,7 @@ impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> {
Ok(())
}

fn resolve_assignment(&mut self, name: &'src str) -> CompilationResult<'src, ()> {
fn resolve_assignment(&mut self, name: &'src str) -> CompileResult<'src, ()> {
if self.evaluated.contains(name) {
return Ok(());
}
Expand All @@ -45,7 +45,7 @@ impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> {
length: 0,
kind: TokenKind::Unspecified,
};
return Err(CompilationError {
return Err(CompileError {
kind: Internal { message },
token,
});
Expand All @@ -56,7 +56,7 @@ impl<'src: 'run, 'run> AssignmentResolver<'src, 'run> {
Ok(())
}

fn resolve_expression(&mut self, expression: &Expression<'src>) -> CompilationResult<'src, ()> {
fn resolve_expression(&mut self, expression: &Expression<'src>) -> CompileResult<'src, ()> {
match expression {
Expression::Variable { name } => {
let variable = name.lexeme();
Expand Down
5 changes: 2 additions & 3 deletions src/ast.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::common::*;

/// The top-level type produced by the parser.Not all successful parses result
/// The top-level type produced by the parser. Not all successful parses result
/// in valid justfiles, so additional consistency checks and name resolution
/// are performed by the `Analyzer`, which produces a `Justfile` from an
/// `Ast`.
/// are performed by the `Analyzer`, which produces a `Justfile` from an `Ast`.
#[derive(Debug, Clone)]
pub(crate) struct Ast<'src> {
/// Items in the justfile
Expand Down
26 changes: 13 additions & 13 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub(crate) use std::{
mem,
ops::{Index, Range, RangeInclusive},
path::{Path, PathBuf},
process::{self, Command, Stdio},
process::{self, Command, ExitStatus, Stdio},
rc::Rc,
str::{self, Chars},
sync::{Mutex, MutexGuard},
Expand All @@ -27,6 +27,7 @@ pub(crate) use libc::EXIT_FAILURE;
pub(crate) use log::{info, warn};
pub(crate) use snafu::{ResultExt, Snafu};
pub(crate) use strum::{Display, EnumString, IntoStaticStr};
pub(crate) use typed_arena::Arena;
pub(crate) use unicode_width::{UnicodeWidthChar, UnicodeWidthStr};

// modules
Expand All @@ -37,24 +38,23 @@ pub(crate) use crate::{load_dotenv::load_dotenv, output::output, unindent::unind

// traits
pub(crate) use crate::{
command_ext::CommandExt, error::Error, error_result_ext::ErrorResultExt, keyed::Keyed,
ordinal::Ordinal, platform_interface::PlatformInterface, range_ext::RangeExt,
command_ext::CommandExt, keyed::Keyed, ordinal::Ordinal, platform_interface::PlatformInterface,
range_ext::RangeExt,
};

// structs and enums
pub(crate) use crate::{
alias::Alias, analyzer::Analyzer, assignment::Assignment,
assignment_resolver::AssignmentResolver, ast::Ast, binding::Binding, color::Color,
compilation_error::CompilationError, compilation_error_kind::CompilationErrorKind,
config::Config, config_error::ConfigError, count::Count, delimiter::Delimiter,
dependency::Dependency, enclosure::Enclosure, evaluator::Evaluator, expression::Expression,
compile_error::CompileError, compile_error_kind::CompileErrorKind, config::Config,
config_error::ConfigError, count::Count, delimiter::Delimiter, dependency::Dependency,
enclosure::Enclosure, error::Error, evaluator::Evaluator, expression::Expression,
fragment::Fragment, function::Function, function_context::FunctionContext,
interrupt_guard::InterruptGuard, interrupt_handler::InterruptHandler, item::Item,
justfile::Justfile, keyword::Keyword, lexer::Lexer, line::Line, list::List,
load_error::LoadError, name::Name, output_error::OutputError, parameter::Parameter,
parameter_kind::ParameterKind, parser::Parser, platform::Platform, position::Position,
positional::Positional, recipe::Recipe, recipe_context::RecipeContext,
recipe_resolver::RecipeResolver, runtime_error::RuntimeError, scope::Scope, search::Search,
justfile::Justfile, keyword::Keyword, lexer::Lexer, line::Line, list::List, loader::Loader,
name::Name, output_error::OutputError, parameter::Parameter, parameter_kind::ParameterKind,
parser::Parser, platform::Platform, position::Position, positional::Positional, recipe::Recipe,
recipe_context::RecipeContext, recipe_resolver::RecipeResolver, scope::Scope, search::Search,
search_config::SearchConfig, search_error::SearchError, set::Set, setting::Setting,
settings::Settings, shebang::Shebang, show_whitespace::ShowWhitespace, string_kind::StringKind,
string_literal::StringLiteral, subcommand::Subcommand, suggestion::Suggestion, table::Table,
Expand All @@ -64,9 +64,9 @@ pub(crate) use crate::{
};

// type aliases
pub(crate) type CompilationResult<'a, T> = Result<T, CompilationError<'a>>;
pub(crate) type CompileResult<'a, T> = Result<T, CompileError<'a>>;
pub(crate) type ConfigResult<T> = Result<T, ConfigError>;
pub(crate) type RunResult<'a, T> = Result<T, RuntimeError<'a>>;
pub(crate) type RunResult<'a, T> = Result<T, Error<'a>>;
pub(crate) type SearchResult<T> = Result<T, SearchError>;

// modules used in tests
Expand Down
Loading