surrealdb/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
25
26
27
28
29
30
31
32
33
34
use crate::err::Error;

impl From<js::CaughtError<'_>> for Error {
	fn from(e: js::CaughtError) -> Error {
		match e {
			js::CaughtError::Exception(e) => {
				let line = e.line().unwrap_or(-1);
				Error::InvalidScript {
					message: format!(
						"An exception occurred{}: {}{}",
						match e.file() {
							Some(file) => format!(" at {file}:{line}"),
							None => String::default(),
						},
						match e.message() {
							Some(message) => message,
							None => String::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(),
			},
		}
	}
}