difftreelog
feat prettier error display for empty strings
in: master
1 file changed
crates/jrsonnet-evaluator/src/error.rsdiffbeforeafterboth35 out35 out36}36}3738const fn format_empty_str(str: &str) -> &str {39 if str.is_empty() {40 "\"\" (empty string)"41 } else {42 str43 }44}374538#[derive(Error, Debug, Clone, Trace)]46#[derive(Error, Debug, Clone, Trace)]39pub enum Error {47pub enum Error {60 #[error("string out of bounds: {0} is not within [0,{1})")]68 #[error("string out of bounds: {0} is not within [0,{1})")]61 StringBoundsError(usize, usize),69 StringBoundsError(usize, usize),627063 #[error("assert failed: {0}")]71 #[error("assert failed: {}", format_empty_str(.0))]64 AssertionFailed(IStr),72 AssertionFailed(IStr),657366 #[error("variable is not defined: {0}{}", format_found(.1, "variable"))]74 #[error("variable is not defined: {0}{}", format_found(.1, "variable"))]707871 #[error("type mismatch: expected {}, got {2} {0}", .1.iter().map(|e| format!("{}", e)).collect::<Vec<_>>().join(", "))]79 #[error("type mismatch: expected {}, got {2} {0}", .1.iter().map(|e| format!("{}", e)).collect::<Vec<_>>().join(", "))]72 TypeMismatch(&'static str, Vec<ValType>, ValType),80 TypeMismatch(&'static str, Vec<ValType>, ValType),73 #[error("no such field: {0}{}", format_found(.1, "field"))]81 #[error("no such field: {}{}", format_empty_str(.0), format_found(.1, "field"))]74 NoSuchField(IStr, Vec<IStr>),82 NoSuchField(IStr, Vec<IStr>),758376 #[error("only functions can be called, got {0}")]84 #[error("only functions can be called, got {0}")]899790 #[error("field name should be string, got {0}")]98 #[error("field name should be string, got {0}")]91 FieldMustBeStringGot(ValType),99 FieldMustBeStringGot(ValType),92 #[error("duplicate field name: {0}")]100 #[error("duplicate field name: {}", format_empty_str(.0))]93 DuplicateFieldName(IStr),101 DuplicateFieldName(IStr),9410295 #[error("attempted to index array with string {0}")]103 #[error("attempted to index array with string {}", format_empty_str(.0))]96 AttemptedIndexAnArrayWithString(IStr),104 AttemptedIndexAnArrayWithString(IStr),97 #[error("{0} index type should be {1}, got {2}")]105 #[error("{0} index type should be {1}, got {2}")]98 ValueIndexMustBeTypeGot(ValType, ValType, ValType),106 ValueIndexMustBeTypeGot(ValType, ValType, ValType),129 error: Box<jrsonnet_parser::ParseError>,137 error: Box<jrsonnet_parser::ParseError>,130 },138 },131139132 #[error("runtime error: {0}")]140 #[error("runtime error: {}", format_empty_str(.0))]133 RuntimeError(IStr),141 RuntimeError(IStr),134 #[error("stack overflow, try to reduce recursion, or set --max-stack to bigger value")]142 #[error("stack overflow, try to reduce recursion, or set --max-stack to bigger value")]135 StackOverflow,143 StackOverflow,152 #[error("stream manifest output cannot consist of raw strings")]160 #[error("stream manifest output cannot consist of raw strings")]153 StreamManifestCannotNestString,161 StreamManifestCannotNestString,154162155 #[error("{0}")]163 #[error("{}", format_empty_str(.0))]156 ImportCallbackError(String),164 ImportCallbackError(String),157 #[error("invalid unicode codepoint: {0}")]165 #[error("invalid unicode codepoint: {0}")]158 InvalidUnicodeCodepointGot(u32),166 InvalidUnicodeCodepointGot(u32),