Repository navigation
Expand file tree
/
Copy patherror.rs
More file actions
107 lines (79 loc) · 2.79 KB
/
Copy patherror.rs
File metadata and controls
107 lines (79 loc) · 2.79 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright 2025 Adobe. All rights reserved.
// This file is licensed to you under the Apache License,
// Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
// or the MIT license (http://opensource.org/licenses/MIT),
// at your option.
// Unless required by applicable law or agreed to in writing,
// this software is distributed on an "AS IS" BASIS, WITHOUT
// WARRANTIES OR REPRESENTATIONS OF ANY KIND, either express or
// implied. See the LICENSE-MIT and LICENSE-APACHE files for the
// specific language governing permissions and limitations under
// each license.
use std::sync::PoisonError;
use neon::prelude::*;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum Error {
#[error("Asset parsing failed: {0}")]
Asset(String),
#[error("Async signing failed {0}")]
AsyncSigning(String),
#[error(transparent)]
C2pa(#[from] c2pa::Error),
#[error(transparent)]
FileIO(#[from] std::io::Error),
#[error(transparent)]
Image(#[from] image::ImageError),
#[error(transparent)]
Json(#[from] serde_json::Error),
#[error("Lock acquisition failed: {0}")]
Lock(String),
#[error(transparent)]
NeonSerde(#[from] neon_serde4::errors::Error),
#[error("Trustmark model download failed")]
ModelDownload(String),
#[error(transparent)]
RemoteManifestFetch(#[from] reqwest::Error),
#[error("Settings handling failed: {0}")]
Settings(String),
#[error("Reading failed: {0}")]
Reading(String),
#[error("Signing failed: {0}")]
Signing(String),
#[error(transparent)]
TokioJoin(#[from] tokio::task::JoinError),
#[error(transparent)]
TokioTimeout(#[from] tokio::time::error::Elapsed),
#[error(transparent)]
TokioLock(#[from] tokio::sync::TryLockError),
#[error(transparent)]
Watermark(#[from] trustmark::Error),
#[error("Watermark configuration error: {0}")]
WatermarkConfiguration(String),
#[error(transparent)]
UTF8(#[from] std::str::Utf8Error),
}
impl<T> From<PoisonError<T>> for Error {
fn from(err: PoisonError<T>) -> Self {
Error::Lock(err.to_string())
}
}
// Implement Send for Error
unsafe impl Send for Error {}
unsafe impl Sync for Error {}
#[allow(dead_code)]
pub type Result<T> = std::result::Result<T, Error>;
pub fn as_js_error<'a>(cx: &mut TaskContext<'a>, err: Error) -> JsResult<'a, JsError> {
cx.execute_scoped(|mut cx| {
let js_err = cx.error(err.to_string())?;
let js_err_name = cx.string(format!("{err:?}"));
js_err.set(&mut cx, "name", js_err_name)?;
Ok(js_err)
})
}
pub fn as_js_error_fn<'a>(cx: &mut FunctionContext<'a>, err: Error) -> JsResult<'a, JsError> {
let js_err = cx.error(err.to_string())?;
let js_err_name = cx.string(format!("{err:?}"));
js_err.set(cx, "name", js_err_name)?;
Ok(js_err)
}