Show slightly better schema mismatch errors
Display terms as CBOR diagnostic when they are Plutus data.
This commit is contained in:
parent
176cb45524
commit
c18deecdc8
|
@ -129,6 +129,7 @@ dependencies = [
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"itertools",
|
"itertools",
|
||||||
"miette",
|
"miette",
|
||||||
|
"minicbor",
|
||||||
"owo-colors",
|
"owo-colors",
|
||||||
"pallas",
|
"pallas",
|
||||||
"pallas-traverse",
|
"pallas-traverse",
|
||||||
|
|
|
@ -20,6 +20,7 @@ ignore = "0.4.20"
|
||||||
indexmap = "1.9.2"
|
indexmap = "1.9.2"
|
||||||
itertools = "0.10.5"
|
itertools = "0.10.5"
|
||||||
miette = { version = "5.5.0", features = ["fancy"] }
|
miette = { version = "5.5.0", features = ["fancy"] }
|
||||||
|
minicbor = "0.19.1"
|
||||||
owo-colors = { version = "3.5.0", features = ["supports-colors"] }
|
owo-colors = { version = "3.5.0", features = ["supports-colors"] }
|
||||||
pallas = "0.18.0"
|
pallas = "0.18.0"
|
||||||
pallas-traverse = "0.18.0"
|
pallas-traverse = "0.18.0"
|
||||||
|
|
|
@ -4,6 +4,7 @@ use super::{
|
||||||
};
|
};
|
||||||
use aiken_lang::ast::Span;
|
use aiken_lang::ast::Span;
|
||||||
use miette::{Diagnostic, NamedSource};
|
use miette::{Diagnostic, NamedSource};
|
||||||
|
use minicbor as cbor;
|
||||||
use owo_colors::{OwoColorize, Stream::Stdout};
|
use owo_colors::{OwoColorize, Stream::Stdout};
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use uplc::ast::Constant;
|
use uplc::ast::Constant;
|
||||||
|
@ -66,9 +67,18 @@ pub enum Error {
|
||||||
#[error("I caught a parameter application that seems off.")]
|
#[error("I caught a parameter application that seems off.")]
|
||||||
#[diagnostic(code("aiken::blueprint::apply::mismatch"))]
|
#[diagnostic(code("aiken::blueprint::apply::mismatch"))]
|
||||||
#[diagnostic(help(
|
#[diagnostic(help(
|
||||||
"When applying parameters to a validator, I control that the shape of the parameter you give me matches what is specified in the blueprint. Unfortunately, schemas didn't match in this case.\n\nI am expecting something of the shape:\n\n{}Which I couldn't match against the following term:\n\n{}\n\nNote that this may only represent part of a bigger whole.",
|
"When applying parameters to a validator, I control that the shape of the parameter you give me matches what is specified in the blueprint. Unfortunately, schemas didn't match in this case.\n\nI am expecting something of the shape:\n\n{expected}Which I couldn't match against the following term:\n\n{term}\n\nNote that this may only represent part of a bigger whole.",
|
||||||
serde_json::to_string_pretty(&schema).unwrap().if_supports_color(Stdout, |s| s.green()),
|
expected = serde_json::to_string_pretty(&schema).unwrap().if_supports_color(Stdout, |s| s.green()),
|
||||||
term.to_pretty().if_supports_color(Stdout, |s| s.red()),
|
term = {
|
||||||
|
let mut buf = vec![];
|
||||||
|
match term {
|
||||||
|
Constant::Data(data) => {
|
||||||
|
cbor::encode(data, &mut buf).unwrap();
|
||||||
|
cbor::display(&buf).to_string()
|
||||||
|
},
|
||||||
|
_ => term.to_pretty()
|
||||||
|
}
|
||||||
|
}.if_supports_color(Stdout, |s| s.red()),
|
||||||
))]
|
))]
|
||||||
SchemaMismatch { schema: Schema, term: Constant },
|
SchemaMismatch { schema: Schema, term: Constant },
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue