cairo_lang_sierra/extensions/
error.rs1use itertools::Itertools;
2use num_bigint::BigInt;
3use smol_str::SmolStr;
4use thiserror::Error;
5
6use crate::ids::{ConcreteTypeId, FunctionId, GenericLibfuncId, GenericTypeId};
7use crate::program::GenericArg;
8
9#[derive(Error, Debug, Eq, PartialEq)]
11pub enum SpecializationError {
12 #[error("Could not find the requested extension: {0}")]
13 UnsupportedId(SmolStr),
14 #[error("Expected a different number of generic arguments")]
15 WrongNumberOfGenericArgs,
16 #[error("Provided generic argument is unsupported")]
17 UnsupportedGenericArg,
18 #[error("index is out of a relevant range")]
19 IndexOutOfRange {
20 index: BigInt,
21 range_size: usize,
23 },
24 #[error("Could not find the requested function")]
25 MissingFunction(FunctionId),
26 #[error("Generic type was not specialized with such arguments")]
27 TypeWasNotDeclared(GenericTypeId, Vec<GenericArg>),
28 #[error("Missing type info for the requested type")]
29 MissingTypeInfo(ConcreteTypeId),
30}
31
32#[derive(Error, Debug, Eq, PartialEq)]
34pub enum ExtensionError {
35 #[error("Could not specialize type")]
36 TypeSpecialization { type_id: GenericTypeId, error: SpecializationError },
37 #[error(
38 "Could not specialize libfunc `{libfunc_id}` with generic_args: [{}]. Error: {error}.",
39 generic_args.iter().map(|arg| arg.to_string()).join(", ")
40 )]
41 LibfuncSpecialization {
42 libfunc_id: GenericLibfuncId,
43 generic_args: Vec<GenericArg>,
44 error: SpecializationError,
45 },
46 #[error("The requested functionality is not implemented yet")]
47 NotImplemented,
48}