Improve error reporting for the blueprint generation.

Actually link schema error to source code with a span and a label. This is easily done and provides some extra context.
This commit is contained in:
KtorZ
2023-01-29 12:58:19 +01:00
parent b3fc2d51cf
commit 90ee86d14e
3 changed files with 173 additions and 86 deletions

View File

@@ -4,6 +4,7 @@ use super::{
};
use crate::module::{CheckedModule, CheckedModules};
use aiken_lang::{ast::TypedFunction, uplc::CodeGenerator};
use miette::NamedSource;
use pallas::ledger::primitives::babbage as cardano;
use pallas_traverse::ComputeHash;
use serde::{
@@ -91,12 +92,27 @@ impl Validator {
purpose,
datum: datum
.map(|datum| {
Annotated::from_type(modules.into(), &datum.tipo, &HashMap::new())
.map_err(Error::Schema)
Annotated::from_type(modules.into(), &datum.tipo, &HashMap::new()).map_err(
|error| Error::Schema {
error,
location: datum.location,
source_code: NamedSource::new(
validator.input_path.display().to_string(),
validator.code.clone(),
),
},
)
})
.transpose()?,
redeemer: Annotated::from_type(modules.into(), &redeemer.tipo, &HashMap::new())
.map_err(Error::Schema)?,
.map_err(|error| Error::Schema {
error,
location: redeemer.location,
source_code: NamedSource::new(
validator.input_path.display().to_string(),
validator.code.clone(),
),
})?,
program: generator
.generate(&def.body, &def.arguments, true)
.try_into()