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

error invoking store/list through access-api (proxying to upload-api) #359

Closed
Tracked by #325
gobengo opened this issue Jan 18, 2023 · 5 comments
Closed
Tracked by #325

Comments

@gobengo
Copy link
Contributor

gobengo commented Jan 18, 2023

Motivation:

When trying to invoke access-api staging with a can: "store/list" invocation, I see this error from the upstream upload-api

# testing aud=did:web:staging.web3.storage url=https://w3access-staging.protocol-labs.workers.dev/
    # unexpected result from store/list invocation {
    #   name: 'HandlerExecutionError',
    #   cause: {
    #     name: 'TypeError',
    #     stack: 'TypeError: Illegal invocation\\n' +
    #       '    at dN.request (d1-beta-facade.entry.js:14579:24)\\n' +
    #       '    at WN (d1-beta-facade.entry.js:15030:61)\\n' +
    #       '    at async Object.<anonymous> (d1-beta-facade.entry.js:15037:132)\\n' +
    #       '    at async IB (d1-beta-facade.entry.js:14077:12)\\n' +
    #       '    at async AB (d1-beta-facade.entry.js:14065:12)\\n' +
    #       '    at async TB (d1-beta-facade.entry.js:14059:42)\\n' +
    #       '    at async PO (d1-beta-facade.entry.js:15097:11)\\n' +
    #       '    at async ed.fetch (d1-beta-facade.entry.js:9434:17)\\n' +
    #       '    at async Object.fetch (d1-beta-facade.entry.js:20183:13)',
    #     message: 'Illegal invocation'
    #   },
    #   error: true,
    #   stack: 'HandlerExecutionError: service handler {can: "store/list"} error: Illegal invocation\\n' +
    #     '    at IB (d1-beta-facade.entry.js:14079:13)\\n' +
    #     '    at async AB (d1-beta-facade.entry.js:14065:12)\\n' +
    #     '    at async TB (d1-beta-facade.entry.js:14059:42)\\n' +
    #     '    at async PO (d1-beta-facade.entry.js:15097:11)\\n' +
    #     '    at async ed.fetch (d1-beta-facade.entry.js:9434:17)\\n' +
    #     '    at async Object.fetch (d1-beta-facade.entry.js:20183:13)',
    #   message: 'service handler {can: "store/list"} error: Illegal invocation',
    #   capability: {
    #     can: 'store/list',
    #     with: 'did:key:z6Mkm46voCRFK8cxifj98D4mSdP1d6xwWWCtMKsB3YcUGt8c'
    #   }
    # }
@gobengo
Copy link
Contributor Author

gobengo commented Jan 18, 2023

It would be a little helpful if upload-api stack traces used source maps. (update: not fully because this stack trace is from access-api not upload-api🤦 , though in other debugging I get upload-api error stacks so it would still be useful)

@gobengo
Copy link
Contributor Author

gobengo commented Jan 18, 2023

I added a unit test for the ucanto proxy that attempts a reduced test case for what I think is happening when the OP error happens, specifically:

  • uses same store/list capability definition as upload-api
  • uses http ucanto transport in connections

https://github.com/web3-storage/w3protocol/pull/360/files#diff-9a0b1851ef99b18fa05356dae74d7db158f89ac19e6e243038dda890fbb0783eR237

Unfortunately I can't reproduce this error. Going to sleep on it

I'm wondering if there's any chance that this line converting the lambda event body from base64 could be a culprit? https://github.com/web3-storage/w3infra/blob/main/upload-api/functions/ucan-invocation-router.js#L90

@gobengo
Copy link
Contributor Author

gobengo commented Jan 18, 2023

thinking it's more likely that somewhere in access-api is calling globalThis.fetch with some other this than globalThis

@gobengo
Copy link
Contributor Author

gobengo commented Jan 18, 2023

The TypeError: Illegal invocation seems like it could be caused by cloudflare's globalThis.fetch being called without this bound to globalThis. https://stackoverflow.com/questions/44720448/fetch-typeerror-failed-to-execute-fetch-on-window-illegal-invocation

gobengo added a commit that referenced this issue Jan 18, 2023
Motivation:
* attempt to fix according to this theory
#359 (comment)
gobengo added a commit to storacha/w3infra that referenced this issue Jan 18, 2023
Motivation:
* I invoked upload-api and [got an error
response](storacha/w3up#359 (comment)).
The error response had a stack trace, but the stack trace doesn't seem
to be source-maps-aware in either our sentry logigng nor the stack trace
included in the http response
* attempt to configure the stack in a way that we get source-map-aware
stack traces
  * in sentry - most important
  * in the stack traces included in the http response - nice to have

Rationale
* in [these sst docs for source
maps](https://docs.sst.dev/advanced/source-maps), it says we might need
this `bundle.sourcemap === true`
@gobengo
Copy link
Contributor Author

gobengo commented Jan 18, 2023

That resolved the issue when invoking can=store/list aud=did:web:staging.web3.storage through url=https://w3access-staging.protocol-labs.workers.dev/version
https://github.com/gobengo/monorepo/actions/runs/3952405802/jobs/6767435499#step:6:20

@gobengo gobengo closed this as completed Jan 18, 2023
gobengo added a commit that referenced this issue Apr 11, 2023
Motivation:
* attempt to fix according to this theory
#359 (comment)
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

No branches or pull requests

1 participant