Skip to main content

cumulus3d_core/
error.rs

1/*
2 * error.rs
3 *
4 * Copyright (c) 2026 ParkSangWoo
5 *
6 * Author(s):
7 *
8 *      ParkSangWoo <dev.parksangwoo@gmail.com>
9 *
10 *
11 * This file is part of cumulus3d.
12 *
13 * Licensed under the Apache License, Version 2.0 (the "License");
14 * you may not use this file except in compliance with the License.
15 * You may obtain a copy of the License at
16 *
17 *      http://www.apache.org/licenses/LICENSE-2.0
18 *
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
24 *
25 * SPDX-License-Identifier: Apache-2.0
26 */
27
28//! Error type.
29
30use std::path::PathBuf;
31
32/// Errors across core.
33#[derive(Debug, thiserror::Error)]
34pub enum Error {
35    #[error("입출력 오류: {0}")]
36    /// I/O failure.
37    Io(#[from] std::io::Error),
38    #[error("구문 오류 ({path}:{line}): {msg}")]
39    /// Text file syntax error (with location).
40    Parse {
41        /// File path.
42        path: PathBuf,
43        /// Line number (1-based).
44        line: usize,
45        /// Error description.
46        msg: String,
47    },
48    #[error("형식 오류: {0}")]
49    /// File format violation.
50    Format(String),
51    #[error("잘못된 인자: {0}")]
52    /// Invalid argument.
53    InvalidArgument(String),
54    #[error("찾을 수 없음: {0}")]
55    /// Target (id or name) not found.
56    NotFound(String),
57    #[error("이미 존재: {0}")]
58    /// Attempt to add a target that already exists.
59    AlreadyExists(String),
60    #[error("불변식 위반: {0}")]
61    /// Data structure invariant violation.
62    Invariant(String),
63    #[error("지원하지 않음: {0}")]
64    /// Unsupported feature or model.
65    Unsupported(String),
66}
67
68/// `Result` alias used across core.
69pub type Result<T> = std::result::Result<T, Error>;
70
71impl Error {
72    pub(crate) fn parse(path: impl Into<PathBuf>, line: usize, msg: impl Into<String>) -> Self {
73        Error::Parse { path: path.into(), line, msg: msg.into() }
74    }
75}