Skip to content

Conversation

@srikanth716
Copy link
Contributor

@srikanth716 srikanth716 commented Jan 16, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for data decoding with enhanced fallback mechanisms and logging for better diagnostics.
  • Chores

    • Released version 0.8.0-RC2.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: srikanth716 <srikanthsri7447@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 16, 2026

Walkthrough

The PR bumps the package version to 0.8.0-RC2, introduces a new hexToBytes utility function for converting hex strings to Uint8Array, and refactors the data decoding logic to use this utility while adding fallback error handling for CBOR and JSON parsing failures.

Changes

Cohort / File(s) Summary
Package Configuration
js/package.json
Version bumped from 0.8.0-RC1 to 0.8.0-RC2. New localPublish script added to perform version patching, testing, and local registry publishing.
Utility Enhancement
js/src/utils/cborUtils.js
New hexToBytes(hex) function added to convert hex strings to Uint8Array. Function exported for public use. Minor formatting update to quote style in decodeFromBase64UrlFormat.
Decode Logic Refactoring
js/src/index.js
decodeMappedData method refactored to use new hexToBytes utility instead of Buffer.from(). Error handling enhanced with fallback JSON parsing and additional logging on CBOR decode failures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • mayuradesh
  • swatigoel

Poem

🐰 A hex-to-bytes path, so clean and bright,
With better errors logged just right,
RC2 hops forward, version blessed,
New utilities put to the test!

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly indicates a fix for decoded mapped data conversion, which aligns with the main changes in the changeset involving hexToBytes conversion and improved CBOR/JSON decoding.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

🧹 Recent nitpick comments
js/src/utils/cborUtils.js (1)

10-16: Add input validation to handle edge cases.

The hexToBytes function lacks validation which could lead to silent failures or incorrect behavior:

  1. Odd-length hex strings will silently truncate (e.g., "abc" → 1 byte instead of error)
  2. Invalid hex characters produce NaN which becomes 0 when coerced to Uint8Array
  3. Non-string inputs will throw at hex.length

Also, substr() is deprecated; prefer substring().

♻️ Proposed fix with input validation
 function hexToBytes(hex) {
+  if (typeof hex !== "string") {
+    throw new TypeError("Expected a hex string");
+  }
+  if (hex.length % 2 !== 0) {
+    throw new Error("Hex string must have an even length");
+  }
   const bytes = new Uint8Array(hex.length / 2);
   for (let i = 0; i < hex.length; i += 2) {
-    bytes[i / 2] = parseInt(hex.substr(i, 2), 16);
+    const byte = parseInt(hex.substring(i, i + 2), 16);
+    if (Number.isNaN(byte)) {
+      throw new Error(`Invalid hex character at position ${i}`);
+    }
+    bytes[i / 2] = byte;
   }
   return bytes;
 }
js/src/index.js (1)

150-156: Consider removing the unused decoded variable.

The decoded variable on line 151 is assigned but only immediately passed to translateToJson. It can be inlined for clarity.

♻️ Suggested simplification
   let jsonData;
-  let decoded;
   try {
     const bytes = hexToBytes(data);
-
-    decoded = cbor.decodeFirstSync(bytes);
-    jsonData = translateToJson(decoded);
+    jsonData = translateToJson(cbor.decodeFirstSync(bytes));
   } catch (error) {

📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 550ea61 and c05e2a5.

⛔ Files ignored due to path filters (1)
  • js/package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (3)
  • js/package.json
  • js/src/index.js
  • js/src/utils/cborUtils.js
🧰 Additional context used
🧬 Code graph analysis (2)
js/src/utils/cborUtils.js (1)
js/src/index.js (1)
  • bytes (153-153)
js/src/index.js (1)
js/src/utils/cborUtils.js (1)
  • bytes (11-11)
🔇 Additional comments (5)
js/package.json (2)

3-3: LGTM!

Version bump to 0.8.0-RC2 is appropriate for the functional changes introduced in this PR (new hexToBytes utility and enhanced error handling in decodeMappedData).


12-13: LGTM on the new localPublish script.

The script correctly chains version patch, test, and publish to a local Verdaccio registry (localhost:4873). This is useful for local development and testing.

js/src/utils/cborUtils.js (1)

177-179: LGTM!

The decodeFromBase64UrlFormat function and the module exports are correctly structured.

js/src/index.js (2)

20-26: LGTM!

The import of hexToBytes from the utilities module is correctly structured alongside other CBOR-related utilities.


157-166: Good fallback strategy with appropriate logging.

The CBOR-to-JSON fallback is a sensible resilience pattern. Using console.warn for the initial CBOR failure and console.error for the final JSON failure provides appropriate logging levels.

One minor note: ensure calling code understands that this function may accept either hex-encoded CBOR or raw JSON strings, as the fallback behavior changes the contract.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@mayuradesh mayuradesh merged commit bf134da into inji:develop Jan 16, 2026
5 checks passed
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