8000 fix(mfile): refuse minimal.toml keys this release does not support yet, and a pty_enabled the root excludes by minimal-backporter[bot] · Pull Request #4081 · gominimal/minimal · GitHub
[go: up one dir, main page]

Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions crates/mfile/src/box_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1250,19 +1250,20 @@ mod tests {
// A type that sets a key in both forms is not checked against
// itself, and each form constrains the type that extends it.
let both = "[box_types.dev]\nextends = \"session\"\n\
constraints = { restart = [\"never\", \"always\"], execution = { restart = \"never\" } }\n";
constraints = { lifetime = [\"until_complete\", \"until_stopped\"], \
box = { lifetime = \"until_complete\" } }\n";
types(both).expect("one type's two forms are not checked against each other");
let err = types(&format!(
"{both}[box_types.leaf]\nextends = \"dev\"\nconstraints = {{ restart = \"always\" }}\n"
"{both}[box_types.leaf]\nextends = \"dev\"\nconstraints = {{ lifetime = \"until_stopped\" }}\n"
))
.expect_err("the section form of dev excludes always");
.expect_err("the section form of dev excludes until_stopped");
assert_eq!(
err,
BoxTypeError::Loosening {
name: "leaf".into(),
key: "restart".into(),
key: "lifetime".into(),
parent: "dev".into(),
value: Some("\"always\"".into()),
value: Some("\"until_stopped\"".into()),
}
);

Expand Down
77 changes: 77 additions & 0 deletions crates/mfile/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ pub enum Error {
box_type: String,
admitted: Vec<String>,
},
/// A layer sets `pty_enabled` to the value that the entry's built-in
/// root excludes (BOX-160, #4044): `false` for `session`, `true` for
/// `task`. Carries the key as the layer wrote it, the layer as the
/// message names it, the root, and whether the layer is a table of the
/// project's `minimal.toml`. Exits 3.
TerminalExcluded {
key: String,
layer: String,
root: &'static str,
in_project_file: bool,
},
/// A spec sets the box's name twice, as a flat `name` and as
/// `box.name`, to two different values (#4067). Carries each layer as
/// the message names it, each value, and whether the flat key's layer
/// is a table of the project's `minimal.toml`. Exits 3.
NameSetTwice {
flat_layer: String,
nested_layer: String,
flat: String,
nested: String,
in_project_file: bool,
},
/// The entry's Box Type does not resolve, or the entry cannot use it.
/// Exits 3.
BoxType(Box<crate::box_types::BoxTypeError>),
Expand Down Expand Up @@ -249,6 +271,14 @@ pub enum TrustedCaProblem {
pub enum SpecKeyProblem {
/// No box setting has this name.
Unknown,
/// No box setting has this name, and the key was in use: a release
/// or a committed `minimal.toml` set it (#4038). Carries the sentences
/// that name what to do instead.
Removed { hint: &'static str },
/// The architecture's `box.toml` specifies the key, and this release
/// does not implement it yet
/// ([`crate::expand::NOT_SUPPORTED_YET`], #4038).
NotSupportedYet,
/// The key is inside an `[upstream]` table, and is not one of the
/// registry pin's keys.
UnknownUpstream,
Expand Down Expand Up @@ -336,6 +366,8 @@ impl Error {
| Error::LoadoutSetsLoadoutMode { .. }
| Error::NamedLoadoutOnSealedBox { .. }
| Error::ConstraintViolated { .. }
| Error::TerminalExcluded { .. }
| Error::NameSetTwice { .. }
| Error::BoxType(_)
| Error::LoadoutVarConflict { .. }
| Error::DerivedGrantConflictsWithClientEnv { .. }
Expand Down Expand Up @@ -380,6 +412,12 @@ impl Error {
| Error::InvalidSpecKey {
in_project_file, ..
}
| Error::TerminalExcluded {
in_project_file, ..
}
| Error::NameSetTwice {
in_project_file, ..
}
| Error::InfrastructureCasSet {
in_project_file, ..
}
Expand Down Expand Up @@ -501,6 +539,17 @@ impl fmt::Display for Error {
"{layer} sets `{key}`, which is not a box setting. \
Remove the key or correct its name."
),
SpecKeyProblem::NotSupportedYet => write!(
f,
"{layer} sets `{key}`, which this release does not support yet. \
Remove `{key}` to start the box."
),
SpecKeyProblem::Removed { hint } => {
write!(
f,
"{layer} sets `{key}`, which is not a box setting. {hint}"
)
}
SpecKeyProblem::UnknownUpstream => write!(
f,
"{layer} sets `{key}`, which is not an `[upstream]` setting. \
Expand Down Expand Up @@ -623,6 +672,32 @@ impl fmt::Display for Error {
),
}
}
Error::TerminalExcluded {
key, layer, root, ..
} => {
let (value, has, fix) = if *root == "task" {
("true", "A task never has a terminal", "false")
} else {
("false", "A session always has a terminal", "true")
};
write!(
f,
"{layer} sets `{key}` to `{value}`, but the entry's built-in \
type is `{root}`. {has}. Remove `{key}`, or set it to `{fix}`."
)
}
Error::NameSetTwice {
flat_layer,
nested_layer,
flat,
nested,
..
} => write!(
f,
"{flat_layer} sets `name` to {flat:?}, and {nested_layer} sets \
`box.name` to {nested:?}. Both set the box's name. Remove one of \
them, or give them the same value."
),
// The type error's own message is the whole message.
Error::BoxType(error) => write!(f, "{error}"),
Error::ConstraintViolated {
Expand Down Expand Up @@ -833,6 +908,8 @@ impl std::error::Error for Error {
Error::LoadoutSetsLoadoutMode { .. } => None,
Error::NamedLoadoutOnSealedBox { .. } => None,
Error::ConstraintViolated { .. } => None,
Error::TerminalExcluded { .. } => None,
Error::NameSetTwice { .. } => None,
// `Display` prints the type error, so a chain printer prints it
// once.
Error::BoxType(_) => None,
Expand Down
Loading
Loading
0