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

fix: Make data retrieval more resilient. Do not throw on ipfs data problems. #375

Merged
merged 7 commits into from
Jan 16, 2024

Conversation

richtera
Copy link
Collaborator

What kind of change does this PR introduce (bug fix, feature, docs update, ...)?

  • fix: Repair problems with IPFS, fetch and VerifiableURI
  • fix: Repair to not throw errors when data is not authentica or not accessible withing getDataFromExternalSources.

What is the current behaviour (you can also link to an open issue here)?

The current behavior is that when data is invalid or unreachable in ipfs. getDataFromExternalSource will throw an exception.

What is the new behaviour (if this is a feature change)?

These are now converted to a console.error, allowing the data to return as "null". This allows getData to be called with multiple keys
including one that maybe invalid and not just throw out of the section of code.

Other information:

I also made a similar kind of fix when the array length data (i.e. LSP12IssuedAssets[]) contains a uint256 instead of a uint128.

@codecov-commenter
Copy link

codecov-commenter commented Jan 15, 2024

Codecov Report

Attention: 18 lines in your changes are missing coverage. Please review.

Comparison is base (330c604) 83.18% compared to head (1df5d90) 32.98%.

Files Patch % Lines
src/lib/encoder.ts 15.38% 8 Missing and 3 partials ⚠️
src/lib/getDataFromExternalSources.ts 0.00% 6 Missing ⚠️
src/lib/provider-wrapper-utils.ts 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##           develop     #375       +/-   ##
============================================
- Coverage    83.18%   32.98%   -50.20%     
============================================
  Files           19       19               
  Lines         1231     1243       +12     
  Branches       282      286        +4     
============================================
- Hits          1024      410      -614     
- Misses         110      802      +692     
+ Partials        97       31       -66     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

src/index.test.ts Outdated Show resolved Hide resolved
src/lib/encoder.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@CallumGrindle CallumGrindle left a comment

Choose a reason for hiding this comment

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

left some comments. Looks okay to me

@CallumGrindle CallumGrindle requested review from Hugoo and CJ42 January 16, 2024 12:03
@richtera richtera force-pushed the fix/cleanup-ipfs-retrieval branch from d8e80e5 to 2a18f2b Compare January 16, 2024 12:11
@richtera
Copy link
Collaborator Author

Rebased.

@richtera richtera merged commit 5709e2c into develop Jan 16, 2024
2 checks passed
@richtera richtera deleted the fix/cleanup-ipfs-retrieval branch January 16, 2024 13:30
Copy link
Collaborator

@CJ42 CJ42 left a comment

Choose a reason for hiding this comment

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

Added some review comments

if (numberOfBytes > (uintLength as number) / 8) {
throw new Error(
`Can't convert hex value ${value} to ${type}. Too many bytes. ${numberOfBytes} > 16`,
console.error(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is incorrect and this part might need to be refactored. If there is more bytes than number of bits / 8, it should be fine as long as the left most bytes are 00.

If for instance for a uint8, there is more than 1 byte, that's ok as long as the left most byte is 00.

For instance, to decoding 0x00fe as uint8 would be ok, it will decode as 254 ✅
But if you try to decode 0x01fe as uint8, it should not allow you ❌

@@ -782,7 +786,7 @@ export const valueContentEncodingMap = (
},
decode: (value: string) => {
if (typeof value !== 'string' || !isHex(value)) {
console.log(`Value: ${value} is not hex.`);
console.error(`Value: ${value} is not hex.`);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice idea to make it error in the console!

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.

4 participants