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

feat: w3 usage report catches/warns about errors invoking usage/report #169

Merged
merged 3 commits into from
Jan 24, 2024

Conversation

@gobengo
Copy link
Contributor Author

gobengo commented Jan 24, 2024

When it encounters these errors, it still shows them on stderr (rationale: they're ugly, but rare, so showing them shouldn't affect anyone that isn't already getting a full blowup, but hiding the stack traces would make debugging them a bit harder)

Sample runs in my weird state

redirect stderr to /dev/null and see output like before.

w3cli on  issues/168 [$] is 📦 6.0.0 via ⬢ v20.11.0 took 31.7s 
⚡ 2>/dev/null w3 usage report 
 Account: did:mailto:dag.house:bengo
Provider: did:web:nft.storage
   Space: did:key:z6MktxMvmk3ii638jWcuqzUP3o2A4x2cFnqh9PVKzsaofN1c
    Size: 0

 Account: did:mailto:dag.house:bengo
Provider: did:web:nft.storage
   Space: did:key:z6Mkp5SqdMbRvDQneB4YvwkodATwuhdQAwoFNU9vsJMbetpq
    Size: 0

 Account: did:mailto:dag.house:bengo
Provider: did:web:web3.storage
   Space: did:key:z6Mkr66sQHvPgzMtF7t6GCFr1nk5mZR9F2xZrvb38pNaUycY
    Size: 0

^C

stdout is still JSON so can be piped. But errors will still show on stderr.

⚡ w3 usage report --json | jq .
error getting usage report. Catching and moving on, but will include in warning at end. {
  error: Error: failed usage/report invocation
      at UsageClient.report (file:///Users/bengo/web3-storage/w3cli/node_modules/@web3-storage/w3up-client/src/capability/usage.js:36:13)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async getSpaceUsageReports (file:///Users/bengo/web3-storage/w3cli/index.js:586:20)
      at async usageReport (file:///Users/bengo/web3-storage/w3cli/index.js:524:20) {
    [cause]: {
      name: 'Unauthorized',
      stack: 'Unauthorized: Claim {"can":"usage/report"} is not authorized\n' +
        '  - Capability {"can":"usage/report","with":"did:key:z6MkqCMroF8KPCVgEvTBcvKgq4fopxdhAfr96aJzwp9Wsg2r","nb":{"period":{"from":1701388800,"to":1706119893}}} is not authorized because:\n' +
        "    - Capability can not be (self) issued by 'did:key:z6MkfbsERaJ7rtJQWMWtYMxNED56bhQMgrNu8CRdUjB5LfRp'\n" +
        '    - Delegated capability not found\n' +
        '    at claim (/node_modules/@ucanto/validator/src/lib.js:308:12)\n' +
        '    at processTicksAndRejections (node:internal/process/task_queues:96:5)\n' +
        '    at Object.report (/node_modules/@ucanto/server/src/handler.js:61:27)\n' +
        '    at invoke2 (/node_modules/@ucanto/server/src/server.js:145:23)\n' +
        '    at async Promise.all (index 0)\n' +
        '    at execute (/node_modules/@ucanto/server/src/server.js:104:5)\n' +
        '    at ucanInvocationRouter (/upload-api/functions/ucan-invocation-router.js:260:20)\n' +
        '    at Runtime.handler (/node_modules/src/awslambda.ts:332:1)',
      message: 'Claim {"can":"usage/report"} is not authorized\n' +
        '  - Capability {"can":"usage/report","with":"did:key:z6MkqCMroF8KPCVgEvTBcvKgq4fopxdhAfr96aJzwp9Wsg2r","nb":{"period":{"from":1701388800,"to":1706119893}}} is not authorized because:\n' +
        "    - Capability can not be (self) issued by 'did:key:z6MkfbsERaJ7rtJQWMWtYMxNED56bhQMgrNu8CRdUjB5LfRp'\n" +
        '    - Delegated capability not found'
    }
  },
  space: 'did:key:z6MkqCMroF8KPCVgEvTBcvKgq4fopxdhAfr96aJzwp9Wsg2r',
  period: { from: 2023-12-01T00:00:00.000Z, to: 2024-01-24T18:11:33.553Z },
  consumers: [ 'did:key:z6MkqCMroF8KPCVgEvTBcvKgq4fopxdhAfr96aJzwp9Wsg2r' ],
  account: 'did:mailto:dag.house:bengo'
}
{
  "account": "did:mailto:dag.house:bengo",
  "provider": "did:web:nft.storage",
  "reportedAt": "2024-01-24T18:11:33.553Z",
  "size": {
    "final": 0,
    "initial": 0
  },
  "space": "did:key:z6MktxMvmk3ii638jWcuqzUP3o2A4x2cFnqh9PVKzsaofN1c"
}

non json output warns about errors at the end

   # ...
   Total: 40941887280

   WARNING: there were 30 errors getting usage reports for some spaces.
   This may happen if your agent does not have usage/report authorization for a space.
   These spaces were not included in the usage report total:
   * space: did:key:z6MkkzxLtWpqXQPPXLEjD2M2gWJZikcpCbdk4HBf7tj7K59j
     error: failed usage/report invocation
     account: did:mailto:dag.house:bengo
   * space: did:key:z6Mkvbww5VWYaeGqASXPkz7hAvFk1igodxiyrKTctk1UvNyE
     error: failed usage/report invocation
     account: did:mailto:dag.house:bengo
   * space: did:key:z6Mked63DNosi2NX6HdQ8xmos2S4D8cT9oJuBRu4gymFrVm7
     error: failed usage/report invocation
     account: did:mailto:dag.house:bengo
   

@gobengo gobengo requested a review from alanshaw January 24, 2024 18:21
index.js Outdated Show resolved Hide resolved
Co-authored-by: Alan Shaw <[email protected]>
@gobengo gobengo merged commit e47159e into main Jan 24, 2024
1 check passed
@gobengo gobengo deleted the issues/168 branch January 24, 2024 20:29
gobengo pushed a commit that referenced this pull request Jan 24, 2024
🤖 I have created a release *beep* *boop*
---


##
[7.4.0](v7.3.0...v7.4.0)
(2024-01-24)


### Features

* w3 usage report catches/warns about errors invoking usage/report
([#169](#169))
([e47159e](e47159e))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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