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

Add details to InstanceError and CreateSurfaceError. #4066

Merged
merged 7 commits into from
Sep 1, 2023

Conversation

kpreid
Copy link
Contributor

@kpreid kpreid commented Aug 16, 2023

Checklist

  • Update all backends
  • Add tests where feasible, such as WebGL and WebGPU canvas errors
  • Run cargo clippy.
  • Run cargo clippy --target wasm32-unknown-unknown if applicable.
  • Add change to CHANGELOG.md.

Connections
Followup to #3052.

Description
This will allow developers, particularly those in communication with users with hardware they don't own, to diagnose “why won't this work on my machine” better, without needing to obtain logs in addition to the error value.

Note that this is a semver-breaking change because InstanceError and CreateSurfaceError no longer implement PartialEq. This could be avoided by pointer comparison of the internal Arc, but I think it is more typical Rust to not implement PartialEq for error types unless there is a strong motivation to and their contents are tightly controlled.

Testing
Ran cargo nextest run; CI will check other platforms.

This will allow developers, particularly those in communication with
users with hardware they don't own, to diagnose “why won't this work
on my machine” better, without needing to obtain logs in addition to
the error value.

Note that this is a semver-breaking change because `InstanceError` and
`CreateSurfaceError` no longer implement `PartialEq`. This could be
avoided by pointer comparison of the internal `Arc`, but I think it is
more typical Rust to not implement `PartialEq` for error types unless
there is a strong motivation to and their contents are tightly
controlled.
@kpreid
Copy link
Contributor Author

kpreid commented Aug 17, 2023

This PR is in principle ready to merge, but I am hoping to get around to writing tests for the canvas.getContext() errors before I mark it ready.

@kpreid
Copy link
Contributor Author

kpreid commented Aug 21, 2023

I've added a test for create_surface_from_canvas() under WebGL and WebGPU. However, a certain amount of persuasion was required for tests/src/lib.rs to cooperate with the custom canvas creation. Please review carefully (and CI will hopefully tell us if the cfgs are wrong).

@kpreid kpreid marked this pull request as ready for review August 21, 2023 03:01
@kpreid
Copy link
Contributor Author

kpreid commented Aug 22, 2023

That clippy::redundant_clone lint that failed in CI is completely bogus — the code wouldn't compile (and would be wrong) without it, since SurfaceGuard has a Drop. I've allowed it.

@kpreid
Copy link
Contributor Author

kpreid commented Aug 29, 2023

Ping? This should be ready to go now.

Also, I have belatedly realized that I want to do exactly the same thing to RequestDeviceError — would you prefer that be folded into this PR or separate?

Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

This is beautiful stuff!

@cwfitzgerald cwfitzgerald merged commit 332cd03 into gfx-rs:trunk Sep 1, 2023
@kpreid kpreid deleted the error branch September 15, 2023 19:29
@kpreid kpreid mentioned this pull request Sep 15, 2023
3 tasks
bradwerth pushed a commit to bradwerth/wgpu that referenced this pull request Sep 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants