Skip to content

Fix: handle undefined binding.size to prevent NaN -fixes #262 - #266

Open
shriya-gatate wants to merge 3 commits into
dbpedia:masterfrom
shriya-gatate:fix/issue-262
Open

Fix: handle undefined binding.size to prevent NaN -fixes #262#266
shriya-gatate wants to merge 3 commits into
dbpedia:masterfrom
shriya-gatate:fix/issue-262

Conversation

@shriya-gatate

@shriya-gatate shriya-gatate commented Jun 28, 2026

Copy link
Copy Markdown

##Problem
When binding.size is undefined, totalSize becomes NaN, showing wrong file count and size in the UI.

##Fix
Added a null check to default to 0 if binding.size is undefined.

Fixes #262

Summary by CodeRabbit

  • Bug Fixes
    • Fixed file browser total size calculations to handle SPARQL results that may not include size data.
    • Missing size values now safely default to zero, preventing totals from failing or accumulating incorrect values.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

querySparql now tolerates missing size bindings when calculating total size, and the versions SPARQL query separates its closing brace from the ordering clause.

Changes

File Browser Size Handling and SPARQL Formatting

Layer / File(s) Summary
SPARQL query clause formatting
server/app/common/queries/sparql/get-versions-by-account.sparql
Separates the query’s closing brace from ORDER BY DESC(?version).
Conditional file-size aggregation
public/js/components/file-browser/file-browser.js
Parses binding.size.value when present and uses 0 when absent during ctrl.totalSize accumulation.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main fix: guarding undefined binding.size to avoid NaN and wrong totals.
Linked Issues check ✅ Passed The change set addresses #262 by null-safe size handling and sorting versions to support correct latest-version selection.
Out of Scope Changes check ✅ Passed The SPARQL ORDER BY tweak supports the linked latest-version selection issue and is not unrelated scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@public/js/components/file-browser/file-browser.js`:
- Line 145: The null fallback in file-browser.js only protects the totalSize
addition, but binding.size is still dereferenced earlier in the same flow.
Update the size parsing logic in the file-browser binding handling so the
null/undefined check happens before accessing binding.size.value or
binding.size.numericalValue, store the parsed size once, and reuse that parsed
value when updating ctrl.totalSize.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c2e1f91e-596d-4286-aa9b-8dd99213f55b

📥 Commits

Reviewing files that changed from the base of the PR and between 2c775e7 and 0d00b8e.

📒 Files selected for processing (1)
  • public/js/components/file-browser/file-browser.js

Comment thread public/js/components/file-browser/file-browser.js Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
public/js/components/file-browser/file-browser.js (1)

135-135: 🩺 Stability & Availability | 🔴 Critical | ⚡ Quick win

Guard still doesn't prevent the crash on missing binding.size.

The ternary at Line 135 only decides the value assigned; the assignment target binding.size.numericalValue = ... still unconditionally dereferences binding.size. When binding.size is undefined, this throws TypeError: Cannot set properties of undefined, which is swallowed by the catch block in querySparql, aborting the loop before Line 145's fallback ever runs. This is the same root cause raised in the previous review round — the fix needs to guard the property write itself, not just the computed value.

🐛 Proposed fix
       for (var b in ctrl.queryResult.bindings) {
         var binding = ctrl.queryResult.bindings[b];
-        binding.size.numericalValue = binding.size? parseInt(binding.size.value):0;
+        var numericalSize = binding.size ? parseInt(binding.size.value, 10) : 0;
+        if (binding.size) {
+          binding.size.numericalValue = numericalSize;
+        }
         ctrl.queryResult.uriList += binding.file.value + "\n";

         if (binding.variant != undefined) {
           binding.variant.value = ctrl.formatVariant(binding.variant.value);
         }

-        ctrl.totalSize += binding.size?binding.size.numericalValue:0;
+        ctrl.totalSize += numericalSize;
         ctrl.numFiles++;
       }

Also applies to: 145-145

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@public/js/components/file-browser/file-browser.js` at line 135, The
`querySparql` loop in `file-browser.js` still crashes when `binding.size` is
missing because the assignment to `binding.size.numericalValue` dereferences
`binding.size` before the ternary runs. Update the size-handling logic around
`binding.size` so the property write itself is guarded, and only set
`numericalValue` when `binding.size` exists; otherwise leave it untouched so the
fallback path later in the same loop can execute.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Duplicate comments:
In `@public/js/components/file-browser/file-browser.js`:
- Line 135: The `querySparql` loop in `file-browser.js` still crashes when
`binding.size` is missing because the assignment to
`binding.size.numericalValue` dereferences `binding.size` before the ternary
runs. Update the size-handling logic around `binding.size` so the property write
itself is guarded, and only set `numericalValue` when `binding.size` exists;
otherwise leave it untouched so the fallback path later in the same loop can
execute.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 48877964-861b-4b22-a023-e85709757658

📥 Commits

Reviewing files that changed from the base of the PR and between 0d00b8e and d606ef1.

📒 Files selected for processing (1)
  • public/js/components/file-browser/file-browser.js

@shriya-gatate shriya-gatate left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Addressed CodeRabbit's feedback — moved the null check to a local variable
(sizeValue) to avoid dereferencing binding.size before the guard runs.
Line 145 now reuses sizeValue directly.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
public/js/components/file-browser/file-browser.js (1)

135-145: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Preserve binding.size.numericalValue for the UI.

This removes the assignment that populates binding.size.numericalValue, but public/js/components/file-browser/file-browser.html still renders and sorts by that property. Keep the local fallback for aggregation and assign the parsed value when binding.size exists.

Suggested fix
-        const sizeValue = binding.size? parseInt(binding.size.value):0;
+        const sizeValue = binding.size ? parseInt(binding.size.value, 10) : 0;
+        if (binding.size) {
+          binding.size.numericalValue = sizeValue;
+        }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@public/js/components/file-browser/file-browser.js` around lines 135 - 145,
Restore assignment of the parsed size to binding.size.numericalValue in the
file-browser result processing flow, while retaining sizeValue’s fallback of 0
for total aggregation. Guard the assignment so it only runs when binding.size
exists, preserving the UI rendering and sorting contract.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@public/js/components/file-browser/file-browser.js`:
- Around line 135-145: Restore assignment of the parsed size to
binding.size.numericalValue in the file-browser result processing flow, while
retaining sizeValue’s fallback of 0 for total aggregation. Guard the assignment
so it only runs when binding.size exists, preserving the UI rendering and
sorting contract.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9c3a5231-ecab-452c-960b-aa6eedaec736

📥 Commits

Reviewing files that changed from the base of the PR and between d606ef1 and f1ed90d.

📒 Files selected for processing (2)
  • public/js/components/file-browser/file-browser.js
  • server/app/common/queries/sparql/get-versions-by-account.sparql

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.

invalid total size and number of files calculation in the UI

1 participant