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

Better error types #516

Merged
merged 18 commits into from
May 30, 2024
Merged

Better error types #516

merged 18 commits into from
May 30, 2024

Conversation

DasLixou
Copy link
Collaborator

@DasLixou DasLixou commented Mar 9, 2024

Using custom thiserror errors instead of Box<dyn Error>, closes #285

This removed the use of Result as a return type for many functions, including RenderContext::new(). This "could" fail when no backend feature is activated for wgpu, but because we don't vendor them, this should never happen. (also there is no failable version of this function)

I also had to make a RendererError which I totally hate, but the problem here is that without the wgpu-profiler feature this function never fails, so should I remove the Result and just unwrap for the GpuProfiler?

There are still many unwraps, which may(?) still be handled correctly with errors, but for most of them I'm not sure. They are in many functions which had Result return types but still, unwrap was called, so was it intention?

Copy link
Member

@simbleau simbleau left a comment

Choose a reason for hiding this comment

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

I think this needs to be redone with a high-level VelloError, and only have variants which apply to helping a developer. Simply saying "channel was closed" in an error message is only confusing, for example, and doesn't address how this came about or how to fix it, or an event a developer cares about.

src/lib.rs Outdated Show resolved Hide resolved
src/shaders.rs Show resolved Hide resolved
src/util.rs Outdated Show resolved Hide resolved
src/wgpu_engine.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/util.rs Outdated Show resolved Hide resolved
.get_gpu_buf(proxy.id)
.ok_or("buffer for indirect dispatch not in map")?;
let buf = self.bind_map.get_gpu_buf(proxy.id).ok_or(
VelloError::UnavailableBufferUsed(proxy.name, "indirect dispatch"),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I made "indirect dispatch" and "download" strings here. Should I make an enum for those two so it is easier to match on the error?

Copy link
Member

@simbleau simbleau May 19, 2024

Choose a reason for hiding this comment

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

I think it's fine, personally. Unless I hear a reason why a developer would need to differentiate between those cases.

I have a broader question - is there ever a reason we wouldn't find this buffer? Couldn't we just panic here? Theoretically, if our code is sound, would this bind map would always be found?

@DasLixou DasLixou requested a review from simbleau March 10, 2024 10:59
@DasLixou
Copy link
Collaborator Author

I would like to also make the CPU variant non-panic but there's no output of the function saying that it isn't available, just that it's in wrong format.
https://github.com/linebender/vello/blob/main/src/wgpu_engine.rs#L512

src/lib.rs Outdated Show resolved Hide resolved
src/util.rs Outdated Show resolved Hide resolved
src/shaders.rs Show resolved Hide resolved
Copy link
Member

@simbleau simbleau left a comment

Choose a reason for hiding this comment

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

Another preliminary pass. It looks better.

src/lib.rs Outdated
Comment on lines 200 to 204
/// Error when using a buffer inside a recording while it's not available.
/// Check if you have created it and not freed before its last usage.
#[cfg(feature = "wgpu")]
#[error("Buffer '{0}' is not available but used for {1}")]
UnavailableBufferUsed(&'static str, &'static str),
Copy link
Member

Choose a reason for hiding this comment

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

Should this only exist if the profiler feature is active, as the docs suggest?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Where is that written in the docs?

Copy link
Member

@simbleau simbleau Apr 14, 2024

Choose a reason for hiding this comment

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

"/// Error when using a buffer inside a recording"

Aren't the recordings only captured when the wgpu-profiler feature is active? Genuinely not sure, need some guidance.

Copy link
Member

@simbleau simbleau May 19, 2024

Choose a reason for hiding this comment

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

If it was unclear, I'm asking whether or not this should be

#[cfg(all(feature = "wgpu", feature = "wgpu-profiler"))]

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/util.rs Outdated Show resolved Hide resolved
@@ -553,7 +552,7 @@ impl WgpuEngine {
let src_buf = self
.bind_map
.get_gpu_buf(proxy.id)
.ok_or("buffer not in map")?;
.ok_or(VelloError::UnavailableBufferUsed(proxy.name, "download"))?;
Copy link
Member

Choose a reason for hiding this comment

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

This error doesn't feel meaningful... is there a way for the developer to react if this is triggered? I don't think so... this error would only happen if we (as Vello maintainers) aren't handling the buffers correctly. In such case, I'd accept a panic here instead with a safety comment.

Copy link
Member

Choose a reason for hiding this comment

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

This is a question about where our abstraction boundaries lie. Concretely, there are effectively two parts:

  1. The recording abstraction
  2. Connecting that abstraction to the Vello shaders

As seen in #416, the recording can theoretically be used for additional functionality by end-users.
Our current API here is very much research quality, and so. I think it's likely that we'll want to have slightly more fine-grained error types for this in future (i.e. a different error at the recording/higher-level Vello levels), but this is fine for this PR.

@waywardmonkeys
Copy link
Collaborator

@DasLixou How far away from ready is this? Any chance it could be done for Vello 0.2?

@DasLixou
Copy link
Collaborator Author

I would have to look over this, will probably do a rebase, but IIRC nothing really blocked this, only some not-100%-sure decisions

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

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

Sorry for not reviewing this earlier - some initial comments, although I've not done a full review

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@DasLixou
Copy link
Collaborator Author

image
Sometimes merge conflicts are just hilarious 😂 (at least they're easy)

@DasLixou DasLixou force-pushed the better-error-types branch from 9ca0e2e to bcd5ea1 Compare May 13, 2024 14:29
@DasLixou DasLixou requested a review from DJMcNab May 13, 2024 14:36
@DasLixou
Copy link
Collaborator Author

That should be it

@DasLixou
Copy link
Collaborator Author

Also just checked that everything runs fine

@simbleau
Copy link
Member

I have many comments that are unresolved still

Copy link
Member

@DJMcNab DJMcNab left a comment

Choose a reason for hiding this comment

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

Once this is rebased/updated with main we can land this. We aren't committing to any stability guarantees, so I think it's perfectly reasonable to land this as an improvement.

This doesn't really change the API we expect our users to use, as seen in with_winit not needing to be updated.

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@simbleau
Copy link
Member

This doesn't really change the API we expect our users to use, as seen in with_winit not needing to be updated.

That's because the example panics or discards most errors. Currently, that's not giving me the confidence I want yet.

I think approving this is a bit hasty as-is. It's definitely an improvement, but the error types will have a big effect on the crate going forward.

I'd prefer if we were specific with the feature flags on error types, whether VelloError should be non_exhaustive, and (personal opinion) get rid of the specialized Result type we've made, and generally address the comments that are withstanding so there is less uncertainty.

@DasLixou DasLixou force-pushed the better-error-types branch from d2b6479 to 67139bd Compare May 20, 2024 07:48
src/lib.rs Show resolved Hide resolved
@simbleau
Copy link
Member

Agree with Chad's comment above, but glad to see all the improvements in such a short turnaround. Nice work @DasLixou !

Approving

Copy link
Member

@xStrom xStrom left a comment

Choose a reason for hiding this comment

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

We want to get this in for Vello 0.2.

I resolved the merge conflict and addressed Chad's reasonable nit. I will merge this based on existing approvals. Additional changes are welcome as follow-up PRs.

Thank you for all your work @DasLixou.

@xStrom xStrom added this pull request to the merge queue May 30, 2024
Merged via the queue into linebender:main with commit 3842b3d May 30, 2024
16 checks passed
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.

Error handling
7 participants