From 2a4e688ff22f3350b673a50a7038334b43895287 Mon Sep 17 00:00:00 2001 From: Matt Godbolt Date: Mon, 9 Jun 2025 11:00:27 -0500 Subject: [PATCH] Fix null reference errors in gccdump view selection handling (#7764) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary Fixes two related null reference errors in the GCC dump view's TomSelect dropdown handling that occur during user interactions. ## Root Cause Analysis **COMPILER-EXPLORER-96P** (1067 occurrences): - Error: `TypeError: undefined is not an object (evaluating 't.filename_suffix')` - Location: `gccdump-view.ts:318` in `onPassSelect()` - Trigger: User deletes a selection via TomSelect → `deleteSelection()` → `removeItem()` → `trigger('change')` → `onPassSelect()` called with passId that no longer exists in `this.selectize.options` **COMPILER-EXPLORER-E44** (34 occurrences): - Error: `TypeError: Cannot read properties of undefined (reading '0')` - Location: `gccdump-view.ts:237` in dropdown open handler - Trigger: `find()` returns undefined when searching for pass by filename_suffix, but code uses non-null assertion `activeOption![0]` Both errors occur due to timing issues when dropdown options are being updated while user interactions are happening. ## Changes 1. **Added null check in `onPassSelect()`**: Safely handle case where `this.selectize.options[passId]` returns undefined 2. **Removed unsafe non-null assertion**: Replace `activeOption![0]` with proper null check and early return 3. **Added CLAUDE.md guidance**: Include preference for modern TypeScript features like optional chaining ## Impact - Prevents crashes with 1100+ reported occurrences combined - Maintains existing user experience - dropdowns continue to work normally - No behavioral changes for valid interactions Fixes COMPILER-EXPLORER-96P Fixes COMPILER-EXPLORER-E44 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude --- CLAUDE.md | 1 + static/panes/gccdump-view.ts | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CLAUDE.md b/CLAUDE.md index 5db914d0b..54e9c6272 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -58,6 +58,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co - Comments should provide additional context or explain "why" something is done, not just restate "what" is being done. - Only add function header comments when they provide meaningful information beyond what the function name and signature convey. - Use British English spellings for things like "initialise" and "colour", but only in new code. It's a preference not a hard requirement +- Use modern Typescript features like optional chaining when updating existing code or adding new code ## Testing Guidelines - Use Vitest for unit tests (compatible with Jest syntax) diff --git a/static/panes/gccdump-view.ts b/static/panes/gccdump-view.ts index 41d0a803f..fc9f890ae 100644 --- a/static/panes/gccdump-view.ts +++ b/static/panes/gccdump-view.ts @@ -234,7 +234,8 @@ export class GccDump extends MonacoPane op[1].filename_suffix === this.selectedPass, ); - const selectedPassId = activeOption![0]; + if (!activeOption) return; + const selectedPassId = activeOption[0]; const option = this.selectize.getOption(selectedPassId); // Workaround for a TomSelect glitch: onFocus sets the active option to the first one // on the first re-open, so this setActiveOption call needs to be delayed. @@ -303,6 +304,12 @@ export class GccDump extends MonacoPane