Skip to content
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

Fix potential nil exception when getting frame #1152

Merged
merged 3 commits into from Jan 11, 2024
Merged

Fix potential nil exception when getting frame #1152

merged 3 commits into from Jan 11, 2024

Conversation

ankur22
Copy link
Collaborator

@ankur22 ankur22 commented Jan 10, 2024

What?

This change avoids the need to check for nil when getting the frame with an id, and reinforces a requirement to check with an addition of a bool return value to indicate whether the frame was found or not.

Why?

When a part of the browser module needs to retrieve the frame given an id, it should check whether the frame is nil before using it. This is not safe, since it's easy to forget to check for nil, and so a new return value is also returned.

Checklist

  • I have performed a self-review of my code
  • I have added tests for my changes
  • I have commented on my code, particularly in hard-to-understand areas

Related PR(s)/Issue(s)

Updates: #1148

When a part of the browser module needs to retrieve the frame given an
id, it should check whether the frame is nil before using it. This is
not safe, since it's easy to forget to check for nil.

This change avoids the need to check for nil and reinforces a
requirement to check with an addition of a bool that is also returned
to indicate whether the frame was found or not.
common/frame_session.go Outdated Show resolved Hide resolved
ka3de
ka3de previously approved these changes Jan 11, 2024
Copy link
Member

@inancgumus inancgumus left a comment

Choose a reason for hiding this comment

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

It's an excellent idea to use the comma-ok idiom here 👍 LGTM and have some suggestions.

common/element_handle.go Outdated Show resolved Hide resolved
common/frame_manager.go Outdated Show resolved Hide resolved
common/frame_manager.go Show resolved Hide resolved
Co-authored-by: İnanç Gümüş <inanc.gumus@grafana.com>
Ok is more idiomatic in Go.
@ankur22 ankur22 merged commit 5f754c2 into main Jan 11, 2024
17 checks passed
@ankur22 ankur22 deleted the fix/frame-npe branch January 11, 2024 12:47
@ankur22 ankur22 mentioned this pull request Jan 11, 2024
5 tasks
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.

None yet

3 participants