surrealdb_core/fnc/script/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::err::Error;

impl From<js::CaughtError<'_>> for Error {
	fn from(e: js::CaughtError) -> Error {
		match e {
			js::CaughtError::Exception(e) => Error::InvalidScript {
				message: format!(
					"An exception occurred: {}{}",
					e.message().unwrap_or_default(),
					match e.stack() {
						Some(stack) => format!("\n{stack}"),
						None => String::default(),
					}
				),
			},
			js::CaughtError::Error(js::Error::Unknown) => Error::InvalidScript {
				message: "An unknown error occurred".to_string(),
			},
			_ => Error::InvalidScript {
				message: e.to_string(),
			},
		}
	}
}