Skip to content

fix: handle undefined values when handling results #845

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main-enterprise
Choose a base branch
from

Conversation

fandasson
Copy link

This is patch update handling undefined values in few scenarios I observed when using this tool.

I believe it should fix issue #501. I observed the same freezing in github action and this fixes properly handling undefined fixes it.

@Copilot Copilot AI review requested due to automatic review settings June 10, 2025 16:52
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR addresses freezing issues by properly handling undefined values when processing results and loading configuration.

  • Uses nullish coalescing to provide default messages for undefined actions in stats.
  • Skips entries with undefined action when building result HTML.
  • Returns null for failed content fetches to avoid undefined responses.

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
lib/settings.js Fallbacks for undefined action values and guard in HTML generation
lib/configManager.js Return null on failed repos.getContent and guard against null
Comments suppressed due to low confidence (1)

lib/configManager.js:24

  • New error path when octokit.repos.getContent fails returns null. Consider adding unit tests to cover this scenario and verify that callers handle null correctly.
return null

@@ -203,15 +203,15 @@ class Settings {
if (!stats.errors[res.repo]) {
stats.errors[res.repo] = []
}
stats.errors[res.repo].push(res.action)
stats.errors[res.repo].push(res.action ?? 'Unknown error')
Copy link
Preview

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

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

Mixing object and string types in stats.errors may lead to runtime errors when code expects an object with properties like msg. Consider using a consistent object shape, e.g., res.action ?? { msg: 'Unknown error' }.

Suggested change
stats.errors[res.repo].push(res.action ?? 'Unknown error')
stats.errors[res.repo].push(res.action ?? { msg: 'Unknown error' })

Copilot uses AI. Check for mistakes.

} else if (!(res.action?.additions === null && res.action?.deletions === null && res.action?.modifications === null)) {
if (!stats.changes[res.plugin]) {
stats.changes[res.plugin] = {}
}
if (!stats.changes[res.plugin][res.repo]) {
stats.changes[res.plugin][res.repo] = []
}
stats.changes[res.plugin][res.repo].push(`${res.action}`)
stats.changes[res.plugin][res.repo].push(`${res.action ?? 'No action details'}`)
Copy link
Preview

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

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

This pushes either an object stringified via template literal or a string fallback, mixing types in stats.changes. To avoid confusion, serialize objects explicitly or normalize to a consistent format.

Suggested change
stats.changes[res.plugin][res.repo].push(`${res.action ?? 'No action details'}`)
stats.changes[res.plugin][res.repo].push(res.action ? JSON.stringify(res.action) : 'No action details')

Copilot uses AI. Check for mistakes.

@@ -242,16 +242,18 @@ ${this.results.reduce((x, y) => {
if (!y) {
return x
}
// Skip results that don't have an action property or have undefined action
if (!y.action) {
return `${x}`
Copy link
Preview

Copilot AI Jun 10, 2025

Choose a reason for hiding this comment

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

Using template interpolation just to return the original string is redundant. You can simplify this to return x.

Suggested change
return `${x}`
return x

Copilot uses AI. Check for mistakes.

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