-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat: access-api handling store/info for space not in db returns failure with name #391
Conversation
error: true, | ||
status: 404, | ||
message: 'Space not found.', | ||
} |
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 probably should start a error.js file like this https://github.com/web3-storage/ucanto/blob/main/packages/validator/src/error.js and a error.ts for error types in the client
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 gonna return a http 200 so i dont think we need the status in there, just a normal SpaceNotFound extends Failure
with name
and message
props.
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 gonna return a http 200
this service could be invoked via non-http transport
The status is in there as a reliable machine-readable indication of what kind of error happened. I don't think we should use just a specific 'message' value as the only discriminant of this error case because doing that would make it so that changing the error message string would be a backward-incompatible change from the perspective of any client trying to detect this error case. I'm intentionally trying to add a specific non-message
error code that clients can use to detect this case.
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.
exactly, non-http transport should not need to understand http codes. For errors IMO either use the name as the identifier or a code nodejs style error.code = ERR_SPACE_NOT_FOUND
// similar to ucanto
if(error.name === 'SpaceNotFound'){}
// similar to nodejs
class SpaceNotFoundError{}
SpaceNotFoundError.code = 'ERR_SPACE_NOT_FOUND'
if(error.code === SpaceNotFoundError.code) {}
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.
@hugomrdias Thanks, when I first responded I missed that you were encouraging a name
and thought you were just saying to cut status
which would make it the same as generic Failure
. my bad
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 updated [here] to not have a status
at all and just a well-defined name
8f0e5e3#diff-f4e938a2d743868395a4bb96adeecd10ce306ac53100e1e978df8d40ac33d4ef
packages/access-client/src/types.ts
Outdated
export type SpaceNotFoundFailure = Failure & { | ||
status: 404 | ||
} | ||
|
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.
maybe create a new errors.ts file exported from types.ts with something like https://github.com/web3-storage/ucanto/blob/main/packages/interface/src/capability.ts#L413-L416
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 moved the failure type to an errors.ts
file as you suggested 8f0e5e3#diff-f4e938a2d743868395a4bb96adeecd10ce306ac53100e1e978df8d40ac33d4ef
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.
Provided feedback. I don't think you need another review from me.
packages/access-client/src/types.ts
Outdated
* Indicates failure executing ability that requires access to a space that cannot be found by the handler | ||
*/ | ||
export type SpaceNotFoundFailure = Failure & { | ||
status: 404 |
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.
status: 404 | |
name: 'UnknownSpaceDID` |
I would say ☝️, which is I think more accurate than not found. If we want to be future compatible I would go as far as do this instead.
status: 404 | |
name: 'NoStorageProvider' |
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.
For what it's worth I don't mind status
along with the name
to categorize concrete errors into a groups with HTTP semantics, I just think it's not replacement for concrete errors.
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 got rid of status
and used name
of UnknownSpace
in 8f0e5e3#diff-f4e938a2d743868395a4bb96adeecd10ce306ac53100e1e978df8d40ac33d4ef
return { | ||
error: true, | ||
status: 404, | ||
message: 'Space not found.', |
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.
message: 'Space not found.', | |
message: 'Space ${capability.with} has not storage provider. Storage provider can be added by invoking "voucher/claim" capability', |
I would for something more descriptive with an actionable feedback
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 agree it would be good to have actionable feedback in the error message. I defer to @hugomrdias on whether this is the best advice to give, as changing the message here would also require a change the tested behavior, and would prefer to have that change be in separate PR if needed.
also relevant: storacha/specs#18 |
… instead of status integer
8f0e5e3
to
dd82bbf
Compare
I updated the change here based on review of @hugomrdias and @Gozala . Now the union tag to detect this failure type is |
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.
LGTM, left a comment inline but not blocking
packages/access-client/src/errors.ts
Outdated
* e.g. it's a space that's never been seen before, | ||
* or it's a seen space that hasn't been fully registered such that the service can serve info about the space. | ||
*/ | ||
export interface SpaceUnknown { |
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 probably should extends Failure
here same as other errors in ucanto
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 had omitted it on purpose so that the canonical service types didn't need to depend on ucanto (and we'd just rely on tsc
checking the structural types), but don't have strong opinions on it either way, so I added the extends
clause 0b63c2e .
🤖 I have created a release *beep* *boop* --- ## [4.9.0](access-api-v4.8.0...access-api-v4.9.0) (2023-01-30) ### Features * access-api handling store/info for space not in db returns failure with name ([#391](#391)) ([9610fcf](9610fcf)) * update @ucanto/* to ~4.2.3 ([#405](#405)) ([50c0c80](50c0c80)) * update access-api ucanto proxy to not need a signer ([#390](#390)) ([71cbeb7](71cbeb7)) ### Bug Fixes * make tests use did:web everywhere ([#397](#397)) ([c7d5c34](c7d5c34)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release *beep* *boop* --- ## [9.3.0](access-v9.2.0...access-v9.3.0) (2023-01-30) ### Features * access-api forwards store/ and upload/ invocations to upload-api ([#334](#334)) ([b773376](b773376)) * access-api handling store/info for space not in db returns failure with name ([#391](#391)) ([9610fcf](9610fcf)) * update @ucanto/* to ~4.2.3 ([#405](#405)) ([50c0c80](50c0c80)) * update access-api ucanto proxy to not need a signer ([#390](#390)) ([71cbeb7](71cbeb7)) ### Bug Fixes * remove unecessary awaits ([#352](#352)) ([64da6e5](64da6e5)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
…ure with name (#391) Motivation: * implement #382 * tl;dr `space/info` now has explicit failure type for case where the ucans are valid, but the space DID is not in the db. that way when upload-api invokes `space/info` as part of its `verifyInvocation` logic, it can distinguish between an invalid invocation and a not-found space id Unblocks: * this test passing gobengo/w3protocol-test#1 * rest of storacha/w3infra#134 (comment)
🤖 I have created a release *beep* *boop* --- ## [4.9.0](access-api-v4.8.0...access-api-v4.9.0) (2023-01-30) ### Features * access-api handling store/info for space not in db returns failure with name ([#391](#391)) ([665dac9](665dac9)) * update @ucanto/* to ~4.2.3 ([#405](#405)) ([ec39443](ec39443)) * update access-api ucanto proxy to not need a signer ([#390](#390)) ([163fb74](163fb74)) ### Bug Fixes * make tests use did:web everywhere ([#397](#397)) ([00be288](00be288)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release *beep* *boop* --- ## [9.3.0](access-v9.2.0...access-v9.3.0) (2023-01-30) ### Features * access-api forwards store/ and upload/ invocations to upload-api ([#334](#334)) ([6be7217](6be7217)) * access-api handling store/info for space not in db returns failure with name ([#391](#391)) ([665dac9](665dac9)) * update @ucanto/* to ~4.2.3 ([#405](#405)) ([ec39443](ec39443)) * update access-api ucanto proxy to not need a signer ([#390](#390)) ([163fb74](163fb74)) ### Bug Fixes * remove unecessary awaits ([#352](#352)) ([2e8c1a1](2e8c1a1)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Motivation:
space/info
invocations for space dids not in its db with a well-defined error result type #382space/info
now has explicit failure type for case where the ucans are valid, but the space DID is not in the db. that way when upload-api invokesspace/info
as part of itsverifyInvocation
logic, it can distinguish between an invalid invocation and a not-found space idUnblocks: