Skip to content

[WasmFS] Allow backends to report errors on setSize#17768

Merged
tlively merged 2 commits intomainfrom
wasmfs-setsize-errors
Sep 1, 2022
Merged

[WasmFS] Allow backends to report errors on setSize#17768
tlively merged 2 commits intomainfrom
wasmfs-setsize-errors

Conversation

@tlively
Copy link
Member

@tlively tlively commented Aug 31, 2022

Add a test that exercises the set_size_file path in the OPFS backend since it
should not be possible to get an error on the set_size_access
codepath. (Although I wouldn't be surprised if it is possible in a way I haven't
thought of.) Also, as a drive-by, fix an error code in doTruncate to be
properly negative.

Add a test that exercises the `set_size_file` path in the OPFS backend since it
should not be possible to get an error on the `set_size_access`
codepath. (Although I wouldn't be surprised if it is possible in a way I haven't
thought of.) Also, as a drive-by, fix an error code in `doTruncate` to be
properly negative.
@tlively tlively requested a review from kripken August 31, 2022 20:24

_wasmfs_opfs_set_size_access__deps: ['$wasmfsOPFSAccessHandles'],
_wasmfs_opfs_set_size_access: async function(ctx, accessID, size) {
_wasmfs_opfs_set_size_access: async function(ctx, accessID, size, errPtr) {
Copy link
Member

Choose a reason for hiding this comment

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

In a PR I am writing I used a return value for the error, using the standard 0 for success and error otherwise. Is there a reason not to do it that way?

Copy link
Member Author

Choose a reason for hiding this comment

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

Since this function is async, it actually returns a promise and you would have to be able to await that promise to get the return value you intended.

Copy link
Member

Choose a reason for hiding this comment

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

An async function can return a non-promise value too (it's ok to await 42). So I think we could do it that way too?

Copy link
Member

Choose a reason for hiding this comment

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

Well, maybe it's simpler this way, I don't feel strongly.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, but only if it returns before it does its first await, since await requires suspending the computation and returning to the event loop.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh right. But main does an await foo(1). I'm pretty sure that foo(1) is returning a promise...

Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure what it does internally, good question. But we can just write return 42; in an async function, and it just works. So we could do this another way, I think, but as above it's probably less simple (so lgtm as is).

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, even without the internal awaits this returns a promise.

Welcome to Node.js v18.6.0.
Type ".help" for more information.
> async function foo() { return 42; }
undefined
> foo()
Promise {
  42,
  [Symbol(async_id_symbol)]: 246,
  [Symbol(trigger_async_id_symbol)]: 5
}

Copy link
Member

Choose a reason for hiding this comment

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

Ah, ok, I guess that internally then an async function returning 42 turns that 42 into a resolved Promise of 42...

Copy link
Member Author

Choose a reason for hiding this comment

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

And IIUC, awaiting still requires a return to the microtask queue even the value is immediately available, so there's really no way around returning via a pointer here.

Copy link
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

lgtm % questions

return -EACCES;
}
} else {
if (!child->is<DataFile>()) {
Copy link
Member

Choose a reason for hiding this comment

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

Should there be a TODO here for symlinks?

Copy link
Member Author

Choose a reason for hiding this comment

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

No, because symlinks are resolved during path parsing. It's not possible for us to observe a symlink here. We already have an assertion for this on line 469.

Copy link
Member

Choose a reason for hiding this comment

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

Got it, thanks!

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