fix: prevent TypeError when updating relationship attribute#2953
fix: prevent TypeError when updating relationship attribute#2953jaydeep-pipaliya wants to merge 1 commit intoappwrite:mainfrom
Conversation
The edit dialog crashed with an uncaught TypeError when clicking "Update" on a relationship attribute because the reactive title statement accessed option.name without checking if option was defined. The submit function also called option.update() without a null guard. Add null checks for option in both the title derivation and the submit function to prevent the crash and show a proper error message. Fix appwrite/appwrite#9951
Greptile SummaryThis PR adds targeted null guards to
Confidence Score: 5/5Safe to merge — targeted two-line fix with no new logic paths, only P2 style feedback remains. Both changes are minimal and correct null guards that stop a real crash. No P0/P1 issues were found; the only observation is a trivial redundant No files require special attention. Important Files Changed
Reviews (1): Last reviewed commit: "fix: prevent TypeError when updating rel..." | Re-trigger Greptile |
| // TODO: @itznotabug - runes? | ||
| $: onShow(showEdit); | ||
| $: title = `Update ${columnOptions.find((v) => v.name === option.name)?.sentenceName ?? ''} column`; | ||
| $: title = `Update ${option ? (columnOptions.find((v) => v.name === option.name)?.sentenceName ?? '') : ''} column`; |
There was a problem hiding this comment.
Redundant
find when option is already the matched entry
When option is defined, it is already the result of columnOptions.find(...), so searching columnOptions a second time by option.name to get sentenceName is redundant — you can read option.sentenceName directly. This simplifies the expression and avoids a linear scan:
| $: title = `Update ${option ? (columnOptions.find((v) => v.name === option.name)?.sentenceName ?? '') : ''} column`; | |
| $: title = `Update ${option?.sentenceName ?? ''} column`; |
Summary
Fixes an uncaught TypeError that crashes the console when clicking "Update" on a relationship attribute from the three-dots menu in the columns list.
Root cause: Two places in
edit.svelteaccess theoptionvariable without null checks:option.namethrowsTypeError: Cannot read property 'name' of undefinedwhen thecolumnOptions.find()on line 37-52 doesn't match the selected column typeoption.update()would also crash if called whenoptionis undefinedFix:
optionis defined before accessing.namesubmit(): throw a descriptive error ("Unsupported column type") instead of crashing with an unhandled TypeErrorFixes appwrite/appwrite#9951
Test plan
onDeletebehavior and save