##// END OF EJS Templates
ci: add a runner for Windows 10...
ci: add a runner for Windows 10 This is currently only manually invoked, and allows for failure because we only have a single runner that takes over 2h for a full run, and there are a handful of flakey tests, plus 3 known failing tests. The system being used here is running MSYS, Python, Visual Studio, etc, as installed by `install-windows-dependencies.ps1`. This script installs everything to a specific directory instead of using the defaults, so we adjust the MinGW shell path to compensate. Additionally, the script doesn't install the launcher `py.exe`. It is possible to adjust the script to install it, but it's an option to an existing python install (instead of a standalone installer), and I've had the whole python install fail and rollback when requested to install the launcher if it detects a newer one is already installed. In short, it is a point of failure for a feature we don't (yet?) need. Unlike other systems where the intepreter name includes the version, everything here is `python.exe`, so they can't all exist on `PATH` and let the script choose the desired one. (The `py.exe` launcher would accomplish, using the registry instead of `PATH`, but that wouldn't allow for venv installs.) Because of this, switch to the absolute path of the python interpreter to be used (in this case a venv created from the py39 install, which is old, but what both pyoxidizer and TortoiseHg currently use). The `RUNTEST_ARGS` hardcodes `-j8` because this system has 4 cores, and therefore runs 4 parallel tests by default. However on Windows, using more parallel tests than cores results in better performance for whatever reason. I don't have an optimal value yet (ideally the runner itself can make the adjustment on Windows), but this results in saving ~15m on a full run that otherwise takes ~2.5h. I'm also not concerned about how it would affect other Windows machines, because we don't have any at this point, and I have no idea when we can get more. As far as system setup goes, the CI is run by a dedicated user that lacks admin rights. The install script was run by an admin user, and then the standard user was configured to use it. If I set this up again, I'd probably give the dedicated user admin rights to run the install script, and reset to standard user rights when done. The python intepreter failed in weird ways when run by the standard user until it was manually reinstalled by the standard user: Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding Additionally, changing the environment through the Windows UI prompts to escalate to an admin user, and then setting the user level environment variables like `TEMP` and `PATH` (to try to avoid exceeding the 260 character path limit) didn't actually change the user's environment. (Likely it changed the admin user's environment, but I didn't confirm that.) I ended up having to use the registry editor for the standard user to make those changes.

File last commit:

r52943:de317a87 default
r53049:8766d47e stable
Show More
errors.rs
224 lines | 7.3 KiB | application/rls-services+xml | RustLexer
Simon Sapin
rust: Add a `ConfigValueParseError` variant to common errors...
r47340 use crate::config::ConfigValueParseError;
Pulkit Goyal
rhg: add exit code to HgError::Abort()...
r48199 use crate::exit_codes;
Raphaël Gomès
rust-pathauditor: match more of Python's behavior and display messages...
r52943 use crate::utils::hg_path::HgPathError;
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 use std::fmt;
/// Common error cases that can happen in many different APIs
Simon Sapin
rust: Add a `ConfigValueParseError` variant to common errors...
r47340 #[derive(Debug, derive_more::From)]
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 pub enum HgError {
IoError {
error: std::io::Error,
context: IoErrorContext,
},
Simon Sapin
rhg: Abort based on config on share-safe mismatch...
r47214 /// A file under `.hg/` normally only written by Mercurial is not in the
/// expected format. This indicates a bug in Mercurial, filesystem
/// corruption, or hardware failure.
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 ///
/// The given string is a short explanation for users, not intended to be
/// machine-readable.
CorruptedRepository(String),
/// The respository or requested operation involves a feature not
/// supported by the Rust implementation. Falling back to the Python
/// implementation may or may not work.
///
/// The given string is a short explanation for users, not intended to be
/// machine-readable.
UnsupportedFeature(String),
Simon Sapin
rhg: Abort based on config on share-safe mismatch...
r47214
/// Operation cannot proceed for some other reason.
///
Pulkit Goyal
rhg: add exit code to HgError::Abort()...
r48199 /// The message is a short explanation for users, not intended to be
Simon Sapin
rhg: Abort based on config on share-safe mismatch...
r47214 /// machine-readable.
Pulkit Goyal
rhg: add exit code to HgError::Abort()...
r48199 Abort {
message: String,
detailed_exit_code: exit_codes::ExitCode,
Raphaël Gomès
rust: add support for hints in error messages...
r50382 hint: Option<String>,
Pulkit Goyal
rhg: add exit code to HgError::Abort()...
r48199 },
Simon Sapin
rust: Add a `ConfigValueParseError` variant to common errors...
r47340
/// A configuration value is not in the expected syntax.
///
/// These errors can happen in many places in the code because values are
/// parsed lazily as the file-level parser does not know the expected type
/// and syntax of each value.
#[from]
ConfigValueParseError(ConfigValueParseError),
Arseniy Alekseyev
censor: make rhg fall back to python when encountering a censored node...
r50069
/// Censored revision data.
CensoredNodeError,
dirstate: deal with read-race for pure rust code path (rhg)...
r51134 /// A race condition has been detected. This *must* be handled locally
/// and not directly surface to the user.
RaceDetected(String),
Raphaël Gomès
rust-pathauditor: match more of Python's behavior and display messages...
r52943 /// An invalid path was found
Path(HgPathError),
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 }
/// Details about where an I/O error happened
Simon Sapin
rust: Add a log file rotation utility...
r47341 #[derive(Debug)]
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 pub enum IoErrorContext {
Simon Sapin
rhg: Propagate permission errors when finding a repository...
r48584 /// `std::fs::metadata`
ReadingMetadata(std::path::PathBuf),
Simon Sapin
rust: Add a log file rotation utility...
r47341 ReadingFile(std::path::PathBuf),
WritingFile(std::path::PathBuf),
RemovingFile(std::path::PathBuf),
RenamingFile {
from: std::path::PathBuf,
to: std::path::PathBuf,
},
Simon Sapin
rhg: Don’t make repository path absolute too early...
r47474 /// `std::fs::canonicalize`
CanonicalizingPath(std::path::PathBuf),
Simon Sapin
rust: Parse system and user configuration...
r47212 /// `std::env::current_dir`
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 CurrentDir,
Simon Sapin
rust: Parse system and user configuration...
r47212 /// `std::env::current_exe`
CurrentExe,
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 }
impl HgError {
pub fn corrupted(explanation: impl Into<String>) -> Self {
Simon Sapin
rust: use HgError in RevlogError and Vfs...
r47172 // TODO: capture a backtrace here and keep it in the error value
// to aid debugging?
// https://doc.rust-lang.org/std/backtrace/struct.Backtrace.html
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 HgError::CorruptedRepository(explanation.into())
}
Simon Sapin
rhg: initial support for shared repositories...
r47190
pub fn unsupported(explanation: impl Into<String>) -> Self {
HgError::UnsupportedFeature(explanation.into())
}
Pulkit Goyal
rhg: add exit code to HgError::Abort()...
r48199
pub fn abort(
explanation: impl Into<String>,
exit_code: exit_codes::ExitCode,
Raphaël Gomès
rust: add support for hints in error messages...
r50382 hint: Option<String>,
Pulkit Goyal
rhg: add exit code to HgError::Abort()...
r48199 ) -> Self {
HgError::Abort {
message: explanation.into(),
detailed_exit_code: exit_code,
Raphaël Gomès
rust: add support for hints in error messages...
r50382 hint,
Pulkit Goyal
rhg: add exit code to HgError::Abort()...
r48199 }
Simon Sapin
rhg: Abort based on config on share-safe mismatch...
r47214 }
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 }
// TODO: use `DisplayBytes` instead to show non-Unicode filenames losslessly?
impl fmt::Display for HgError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Pulkit Goyal
rhg: add exit code to HgError::Abort()...
r48199 HgError::Abort { message, .. } => write!(f, "{}", message),
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 HgError::IoError { error, context } => {
Simon Sapin
rhg: Align config file parse error formatting with Python...
r47465 write!(f, "abort: {}: {}", context, error)
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 }
HgError::CorruptedRepository(explanation) => {
Simon Sapin
rhg: Align with Python on some more error messages...
r47469 write!(f, "abort: {}", explanation)
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 }
HgError::UnsupportedFeature(explanation) => {
write!(f, "unsupported feature: {}", explanation)
}
Arseniy Alekseyev
censor: make rhg fall back to python when encountering a censored node...
r50069 HgError::CensoredNodeError => {
write!(f, "encountered a censored node")
}
Simon Sapin
rhg: Add more conversions between error types...
r47555 HgError::ConfigValueParseError(error) => error.fmt(f),
dirstate: deal with read-race for pure rust code path (rhg)...
r51134 HgError::RaceDetected(context) => {
write!(f, "encountered a race condition {context}")
}
Raphaël Gomès
rust-pathauditor: match more of Python's behavior and display messages...
r52943 HgError::Path(hg_path_error) => write!(f, "{}", hg_path_error),
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 }
}
}
// TODO: use `DisplayBytes` instead to show non-Unicode filenames losslessly?
impl fmt::Display for IoErrorContext {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Simon Sapin
rhg: Propagate permission errors when finding a repository...
r48584 IoErrorContext::ReadingMetadata(path) => {
write!(f, "when reading metadata of {}", path.display())
}
Simon Sapin
rust: Add a log file rotation utility...
r47341 IoErrorContext::ReadingFile(path) => {
write!(f, "when reading {}", path.display())
}
IoErrorContext::WritingFile(path) => {
write!(f, "when writing {}", path.display())
}
IoErrorContext::RemovingFile(path) => {
write!(f, "when removing {}", path.display())
}
IoErrorContext::RenamingFile { from, to } => write!(
f,
"when renaming {} to {}",
from.display(),
to.display()
),
Simon Sapin
rhg: Don’t make repository path absolute too early...
r47474 IoErrorContext::CanonicalizingPath(path) => {
write!(f, "when canonicalizing {}", path.display())
}
Simon Sapin
rhg: Align config file parse error formatting with Python...
r47465 IoErrorContext::CurrentDir => {
write!(f, "error getting current working directory")
}
IoErrorContext::CurrentExe => {
write!(f, "error getting current executable")
}
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 }
}
}
pub trait IoResultExt<T> {
Simon Sapin
rust: Add a log file rotation utility...
r47341 /// Annotate a possible I/O error as related to a reading a file at the
/// given path.
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 ///
Simon Sapin
rust: Add a log file rotation utility...
r47341 /// This allows printing something like “File not found when reading
/// example.txt” instead of just “File not found”.
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 ///
/// Converts a `Result` with `std::io::Error` into one with `HgError`.
Simon Sapin
rust: Add a log file rotation utility...
r47341 fn when_reading_file(self, path: &std::path::Path) -> Result<T, HgError>;
Simon Sapin
rust: Add Vfs::write_atomic...
r49246 fn when_writing_file(self, path: &std::path::Path) -> Result<T, HgError>;
Simon Sapin
rust: Add a log file rotation utility...
r47341 fn with_context(
self,
context: impl FnOnce() -> IoErrorContext,
) -> Result<T, HgError>;
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 }
impl<T> IoResultExt<T> for std::io::Result<T> {
Simon Sapin
rust: Add a log file rotation utility...
r47341 fn when_reading_file(self, path: &std::path::Path) -> Result<T, HgError> {
self.with_context(|| IoErrorContext::ReadingFile(path.to_owned()))
}
Simon Sapin
rust: Add Vfs::write_atomic...
r49246 fn when_writing_file(self, path: &std::path::Path) -> Result<T, HgError> {
self.with_context(|| IoErrorContext::WritingFile(path.to_owned()))
}
Simon Sapin
rust: Add a log file rotation utility...
r47341 fn with_context(
self,
context: impl FnOnce() -> IoErrorContext,
) -> Result<T, HgError> {
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 self.map_err(|error| HgError::IoError {
error,
Simon Sapin
rust: Add a log file rotation utility...
r47341 context: context(),
Simon Sapin
rust: Introduce an `HgError` enum for common error cases...
r47167 })
}
}
pub trait HgResultExt<T> {
/// Handle missing files separately from other I/O error cases.
///
/// Wraps the `Ok` type in an `Option`:
///
/// * `Ok(x)` becomes `Ok(Some(x))`
/// * An I/O "not found" error becomes `Ok(None)`
/// * Other errors are unchanged
fn io_not_found_as_none(self) -> Result<Option<T>, HgError>;
}
impl<T> HgResultExt<T> for Result<T, HgError> {
fn io_not_found_as_none(self) -> Result<Option<T>, HgError> {
match self {
Ok(x) => Ok(Some(x)),
Err(HgError::IoError { error, .. })
if error.kind() == std::io::ErrorKind::NotFound =>
{
Ok(None)
}
Err(other_error) => Err(other_error),
}
}
}