Skip to content

Commit 3f9b265

Browse files
roypatzulinx86
authored andcommitted
chore: use thiserror for seccomp::FilterError
Please see issue #3278 for context on this activity Signed-off-by: Patrick Roy <[email protected]>
1 parent c61ae08 commit 3f9b265

File tree

3 files changed

+7
-19
lines changed

3 files changed

+7
-19
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/firecracker/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ bench = false
1616
event-manager = "0.3.0"
1717
libc = "0.2.146"
1818
serde_json = "1.0.78"
19+
thiserror = "1.0.32"
1920
timerfd = "1.3.0"
2021

2122
api_server = { path = "../api_server" }

src/firecracker/src/seccomp.rs

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
use std::fmt;
43
use std::fs::File;
54
use std::io::{BufReader, Read};
65

@@ -16,35 +15,22 @@ const THREAD_CATEGORIES: [&str; 3] = ["vmm", "api", "vcpu"];
1615
const DESERIALIZATION_BYTES_LIMIT: Option<u64> = Some(100_000);
1716

1817
/// Error retrieving seccomp filters.
19-
#[derive(fmt::Debug)]
18+
#[derive(Debug, thiserror::Error)]
2019
pub enum FilterError {
2120
/// Filter deserialitaion error.
21+
#[error("Filter deserialization failed: {0}")]
2222
Deserialization(DeserializationError),
2323
/// Invalid thread categories.
24+
#[error("Invalid thread categories: {0}")]
2425
ThreadCategories(String),
2526
/// Missing Thread Category.
27+
#[error("Missing thread category: {0}")]
2628
MissingThreadCategory(String),
2729
/// File open error.
30+
#[error("Filter file open error: {0}")]
2831
FileOpen(std::io::Error),
2932
}
3033

31-
impl fmt::Display for FilterError {
32-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
33-
use self::FilterError::*;
34-
35-
match *self {
36-
Deserialization(ref err) => write!(f, "Filter deserialization failed: {}", err),
37-
ThreadCategories(ref categories) => {
38-
write!(f, "Invalid thread categories: {}", categories)
39-
}
40-
MissingThreadCategory(ref category) => {
41-
write!(f, "Missing thread category: {}", category)
42-
}
43-
FileOpen(ref err) => write!(f, "Filter file open error: {}", err),
44-
}
45-
}
46-
}
47-
4834
/// Seccomp filter configuration.
4935
pub enum SeccompConfig {
5036
/// Seccomp filtering disabled.

0 commit comments

Comments
 (0)