Skip to content

fix: guard cached source against null when preference has only freeText data#6

Merged
avifenesh merged 1 commit intomainfrom
fix/cached-source-nullcheck
Mar 10, 2026
Merged

fix: guard cached source against null when preference has only freeText data#6
avifenesh merged 1 commit intomainfrom
fix/cached-source-nullcheck

Conversation

@avifenesh
Copy link
Copy Markdown
Contributor

When preference.json contains only freeText entries (no source field), getPolicyQuestions crashed on cached.source.charAt(). Now checks cached?.source before accessing.

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@avifenesh avifenesh merged commit cc09710 into main Mar 10, 2026
4 checks passed
@avifenesh avifenesh deleted the fix/cached-source-nullcheck branch March 10, 2026 11:15
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial null check to prevent an application crash. By ensuring that the cached.source property exists before attempting to access its methods, the change enhances the robustness of the getPolicyQuestions function, particularly when handling preference data that may not include a source field.

Highlights

  • Bug Fix: Resolved a crash in getPolicyQuestions that occurred when preference.json contained only freeText entries and lacked a source field. Previously, accessing cached.source.charAt() would cause an error.
Changelog
  • lib/sources/policy-questions.js
    • Added a null check for cached?.source to prevent crashes when the source field is missing from cached preferences.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a crash that occurs when cached preferences lack a source property by adding an optional chaining guard. The fix is correct and effectively prevents the error. My review includes one suggestion to further improve the robustness of this code block by handling cases where tool and type properties might be missing for a 'custom' source, which could prevent malformed UI labels.

// If cached, add as first option
// NOTE: OpenCode enforces 30-char max on labels
if (cached) {
if (cached?.source) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

While this change correctly guards against a missing source property, the code within this if block could be more robust. If cached.source is 'custom', the code on lines 52-53 accesses cached.tool and cached.type without checking if they exist. If these properties are missing from the cached preference object, it could result in a malformed UI label like "undefined (cli)".

To make this more robust, you could provide default values. For example:

const cachedLabel = cached.source === 'custom'
  ? `${cached.tool || 'Custom'} (${cached.type || 'source'})`
  : SOURCE_LABELS[cached.source] || (cached.source.charAt(0).toUpperCase() + cached.source.slice(1));

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.

1 participant