2021-12-21 11:37:35 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Fluence Labs Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2023-03-02 22:22:13 +03:00
|
|
|
use super::Stream;
|
|
|
|
use crate::execution_step::Generation;
|
2023-08-23 12:33:00 +03:00
|
|
|
use crate::execution_step::STREAM_MAX_SIZE;
|
2023-09-07 11:30:24 +03:00
|
|
|
use crate::CanonStreamMapError;
|
|
|
|
use crate::StreamMapError;
|
|
|
|
use crate::StreamMapKeyError;
|
2021-12-21 11:37:35 +03:00
|
|
|
use crate::ToErrorCode;
|
|
|
|
|
2022-12-26 15:45:14 +07:00
|
|
|
use air_interpreter_cid::CidCalculationError;
|
|
|
|
use air_interpreter_data::ValueRef;
|
2023-08-03 21:07:57 +03:00
|
|
|
use air_trace_handler::GenerationCompactificationError;
|
2023-04-05 11:50:15 +03:00
|
|
|
use air_trace_handler::IntConversionError;
|
2021-12-21 11:37:35 +03:00
|
|
|
use air_trace_handler::TraceHandlerError;
|
2023-03-02 22:22:13 +03:00
|
|
|
|
2021-12-21 11:37:35 +03:00
|
|
|
use strum::IntoEnumIterator;
|
|
|
|
use strum_macros::EnumDiscriminants;
|
|
|
|
use strum_macros::EnumIter;
|
|
|
|
use thiserror::Error as ThisError;
|
|
|
|
|
|
|
|
/// Uncatchable errors arisen during AIR script execution. Uncatchable here means that these errors
|
|
|
|
/// couldn't be handled by a xor instruction and their error_code couldn't be used in a match
|
|
|
|
/// instruction. They are similar to JVM runtime errors and some of them could be caught only
|
|
|
|
/// while execution of AIR script, others (FoldStateNotFound and MultipleVariablesFound) are
|
|
|
|
/// checked additionally on the validation step, and presence here for convenience.
|
|
|
|
#[derive(ThisError, EnumDiscriminants, Debug)]
|
|
|
|
#[strum_discriminants(derive(EnumIter))]
|
|
|
|
pub enum UncatchableError {
|
|
|
|
/// Errors bubbled from a trace handler.
|
2021-12-26 22:52:00 +03:00
|
|
|
#[error("on instruction '{instruction}' trace handler encountered an error: {trace_error}")]
|
|
|
|
TraceError {
|
|
|
|
trace_error: TraceHandlerError,
|
|
|
|
instruction: String,
|
|
|
|
},
|
2021-12-21 11:37:35 +03:00
|
|
|
|
2022-10-12 04:29:31 +03:00
|
|
|
/// These errors are related to internal bug in the interpreter when result trace is corrupted.
|
|
|
|
#[error(transparent)]
|
2023-08-03 21:07:57 +03:00
|
|
|
GenerationCompactificationError(#[from] GenerationCompactificationError),
|
2022-10-12 04:29:31 +03:00
|
|
|
|
2023-04-05 11:50:15 +03:00
|
|
|
/// Integer casts, e.g. usize(=u64) to u32, might trigger such errors.
|
|
|
|
#[error(transparent)]
|
|
|
|
IntConversionError(#[from] IntConversionError),
|
|
|
|
|
2021-12-21 11:37:35 +03:00
|
|
|
/// Fold state wasn't found for such iterator name.
|
|
|
|
#[error("fold state not found for this iterable '{0}'")]
|
|
|
|
FoldStateNotFound(String),
|
|
|
|
|
|
|
|
/// Errors encountered while shadowing non-scalar values.
|
|
|
|
#[error("variable with name '{0}' can't be shadowed, shadowing isn't supported for iterables")]
|
|
|
|
IterableShadowing(String),
|
|
|
|
|
|
|
|
/// Multiple fold states found for such iterator name.
|
|
|
|
#[error("multiple iterable values found for iterable name '{0}'")]
|
|
|
|
MultipleIterableValues(String),
|
|
|
|
|
2022-10-06 19:59:47 +03:00
|
|
|
/// Errors occurred when result from data doesn't match to a call instruction, f.e. a call
|
|
|
|
/// could be applied to a stream, but result doesn't contain generation in a source position.
|
|
|
|
#[error("call result value {0:?} doesn't match with corresponding instruction")]
|
2022-12-26 15:45:14 +07:00
|
|
|
CallResultNotCorrespondToInstr(ValueRef),
|
2022-10-06 19:59:47 +03:00
|
|
|
|
2022-04-20 11:43:46 +03:00
|
|
|
/// Variable shadowing is not allowed, usually it's thrown when a AIR tries to assign value
|
|
|
|
/// for a variable not in a fold block or in a global scope but not right after new.
|
|
|
|
#[error("trying to shadow variable '{0}', but shadowing is allowed only inside fold blocks")]
|
|
|
|
ShadowingIsNotAllowed(String),
|
|
|
|
|
|
|
|
/// This error occurred when new tries to pop up a variable at the end, but scalar state doesn't
|
|
|
|
/// contain an appropriate variable. It should be considered as an internal error and shouldn't
|
|
|
|
/// be caught by a xor instruction.
|
|
|
|
#[error("new end block tries to pop up a variable '{scalar_name}' that wasn't defined at depth {depth}")]
|
|
|
|
ScalarsStateCorrupted { scalar_name: String, depth: usize },
|
2022-08-26 00:43:43 +03:00
|
|
|
|
2022-12-26 15:45:14 +07:00
|
|
|
#[error("failed to calculate value's CID")]
|
|
|
|
CidError(#[from] CidCalculationError),
|
|
|
|
|
2023-01-09 13:22:57 +07:00
|
|
|
/// We consider now that every CID should present in the data;
|
|
|
|
/// and not having any CID is considered a non-catching error.
|
|
|
|
#[error("{0} for CID {1:?} not found")]
|
|
|
|
ValueForCidNotFound(&'static str, String),
|
2023-03-02 22:22:13 +03:00
|
|
|
|
|
|
|
/// Errors occurred while insertion of a value inside stream that doesn't have corresponding generation.
|
|
|
|
#[error(
|
|
|
|
"stream doesn't have generation with number {generation}, supplied to the interpreter data is corrupted,\n\
|
|
|
|
stream is {stream:?}"
|
|
|
|
)]
|
|
|
|
StreamDontHaveSuchGeneration { stream: Stream, generation: Generation },
|
2023-03-21 19:12:04 +07:00
|
|
|
|
|
|
|
#[error("failed to deserialize to CallServiceFailed: {0}")]
|
|
|
|
MalformedCallServiceFailed(serde_json::Error),
|
2023-08-23 12:33:00 +03:00
|
|
|
|
|
|
|
/// Stream size estimate goes over a hardcoded limit.
|
|
|
|
#[error("stream size goes over the allowed limit of {STREAM_MAX_SIZE}")]
|
|
|
|
StreamSizeLimitExceeded,
|
2023-09-07 11:30:24 +03:00
|
|
|
|
|
|
|
/// CanonStreamMapKey related errors.
|
|
|
|
#[error(transparent)]
|
|
|
|
StreamMapKeyError(#[from] StreamMapKeyError),
|
|
|
|
|
|
|
|
/// Stream map related errors.
|
|
|
|
#[error(transparent)]
|
|
|
|
StreamMapError(#[from] StreamMapError),
|
|
|
|
|
|
|
|
/// CanonStreamMap related errors.
|
|
|
|
#[error(transparent)]
|
|
|
|
CanonStreamMapError(#[from] CanonStreamMapError),
|
2023-10-13 23:19:02 +04:00
|
|
|
|
|
|
|
/// Argument hash or tetraplet mismatch in a call/canon merged from current_data with an evaluated value.
|
|
|
|
#[error("{param} doesn't match expected parameters: expected {expected_value}, got {stored_value} ")]
|
|
|
|
InstructionParametersMismatch {
|
|
|
|
param: &'static str,
|
|
|
|
expected_value: String,
|
|
|
|
stored_value: String,
|
|
|
|
},
|
|
|
|
|
|
|
|
#[error("failed to sign data: {0}")]
|
|
|
|
SigningError(#[from] fluence_keypair::error::SigningError),
|
2021-12-21 11:37:35 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl ToErrorCode for UncatchableError {
|
|
|
|
fn to_error_code(&self) -> i64 {
|
|
|
|
use crate::utils::UNCATCHABLE_ERRORS_START_ID;
|
|
|
|
crate::generate_to_error_code!(self, UncatchableError, UNCATCHABLE_ERRORS_START_ID)
|
|
|
|
}
|
|
|
|
}
|