lewp_css/stylesheet_error.rs
1// This file is part of css. It is subject to the license terms in the COPYRIGHT file found in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT. No part of predicator, including this file, may be copied, modified, propagated, or distributed except according to the terms contained in the COPYRIGHT file.
2// Copyright © 2017 The developers of css. See the COPYRIGHT file in the top-level directory of this distribution and at https://raw.githubusercontent.com/lemonrock/css/master/COPYRIGHT.
3
4use {
5 cssparser::SourceLocation,
6 std::path::{Path, PathBuf},
7};
8
9quick_error! {
10 /// Represents all the things that can go wrong when loading and saving stylesheets.
11 #[derive(Debug)]
12 pub enum StylesheetError
13 {
14 /// An input-output error occurred, typically when loading or creating a file.
15 Io(path: PathBuf, cause: ::std::io::Error)
16 {
17 cause(cause)
18 description(cause.description())
19 display("I/O error with {:?} was '{}'", path, cause)
20 context(path: &'a Path, cause: ::std::io::Error) -> (path.to_path_buf(), cause)
21 }
22
23 /// An error occurred during a std::fmt::write (only happens when saving).
24 Format(path: PathBuf, cause: ::std::fmt::Error)
25 {
26 cause(cause)
27 description(cause.description())
28 display("Format error with {:?} was '{}'", path, cause)
29 context(path: &'a Path, cause: ::std::fmt::Error) -> (path.to_path_buf(), cause)
30 }
31
32 /// An error occurred during a parse.
33 Parse(path: PathBuf, source_location: SourceLocation, reason: String)
34 {
35 description(&reason)
36 display("Parse error with {:?} at '{:?}' was '{}'", path, source_location, &reason)
37 }
38 }
39}