fix: remove unwrap which is causing panics closes #1073
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use miette::IntoDiagnostic;
|
||||
use miette::{Context, IntoDiagnostic};
|
||||
use std::{path::PathBuf, println};
|
||||
use uplc::ast::{DeBruijn, Name, NamedDeBruijn, Program};
|
||||
|
||||
@@ -39,16 +39,14 @@ pub fn exec(
|
||||
std::fs::read(&input).into_diagnostic()?
|
||||
};
|
||||
|
||||
let pretty_uplc = match from {
|
||||
let program: Program<Name> = match from {
|
||||
Format::Name => {
|
||||
let program: Program<Name> = if cbor {
|
||||
if cbor {
|
||||
let mut flat_buffer = Vec::new();
|
||||
Program::from_cbor(&bytes, &mut flat_buffer).into_diagnostic()?
|
||||
} else {
|
||||
Program::from_flat(&bytes).into_diagnostic()?
|
||||
};
|
||||
|
||||
program.to_pretty()
|
||||
}
|
||||
}
|
||||
Format::NamedDebruijn => {
|
||||
let program: Program<NamedDeBruijn> = if cbor {
|
||||
@@ -58,9 +56,10 @@ pub fn exec(
|
||||
Program::from_flat(&bytes).into_diagnostic()?
|
||||
};
|
||||
|
||||
let program: Program<Name> = program.try_into().unwrap();
|
||||
|
||||
program.to_pretty()
|
||||
program
|
||||
.try_into()
|
||||
.into_diagnostic()
|
||||
.context("failed to decode, maybe try `--cbor`")?
|
||||
}
|
||||
Format::Debruijn => {
|
||||
let program: Program<DeBruijn> = if cbor {
|
||||
@@ -70,13 +69,14 @@ pub fn exec(
|
||||
Program::from_flat(&bytes).into_diagnostic()?
|
||||
};
|
||||
|
||||
let program: Program<Name> = program.try_into().unwrap();
|
||||
|
||||
program.to_pretty()
|
||||
program
|
||||
.try_into()
|
||||
.into_diagnostic()
|
||||
.context("failed to decode, maybe try `--cbor`")?
|
||||
}
|
||||
};
|
||||
|
||||
println!("{pretty_uplc}");
|
||||
println!("{}", program.to_pretty());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -461,7 +461,12 @@ impl Converter {
|
||||
|
||||
fn get_unique(&mut self, index: &DeBruijn) -> Result<Unique, Error> {
|
||||
for scope in self.levels.iter().rev() {
|
||||
let index = Level(self.current_level.0 - index.inner());
|
||||
let index = Level(
|
||||
self.current_level
|
||||
.0
|
||||
.checked_sub(index.inner())
|
||||
.ok_or(Error::FreeIndex(*index))?,
|
||||
);
|
||||
|
||||
if let Some(unique) = scope.get_right(&index) {
|
||||
return Ok(*unique);
|
||||
|
||||
Reference in New Issue
Block a user