-
Notifications
You must be signed in to change notification settings - Fork 142
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
Better error types #516
Conversation
There was a problem hiding this 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/wgpu_engine.rs
Outdated
.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"), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
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. |
There was a problem hiding this 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
/// 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), |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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/wgpu_engine.rs
Outdated
@@ -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"))?; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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:
- The recording abstraction
- 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.
@DasLixou How far away from ready is this? Any chance it could be done for Vello 0.2? |
I would have to look over this, will probably do a rebase, but IIRC nothing really blocked this, only some not-100%-sure decisions |
There was a problem hiding this 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
9ca0e2e
to
bcd5ea1
Compare
That should be it |
Also just checked that everything runs fine |
I have many comments that are unresolved still |
There was a problem hiding this 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.
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 |
d2b6479
to
67139bd
Compare
Agree with Chad's comment above, but glad to see all the improvements in such a short turnaround. Nice work @DasLixou ! Approving |
There was a problem hiding this 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.
Using custom
thiserror
errors instead ofBox<dyn Error>
, closes #285This removed the use of
Result
as a return type for many functions, includingRenderContext::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 thewgpu-profiler
feature this function never fails, so should I remove theResult
and just unwrap for theGpuProfiler
?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?