From 3ea3f30e21926d4ec57f5792ae9892628e8ec6d7 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Wed, 14 Jun 2023 18:23:09 +0000 Subject: [PATCH] feat: enable friendly-errors by default --- --- a/crates/jrsonnet-evaluator/Cargo.toml +++ b/crates/jrsonnet-evaluator/Cargo.toml @@ -8,14 +8,11 @@ edition = "2021" [features] -default = ["explaining-traces", "friendly-errors"] +default = ["explaining-traces"] # Rustc-like trace visualization explaining-traces = ["annotate-snippets"] # Allows library authors to throw custom errors anyhow-error = ["anyhow"] -# Provides helpful explaintations to errors, at cost of adding -# more dependencies and slowing down error path -friendly-errors = ["strsim"] # Adds ability to build import closure in async async-import = ["async-trait"] @@ -45,12 +42,12 @@ rustc-hash = "1.1" thiserror = "1.0" +# Friendly errors +strsim = { version = "0.10.0" } serde = "1.0" anyhow = { version = "1.0", optional = true } -# Friendly errors -strsim = { version = "0.10.0", optional = true } # Serialized stdlib bincode = { version = "1.3", optional = true } # Explaining traces --- a/crates/jrsonnet-evaluator/src/ctx.rs +++ b/crates/jrsonnet-evaluator/src/ctx.rs @@ -51,17 +51,6 @@ self.0.sup.as_ref() } - #[cfg(not(feature = "friendly-errors"))] - pub fn binding(&self, name: IStr) -> Result> { - Ok(self - .0 - .bindings - .get(&name) - .cloned() - .ok_or(VariableIsNotDefined(name, vec![]))?) - } - - #[cfg(feature = "friendly-errors")] pub fn binding(&self, name: IStr) -> Result> { use std::cmp::Ordering; --- a/crates/jrsonnet-evaluator/src/error.rs +++ b/crates/jrsonnet-evaluator/src/error.rs @@ -1,6 +1,7 @@ use std::{ + cmp::Ordering, fmt::{Debug, Display}, - path::PathBuf, cmp::Ordering, + path::PathBuf, }; use jrsonnet_gcmodule::Trace; @@ -79,9 +80,8 @@ if conf < 0.8 { continue; } - if field.as_str() == key.as_str() { - panic!("looks like string pooling failure, please write any info regarding this crash to https://github.com/CertainLach/jrsonnet/issues/113, thanks!"); - } + assert!(field.as_str() != key.as_str(), "looks like string pooling failure, please write any info regarding this crash to https://github.com/CertainLach/jrsonnet/issues/113, thanks!"); + heap.push((conf, field)); } heap.sort_by(|a, b| b.0.partial_cmp(&a.0).unwrap_or(Ordering::Equal)); --- a/crates/jrsonnet-evaluator/src/evaluate/mod.rs +++ b/crates/jrsonnet-evaluator/src/evaluate/mod.rs @@ -1,4 +1,4 @@ -use std::{cmp::Ordering, rc::Rc}; +use std::rc::Rc; use jrsonnet_gcmodule::{Cc, Trace}; use jrsonnet_interner::IStr; @@ -12,7 +12,7 @@ use crate::{ arr::ArrValue, destructure::evaluate_dest, - error::{ErrorKind::*, suggest_object_fields}, + error::{suggest_object_fields, ErrorKind::*}, evaluate::operator::{evaluate_add_op, evaluate_binary_op_special, evaluate_unary_op}, function::{CallLocation, FuncDesc, FuncVal}, throw, -- gitstuff