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(codec): molecule friendly error message #403

Merged
merged 9 commits into from
Sep 14, 2022

Conversation

IronLu233
Copy link
Contributor

@IronLu233 IronLu233 commented Sep 5, 2022

@vercel
Copy link

vercel bot commented Sep 5, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
lumos-website ✅ Ready (Inspect) Visit Preview Sep 14, 2022 at 9:59AM (UTC)

@codecov
Copy link

codecov bot commented Sep 5, 2022

Codecov Report

Merging #403 (5d1cbe0) into develop (cc69d90) will increase coverage by 0.14%.
The diff coverage is 98.50%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #403      +/-   ##
===========================================
+ Coverage    81.98%   82.13%   +0.14%     
===========================================
  Files           93       94       +1     
  Lines        19105    19269     +164     
  Branches      1794     1820      +26     
===========================================
+ Hits         15664    15826     +162     
- Misses        3400     3401       +1     
- Partials        41       42       +1     
Impacted Files Coverage Δ
packages/codec/src/error.ts 94.64% <94.64%> (ø)
packages/codec/src/high-order/nested.ts 99.17% <100.00%> (-0.83%) ⬇️
packages/codec/src/molecule/layout.ts 99.74% <100.00%> (+0.65%) ⬆️
packages/codec/src/number/uint.ts 99.23% <100.00%> (+0.10%) ⬆️
packages/codec/src/utils.ts 96.07% <100.00%> (+1.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cc69d90...5d1cbe0. Read the comment docs.

@IronLu233 IronLu233 changed the title feat(codec): codec human readable error feat(codec): molecule friendly error message Sep 6, 2022
@PainterPuppets
Copy link
Contributor

PainterPuppets commented Sep 6, 2022

Can you add description and purpose about this pull request?

Copy link
Contributor

@PainterPuppets PainterPuppets left a comment

Choose a reason for hiding this comment

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

I'm wondering if it's possible to use the higher-order function to do non-intrusive modifications instead of directly changing the codec?

maybe example like that

withReadableError(array)(xxxx)

@IronLu233
Copy link
Contributor Author

I'm wondering if it's possible to use the higher-order function to do non-intrusive modifications instead of directly changing the codec?

maybe example like that

withReadableError(array)(xxxx)

It is difficult.

We want track the property access path in codec pack input, but these key only appears in Array.prototype.map/reduce
methods.

When code run out of these high order function, we can not get the current key anymore. so I think we have to modify some code in codec pack logic.

@IronLu233 IronLu233 requested review from PainterPuppets and zhangyouxin and removed request for PainterPuppets September 6, 2022 07:19
@homura
Copy link
Collaborator

homura commented Sep 9, 2022

When code run out of these high order function, we can not get the current key anymore. so I think we have to modify some code in codec pack logic.

vote for this. but i want to know it is possible to refactor createObjectCodec and createArrayCodec to provide the friendly message? because it's not just molecule that can be affected by nested error. for struct/table/array/vector will call the createObject|ArrayCodec to report the friendly message

@IronLu233
Copy link
Contributor Author

When code run out of these high order function, we can not get the current key anymore. so I think we have to modify some code in codec pack logic.

vote for this. but i want to know it is possible to refactor createObjectCodec and createArrayCodec to provide the friendly message? because it's not just molecule that can be affected by nested error. for struct/table/array/vector will call the createObject|ArrayCodec to report the friendly message

Maybe ES6 proxy class can implement this feature.

@homura
Copy link
Collaborator

homura commented Sep 12, 2022

Maybe ES6 proxy class can implement this feature.

it can be simpler

function struct(shape, fields) {
  const codec = createObjectCodec(...)

  return {
    pack(packable) {
      const packedFields = fields.map(field => codec[field].pack(packable[item]))
      return concat(...packedFields) 
    }
    unpack() {
      // ...
    }
  }
}

@IronLu233
Copy link
Contributor Author

Maybe ES6 proxy class can implement this feature.

it can be simpler

function struct(shape, fields) {
  const codec = createObjectCodec(...)

  return {
    pack(packable) {
      const packedFields = fields.map(field => codec[field].pack(packable[item]))
      return concat(...packedFields) 
    }
    unpack() {
      // ...
    }
  }
}

I found a way to track layout struct(array, table) error without modify it's codec implementations.

This can be in another PR in #408

packages/codec/src/error.ts Outdated Show resolved Hide resolved
packages/codec/src/error.ts Outdated Show resolved Hide resolved
packages/codec/src/error.ts Outdated Show resolved Hide resolved
IronLu233 and others added 2 commits September 14, 2022 14:48
Co-authored-by: Yonghui Lin <homura.dev@gmail.com>
Co-authored-by: Yonghui Lin <homura.dev@gmail.com>
@IronLu233
Copy link
Contributor Author

Seems everything is OK. Can you please help review again? @homura

@homura homura merged commit 08b7f8d into ckb-js:develop Sep 14, 2022
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.

[feature request] validator for codec when packing the object
4 participants