Finish re-working machine errors display.

This commit is contained in:
KtorZ 2024-08-16 17:04:16 +02:00
parent fe205e360f
commit 5943d94c6c
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
1 changed files with 58 additions and 23 deletions

View File

@ -5,49 +5,64 @@ use std::string::FromUtf8Error;
#[derive(Debug, Clone, PartialEq, thiserror::Error, miette::Diagnostic)] #[derive(Debug, Clone, PartialEq, thiserror::Error, miette::Diagnostic)]
pub enum Error { pub enum Error {
#[error("Over budget mem: {} & cpu: {}", .0.mem, .0.cpu)] #[error("execution went over budget\n{:>13} {}\n{:>13} {}", "Mem", .0.mem, "CPU", .0.cpu)]
OutOfExError(ExBudget), OutOfExError(ExBudget),
#[error("Invalid Stepkind: {0}")] #[error("invalid step kind: {0}")]
InvalidStepKind(u8), InvalidStepKind(u8),
#[error( #[error(
"Cannot evaluate an open term:\\n{}", "cannot evaluate an open term:\n{:>13} {}",
"Term",
indent(redacted(.0.to_pretty(), 10)), indent(redacted(.0.to_pretty(), 10)),
)] )]
OpenTermEvaluated(Term<NamedDeBruijn>), OpenTermEvaluated(Term<NamedDeBruijn>),
#[error("The validator crashed / exited prematurely")] #[error("the validator crashed / exited prematurely")]
EvaluationFailure, EvaluationFailure,
#[error( #[error(
"Attempted to instantiate a non-polymorphic term\n{:>13} {}", "attempted to instantiate a non-polymorphic term\n{:>13} {}",
"Term", "Term",
indent(redacted(format!("{:#?}", .0), 10)), indent(redacted(format!("{:#?}", .0), 10)),
)] )]
NonPolymorphicInstantiation(Value), NonPolymorphicInstantiation(Value),
#[error( #[error(
"Attempted to apply an argument to a non-function\n{:>13} {}\n{:>13} {}", "attempted to apply an argument to a non-function\n{:>13} {}\n{:>13} {}",
"Thing", "Thing",
indent(redacted(format!("{:#?}", .0), 5)), indent(redacted(format!("{:#?}", .0), 5)),
"Argument", "Argument",
indent(redacted(format!("{:#?}", .1), 5)), indent(redacted(format!("{:#?}", .1), 5)),
)] )]
NonFunctionalApplication(Value, Value), NonFunctionalApplication(Value, Value),
#[error("Attempted to case a non-const:\n\n{0:#?}")] #[error(
"attempted to case a non-const\n{:>13} {}",
"Value",
indent(redacted(format!("{:#?}", .0), 10)),
)]
NonConstrScrutinized(Value), NonConstrScrutinized(Value),
#[error("Cases: {0:#?}\n\n are missing branch for constr:\n\n{1:#?}")] #[error("Cases: {0:#?}\n\n are missing branch for constr:\n\n{1:#?}")]
MissingCaseBranch(Vec<Term<NamedDeBruijn>>, Value), MissingCaseBranch(Vec<Term<NamedDeBruijn>>, Value),
#[error("Type mismatch expected '{0}' got '{1}'")] #[error("type mismatch\n{:>13} {0}\n{:>13} {1}", "Expected", "Got")]
TypeMismatch(Type, Type), TypeMismatch(Type, Type),
#[error("Type mismatch expected '(list a)' got '{0}'")] #[error("type mismatch\n{:>13} (list a)\n{:>13} {0}", "Expected", "Got")]
ListTypeMismatch(Type), ListTypeMismatch(Type),
#[error("Type mismatch expected '(pair a b)' got '{0}'")] #[error("type mismatch\n{:>13}(pair a b)\n{:>13} {0}", "Expected", "Got")]
PairTypeMismatch(Type), PairTypeMismatch(Type),
#[error("Empty List:\n\n{0:#?}")] #[error(
"unexpected empty list\n{:>13} {}",
"List",
indent(redacted(format!("{:#?}", .0), 10)),
)]
EmptyList(Value), EmptyList(Value),
#[error( #[error(
"A builtin received a term argument when something else was expected:\n\n{0}\n\nYou probably forgot to wrap the builtin with a force." "a builtin received a term argument when something else was expected\n{:>13} {}\n{:>13} You probably forgot to wrap the builtin with a force.",
"Term",
indent(redacted(format!("{:#?}", .0), 10)),
"Hint"
)] )]
UnexpectedBuiltinTermArgument(Term<NamedDeBruijn>), UnexpectedBuiltinTermArgument(Term<NamedDeBruijn>),
#[error( #[error(
"A builtin expected a term argument, but something else was received:\n\n{0}\n\nYou probably have an extra force wrapped around a builtin" "a builtin expected a term argument, but something else was received:\n{:>13} {}\n{:>13} You probably have an extra force wrapped around a builtin",
"Term",
indent(redacted(format!("{:#?}", .0), 10)),
"Hint"
)] )]
BuiltinTermArgumentExpected(Term<NamedDeBruijn>), BuiltinTermArgumentExpected(Term<NamedDeBruijn>),
#[error( #[error(
@ -58,32 +73,52 @@ pub enum Error {
NotAConstant(Value), NotAConstant(Value),
#[error("The evaluation never reached a final state")] #[error("The evaluation never reached a final state")]
MachineNeverReachedDone, MachineNeverReachedDone,
#[error("integerToByteString encountered negative size {0}")] #[error("integerToByteString encountered negative size\n{:>13} {0}", "Size")]
IntegerToByteStringNegativeSize(BigInt), IntegerToByteStringNegativeSize(BigInt),
#[error("integerToByteString encountered negative input {0}")] #[error("integerToByteString encountered negative input\n{:>13} {0}", "Input")]
IntegerToByteStringNegativeInput(BigInt), IntegerToByteStringNegativeInput(BigInt),
#[error("integerToByteString encountered size {0} which is bigger than the max size of {1}")] #[error(
"bytes size beyond limit when converting from integer\n{:>13} {0}\n{:>13} {1}",
"Size",
"Maximum"
)]
IntegerToByteStringSizeTooBig(BigInt, i64), IntegerToByteStringSizeTooBig(BigInt, i64),
#[error("integerToByteString encountered size {0} which is not enough space for {1} bytes")] #[error(
"bytes size below limit when converting from integer\n{:>13} {0}\n{:>13} {1}",
"Size",
"Minimum"
)]
IntegerToByteStringSizeTooSmall(BigInt, usize), IntegerToByteStringSizeTooSmall(BigInt, usize),
#[error("Decoding utf8")] #[error("Decoding utf8")]
Utf8(#[from] FromUtf8Error), Utf8(#[from] FromUtf8Error),
#[error("Out of Bounds\n\nindex: {}\nbytestring: {}\npossible: 0 - {}", .0, hex::encode(.1), .1.len() - 1)] #[error(
"Out of Bounds\n{:>13} {}\nb{:>13} {}\n{:>13} 0 - {}",
"Index",
.0,
"ByteArray",
hex::encode(.1),
"Allowed",
.1.len() - 1
)]
ByteStringOutOfBounds(BigInt, Vec<u8>), ByteStringOutOfBounds(BigInt, Vec<u8>),
#[error("Attempt to consByteString something than isn't a byte between [0-255]: {0}")] #[error(
"attempt to consByteString something than isn't a byte between [0-255]\n{:>13} {0}",
"Found"
)]
ByteStringConsNotAByte(BigInt), ByteStringConsNotAByte(BigInt),
#[error("Divide By Zero\n\n{0} / {1}")] #[error("divide By Zero: {0} / {1}")]
DivideByZero(BigInt, BigInt), DivideByZero(BigInt, BigInt),
#[error("Ed25519S PublicKey should be 32 bytes but it was {0}")] #[error("Ed25519S PublicKey should be 32 bytes but it was {0}")]
UnexpectedEd25519PublicKeyLength(usize), UnexpectedEd25519PublicKeyLength(usize),
#[error("Ed25519S Signature should be 64 bytes but it was {0}")] #[error("Ed25519S Signature should be 64 bytes but it was {0}")]
UnexpectedEd25519SignatureLength(usize), UnexpectedEd25519SignatureLength(usize),
#[error( #[error(
"Failed to deserialise PlutusData using {0}:\n\n{}", "failed to deserialise PlutusData using {0}\n{:>13} {}",
redacted(format!("{:#?}", .1), 10), "Value",
indent(redacted(format!("{:#?}", .1), 10)),
)] )]
DeserialisationError(String, Value), DeserialisationError(String, Value),
#[error("Integer overflow")] #[error("integer overflow")]
OverflowError, OverflowError,
#[error("blst error {0:?}")] #[error("blst error {0:?}")]
Blst(blst::BLST_ERROR), Blst(blst::BLST_ERROR),