Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

client: Include version info and interface name in BindError #682

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
5 changes: 5 additions & 0 deletions wayland-client/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
## Unreleased

#### Additions

- Implement `Eq` for `Connection`

#### Breaking changes

- `BindError` now includes the requested and available version, or interface name that failed to bind.

## 0.31.1 -- 2023-09-19

#### Additions
Expand Down
45 changes: 24 additions & 21 deletions wayland-client/src/globals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
/// version of the returned protocol object is the lower of the maximum requested version and the advertised
/// version.
///
/// If the lower bound of the `version` is less than the version advertised by the server, then
/// If the lower bound of the `version` is greater than the version advertised by the server, then
/// [`BindError::UnsupportedVersion`] is returned.
Comment on lines -118 to 119
Copy link
Contributor Author

@MarijnS95 MarijnS95 Dec 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I assume happened here is that let version in the code is rebound to what is found in the global registry (i.e. the version that is available), while "the lower bound of the version" is rebound to version_start.

///
/// ## Multi-instance/Device globals.
Expand Down Expand Up @@ -152,23 +152,19 @@

let globals = &self.registry.data::<GlobalListContents>().unwrap().contents;
let guard = globals.lock().unwrap();
let (name, version) = guard
let &Global { name, version, .. } = guard
.iter()
// Find the with the correct interface
.filter_map(|Global { name, interface: interface_name, version }| {
// TODO: then_some
if interface.name == &interface_name[..] {
Some((*name, *version))
} else {
None
}
})
.next()
.ok_or(BindError::NotPresent)?;
// Find the global with the correct interface
.find(|Global { interface: interface_name, .. }| interface.name == interface_name)
.ok_or(BindError::NotPresent(interface.name))?;

// Test version requirements
if version < version_start {
return Err(BindError::UnsupportedVersion);
if version_start > version {
return Err(BindError::UnsupportedVersion {
interface: interface.name,
requested: version_start,
available: version,
});
}

// To get the version to bind, take the lower of the version advertised by the server and the maximum
Expand Down Expand Up @@ -232,22 +228,29 @@
#[derive(Debug)]
pub enum BindError {
/// The requested version of the global is not supported.
UnsupportedVersion,
UnsupportedVersion {
/// The name of the global for which the server provides a too low value.
interface: &'static str,
/// The lowest version that was requested by the caller, must be greater than [`Self::UnsupportedVersion::requested`].
requested: u32,
/// The actual verison that was available on the server, must be less than [`Self::UnsupportedVersion::requested`].
available: u32,
},

/// The requested global was not found in the registry.
NotPresent,
NotPresent(&'static str),
}

impl std::error::Error for BindError {}

impl fmt::Display for BindError {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
BindError::UnsupportedVersion {} => {
write!(f, "the requested version of the global is not supported")
BindError::UnsupportedVersion { interface, requested, available } => {
write!(f, "the requested version `{requested}` of the global `{interface}` is not supported, only `{available}` is available")

Check warning on line 250 in wayland-client/src/globals.rs

View check run for this annotation

Codecov / codecov/patch

wayland-client/src/globals.rs#L249-L250

Added lines #L249 - L250 were not covered by tests
}
BindError::NotPresent {} => {
write!(f, "the requested global was not found in the registry")
BindError::NotPresent(name) => {
write!(f, "the requested global `{name}` was not found in the registry")

Check warning on line 253 in wayland-client/src/globals.rs

View check run for this annotation

Codecov / codecov/patch

wayland-client/src/globals.rs#L252-L253

Added lines #L252 - L253 were not covered by tests
}
}
}
Expand Down
Loading