fix(web): guard undefined hash in commit detail view - #7148
Conversation
When hash is undefined (e.g. from older Piped v0 messages where the field was unpopulated), hash.slice(0, 7) throws: TypeError: Cannot read properties of undefined (reading 'slice') Add null-coalescing fallback to empty string before slicing. Related: pipe-cd#6706 Signed-off-by: vikash7485 <vikkiraj073@gmail.com>
9fc67c1 to
818473d
Compare
rahulshendre
left a comment
There was a problem hiding this comment.
LGMT, thanks @vikash7485
one thing I am curious about - commit.hash is typed string from the protobuf (proto3 defaults an unset string to "", not undefined), so I couldn't see where it'd actually be undefined.
If you saw it, please let use know where, mostly so we know if message/url next to it need the same
|
@rahulshendre Thanks for the review and approval The reason In standard protobuf generated classes, proto3 does default strings to |
✅ Deploy Preview for pipecd-site canceled.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7148 +/- ##
==========================================
- Coverage 29.68% 29.01% -0.68%
==========================================
Files 601 532 -69
Lines 64383 58157 -6226
==========================================
- Hits 19113 16873 -2240
+ Misses 43779 39919 -3860
+ Partials 1491 1365 -126
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What this PR does:
Guard against
undefinedhash in the deployment detail commit section by adding a null-coalescing fallback (?? "") before calling.slice(0, 7).Why we need it:
When
deployment.trigger.commit.hashisundefined(possible from older Piped v0 protobuf messages where the field was unpopulated), the current code calls.slice(0, 7)directly onundefined, causing a runtime crash:The outer guard at L254 (
deployment.trigger?.commit &&) only checks thatcommitexists, not thathashis populated. This fix adds a safe fallback so the link renders with an empty string instead of crashing.Which issue(s) this PR fixes:
Fixes #
Does this PR introduce a user-facing change?:
No. This prevents a crash for an edge case. Users with valid commit hashes see no difference.