leo_errors/errors/
interpreter_halt.rs

1// Copyright (C) 2019-2025 Provable Inc.
2// This file is part of the Leo library.
3
4// The Leo library is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// The Leo library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
16
17use std::fmt;
18
19use leo_span::Span;
20
21/// Represents the interpreter halting, which should not be considered an
22/// actual runtime error.
23#[derive(Clone, Debug, Error)]
24pub struct InterpreterHalt {
25    /// Optional Span where the halt occurred.
26    span: Option<Span>,
27
28    /// User visible message.
29    message: String,
30}
31
32impl InterpreterHalt {
33    pub fn new(message: String) -> Self {
34        InterpreterHalt { span: None, message }
35    }
36
37    pub fn new_spanned(message: String, span: Span) -> Self {
38        InterpreterHalt { span: Some(span), message }
39    }
40
41    pub fn span(&self) -> Option<Span> {
42        self.span
43    }
44}
45
46impl fmt::Display for InterpreterHalt {
47    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48        write!(f, "{}", self.message)
49    }
50}