refactor(tvix): turn nullary enum variants into unit variants
Change-Id: Iad4f2cb4aa92b5bb29ead6050348a8cd3e7b8632 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9860 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
520c5a191e
commit
e525272019
6 changed files with 30 additions and 30 deletions
|
@ -48,7 +48,7 @@ pub enum ValidateNodeError {
|
|||
InvalidDigestLen(usize),
|
||||
/// Invalid name encountered
|
||||
#[error("Invalid name")]
|
||||
InvalidName(),
|
||||
InvalidName,
|
||||
/// Invalid symlink target
|
||||
#[error("Invalid symlink target: {}", .0.as_bstr())]
|
||||
InvalidSymlinkTarget(Vec<u8>),
|
||||
|
@ -63,7 +63,7 @@ fn validate_node_name(name: &[u8]) -> Result<(), ValidateNodeError> {
|
|||
|| name.contains(&0x00)
|
||||
|| name.contains(&b'/')
|
||||
{
|
||||
Err(ValidateNodeError::InvalidName())?;
|
||||
Err(ValidateNodeError::InvalidName)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -165,7 +165,7 @@ fn validate_invalid_names() {
|
|||
..Default::default()
|
||||
};
|
||||
match d.validate().expect_err("must fail") {
|
||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName()) => {
|
||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
|
||||
assert_eq!(n, b"")
|
||||
}
|
||||
_ => panic!("unexpected error"),
|
||||
|
@ -182,7 +182,7 @@ fn validate_invalid_names() {
|
|||
..Default::default()
|
||||
};
|
||||
match d.validate().expect_err("must fail") {
|
||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName()) => {
|
||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
|
||||
assert_eq!(n, b".")
|
||||
}
|
||||
_ => panic!("unexpected error"),
|
||||
|
@ -200,7 +200,7 @@ fn validate_invalid_names() {
|
|||
..Default::default()
|
||||
};
|
||||
match d.validate().expect_err("must fail") {
|
||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName()) => {
|
||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
|
||||
assert_eq!(n, b"..")
|
||||
}
|
||||
_ => panic!("unexpected error"),
|
||||
|
@ -216,7 +216,7 @@ fn validate_invalid_names() {
|
|||
..Default::default()
|
||||
};
|
||||
match d.validate().expect_err("must fail") {
|
||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName()) => {
|
||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
|
||||
assert_eq!(n, b"\x00")
|
||||
}
|
||||
_ => panic!("unexpected error"),
|
||||
|
@ -232,7 +232,7 @@ fn validate_invalid_names() {
|
|||
..Default::default()
|
||||
};
|
||||
match d.validate().expect_err("must fail") {
|
||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName()) => {
|
||||
ValidateDirectoryError::InvalidNode(n, ValidateNodeError::InvalidName) => {
|
||||
assert_eq!(n, b"foo/bar")
|
||||
}
|
||||
_ => panic!("unexpected error"),
|
||||
|
|
|
@ -19,7 +19,7 @@ pub enum Nixbase32DecodeError {
|
|||
#[error("character {0:x} not in alphabet")]
|
||||
CharacterNotInAlphabet(u8),
|
||||
#[error("nonzero carry")]
|
||||
NonzeroCarry(),
|
||||
NonzeroCarry,
|
||||
#[error("invalid length")]
|
||||
InvalidLength,
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ fn decode_inner(input: &[u8], output: &mut [u8]) -> Result<(), Nixbase32DecodeEr
|
|||
|
||||
// if we're at the end, but have a nonzero carry, the encoding is invalid.
|
||||
if carry != 0 {
|
||||
return Err(Nixbase32DecodeError::NonzeroCarry());
|
||||
return Err(Nixbase32DecodeError::NonzeroCarry);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -28,11 +28,11 @@ pub const STORE_DIR_WITH_SLASH: &str = "/nix/store/";
|
|||
#[derive(Debug, PartialEq, Eq, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("Dash is missing between hash and name")]
|
||||
MissingDash(),
|
||||
MissingDash,
|
||||
#[error("Hash encoding is invalid: {0}")]
|
||||
InvalidHashEncoding(Nixbase32DecodeError),
|
||||
#[error("Invalid length")]
|
||||
InvalidLength(),
|
||||
InvalidLength,
|
||||
#[error(
|
||||
"Invalid name: \"{}\", character at position {} is invalid",
|
||||
std::str::from_utf8(.0).unwrap_or(&BASE64.encode(.0)),
|
||||
|
@ -40,7 +40,7 @@ pub enum Error {
|
|||
)]
|
||||
InvalidName(Vec<u8>, u8),
|
||||
#[error("Tried to parse an absolute path which was missing the store dir prefix.")]
|
||||
MissingStoreDir(),
|
||||
MissingStoreDir,
|
||||
}
|
||||
|
||||
/// Represents a path in the Nix store (a direct child of [STORE_DIR]).
|
||||
|
@ -102,7 +102,7 @@ impl StorePath {
|
|||
// - 1 dash
|
||||
// - 1 character for the name
|
||||
if s.len() < ENCODED_DIGEST_SIZE + 2 {
|
||||
Err(Error::InvalidLength())?
|
||||
Err(Error::InvalidLength)?
|
||||
}
|
||||
|
||||
let digest = match nixbase32::decode(&s[..ENCODED_DIGEST_SIZE]) {
|
||||
|
@ -111,7 +111,7 @@ impl StorePath {
|
|||
};
|
||||
|
||||
if s[ENCODED_DIGEST_SIZE] != b'-' {
|
||||
return Err(Error::MissingDash());
|
||||
return Err(Error::MissingDash);
|
||||
}
|
||||
|
||||
Ok(StorePath {
|
||||
|
@ -126,7 +126,7 @@ impl StorePath {
|
|||
pub fn from_absolute_path(s: &[u8]) -> Result<StorePath, Error> {
|
||||
match s.strip_prefix(STORE_DIR_WITH_SLASH.as_bytes()) {
|
||||
Some(s_stripped) => Self::from_bytes(s_stripped),
|
||||
None => Err(Error::MissingStoreDir()),
|
||||
None => Err(Error::MissingStoreDir),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ impl StorePath {
|
|||
pub fn from_name_and_digest(name: String, digest: &[u8]) -> Result<StorePath, Error> {
|
||||
Ok(Self {
|
||||
name: validate_name(name.as_bytes())?.to_owned(),
|
||||
digest: digest.try_into().map_err(|_| Error::InvalidLength())?,
|
||||
digest: digest.try_into().map_err(|_| Error::InvalidLength)?,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ impl StorePath {
|
|||
pub fn from_absolute_path_full(s: &str) -> Result<(StorePath, PathBuf), Error> {
|
||||
// strip [STORE_DIR_WITH_SLASH] from s
|
||||
match s.strip_prefix(STORE_DIR_WITH_SLASH) {
|
||||
None => Err(Error::MissingStoreDir()),
|
||||
None => Err(Error::MissingStoreDir),
|
||||
Some(rest) => {
|
||||
// put rest in a PathBuf
|
||||
let mut p = PathBuf::new();
|
||||
|
@ -161,7 +161,7 @@ impl StorePath {
|
|||
let rest_buf: PathBuf = it.collect();
|
||||
Ok((store_path, rest_buf))
|
||||
} else {
|
||||
Err(Error::InvalidLength()) // Well, or missing "/"?
|
||||
Err(Error::InvalidLength) // Well, or missing "/"?
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -205,7 +205,7 @@ pub(crate) fn validate_name(s: &(impl AsRef<[u8]> + ?Sized)) -> Result<&str, Err
|
|||
|
||||
// Empty or excessively long names are not allowed.
|
||||
if s.is_empty() || s.len() > 211 {
|
||||
return Err(Error::InvalidLength());
|
||||
return Err(Error::InvalidLength);
|
||||
}
|
||||
|
||||
if s[0] == b'.' {
|
||||
|
@ -341,7 +341,7 @@ mod tests {
|
|||
#[test]
|
||||
fn absolute_path_missing_prefix() {
|
||||
assert_eq!(
|
||||
Error::MissingStoreDir(),
|
||||
Error::MissingStoreDir,
|
||||
StorePath::from_absolute_path(b"foobar-123").expect_err("must fail")
|
||||
);
|
||||
}
|
||||
|
@ -370,15 +370,15 @@ mod tests {
|
|||
#[test]
|
||||
fn from_absolute_path_errors() {
|
||||
assert_eq!(
|
||||
Error::InvalidLength(),
|
||||
Error::InvalidLength,
|
||||
StorePath::from_absolute_path_full("/nix/store/").expect_err("must fail")
|
||||
);
|
||||
assert_eq!(
|
||||
Error::InvalidLength(),
|
||||
Error::InvalidLength,
|
||||
StorePath::from_absolute_path_full("/nix/store/foo").expect_err("must fail")
|
||||
);
|
||||
assert_eq!(
|
||||
Error::MissingStoreDir(),
|
||||
Error::MissingStoreDir,
|
||||
StorePath::from_absolute_path_full(
|
||||
"00bgd045z0d4icpbc2yyz4gx48ak44la-net-tools-1.60_p20170221182432"
|
||||
)
|
||||
|
|
|
@ -29,7 +29,7 @@ pub enum ValidatePathInfoError {
|
|||
|
||||
/// No node present
|
||||
#[error("No node present")]
|
||||
NoNodePresent(),
|
||||
NoNodePresent,
|
||||
|
||||
/// Node fails validation
|
||||
#[error("Invalid root node: {:?}", .0.to_string())]
|
||||
|
@ -159,7 +159,7 @@ impl PathInfo {
|
|||
// Ensure there is a (root) node present, and it properly parses to a [store_path::StorePath].
|
||||
let root_nix_path = match &self.node {
|
||||
None | Some(castorepb::Node { node: None }) => {
|
||||
Err(ValidatePathInfoError::NoNodePresent())?
|
||||
Err(ValidatePathInfoError::NoNodePresent)?
|
||||
}
|
||||
Some(castorepb::Node { node: Some(node) }) => {
|
||||
node.validate()
|
||||
|
|
|
@ -8,12 +8,12 @@ use tvix_castore::proto as castorepb;
|
|||
|
||||
#[test_case(
|
||||
None,
|
||||
Err(ValidatePathInfoError::NoNodePresent()) ;
|
||||
Err(ValidatePathInfoError::NoNodePresent) ;
|
||||
"No node"
|
||||
)]
|
||||
#[test_case(
|
||||
Some(castorepb::Node { node: None }),
|
||||
Err(ValidatePathInfoError::NoNodePresent());
|
||||
Err(ValidatePathInfoError::NoNodePresent);
|
||||
"No node 2"
|
||||
)]
|
||||
fn validate_no_node(
|
||||
|
@ -54,7 +54,7 @@ fn validate_no_node(
|
|||
},
|
||||
Err(ValidatePathInfoError::InvalidNodeName(
|
||||
"invalid".into(),
|
||||
store_path::Error::InvalidLength()
|
||||
store_path::Error::InvalidLength
|
||||
));
|
||||
"invalid node name"
|
||||
)]
|
||||
|
@ -99,7 +99,7 @@ fn validate_directory(
|
|||
},
|
||||
Err(ValidatePathInfoError::InvalidNodeName(
|
||||
"invalid".into(),
|
||||
store_path::Error::InvalidLength()
|
||||
store_path::Error::InvalidLength
|
||||
));
|
||||
"invalid node name"
|
||||
)]
|
||||
|
@ -132,7 +132,7 @@ fn validate_file(
|
|||
},
|
||||
Err(ValidatePathInfoError::InvalidNodeName(
|
||||
"invalid".into(),
|
||||
store_path::Error::InvalidLength()
|
||||
store_path::Error::InvalidLength
|
||||
));
|
||||
"invalid node name"
|
||||
)]
|
||||
|
|
Loading…
Reference in a new issue