Pointers v2 package test#1208
Conversation
SummaryMigrated pointers package from v1 to v2 across multiple files. Updated imports from github.com/bitrise-io/go-utils/pointers to github.com/bitrise-io/go-utils/v2/pointers and replaced utility function calls with manual nil checks where needed. Walkthrough
|
| func prepareAnalyticsStepInfo(step stepmanModels.StepModel, stepInfoPtr stepmanModels.StepInfoModel) analytics.StepInfo { | ||
| stepTitle := "" | ||
| if stepInfoPtr.Step.Title != nil { | ||
| stepTitle = *stepInfoPtr.Step.Title | ||
| } | ||
| stepSource := "" | ||
| if stepInfoPtr.Step.SourceCodeURL != nil { | ||
| stepSource = *stepInfoPtr.Step.SourceCodeURL | ||
| } | ||
| skippable := false | ||
| if stepInfoPtr.Step.IsSkippable != nil { | ||
| skippable = *stepInfoPtr.Step.IsSkippable | ||
| } | ||
|
|
||
| return analytics.StepInfo{ | ||
| StepID: stepInfoPtr.ID, | ||
| StepTitle: pointers.StringWithDefault(step.Title, ""), | ||
| StepTitle: stepTitle, | ||
| StepVersion: stepInfoPtr.Version, | ||
| StepSource: pointers.StringWithDefault(step.SourceCodeURL, ""), | ||
| Skippable: pointers.BoolWithDefault(step.IsSkippable, false), | ||
| StepSource: stepSource, | ||
| Skippable: skippable, | ||
| } | ||
| } |
There was a problem hiding this comment.
🐛 Bug
The function now uses stepInfoPtr.Step fields instead of the step parameter. However, stepInfoPtr.Step.IsSkippable is never populated in the activateStep function, so it will always be nil and default to false. This causes incorrect analytics data. Additionally, stepTitle should use the step parameter (the merged step) not stepInfoPtr.Step.Title for consistency with the original implementation.
🔄 Suggestion:
| func prepareAnalyticsStepInfo(step stepmanModels.StepModel, stepInfoPtr stepmanModels.StepInfoModel) analytics.StepInfo { | |
| stepTitle := "" | |
| if stepInfoPtr.Step.Title != nil { | |
| stepTitle = *stepInfoPtr.Step.Title | |
| } | |
| stepSource := "" | |
| if stepInfoPtr.Step.SourceCodeURL != nil { | |
| stepSource = *stepInfoPtr.Step.SourceCodeURL | |
| } | |
| skippable := false | |
| if stepInfoPtr.Step.IsSkippable != nil { | |
| skippable = *stepInfoPtr.Step.IsSkippable | |
| } | |
| return analytics.StepInfo{ | |
| StepID: stepInfoPtr.ID, | |
| StepTitle: pointers.StringWithDefault(step.Title, ""), | |
| StepTitle: stepTitle, | |
| StepVersion: stepInfoPtr.Version, | |
| StepSource: pointers.StringWithDefault(step.SourceCodeURL, ""), | |
| Skippable: pointers.BoolWithDefault(step.IsSkippable, false), | |
| StepSource: stepSource, | |
| Skippable: skippable, | |
| } | |
| } | |
| func prepareAnalyticsStepInfo(step stepmanModels.StepModel, stepInfoPtr stepmanModels.StepInfoModel) analytics.StepInfo { | |
| stepTitle := "" | |
| if step.Title != nil { | |
| stepTitle = *step.Title | |
| } | |
| stepSource := "" | |
| if step.SourceCodeURL != nil { | |
| stepSource = *step.SourceCodeURL | |
| } | |
| skippable := false | |
| if step.IsSkippable != nil { | |
| skippable = *step.IsSkippable | |
| } | |
| return analytics.StepInfo{ | |
| StepID: stepInfoPtr.ID, | |
| StepTitle: stepTitle, | |
| StepVersion: stepInfoPtr.Version, | |
| StepSource: stepSource, | |
| Skippable: skippable, | |
| } | |
| } |
| if stepInfoPtr.Step.Title != nil { | ||
| stepTitle = *step.Title | ||
| } | ||
| stepSource := "" | ||
| if stepInfoPtr.Step.SourceCodeURL != nil { | ||
| stepSource = *step.SourceCodeURL | ||
| } | ||
| skippable := false | ||
| if stepInfoPtr.Step.IsSkippable != nil { | ||
| skippable = *step.IsSkippable | ||
| } |
There was a problem hiding this comment.
🐛 Bug
The nil checks are performed on stepInfoPtr.Step fields, but the dereferences are on step fields. This causes a mismatch: if stepInfoPtr.Step.Title is not nil but step.Title is nil, this will cause a nil pointer dereference. The dereferences should use stepInfoPtr.Step fields instead of step fields.
🔄 Suggestion:
| if stepInfoPtr.Step.Title != nil { | |
| stepTitle = *step.Title | |
| } | |
| stepSource := "" | |
| if stepInfoPtr.Step.SourceCodeURL != nil { | |
| stepSource = *step.SourceCodeURL | |
| } | |
| skippable := false | |
| if stepInfoPtr.Step.IsSkippable != nil { | |
| skippable = *step.IsSkippable | |
| } | |
| if stepInfoPtr.Step.Title != nil { | |
| stepTitle = *stepInfoPtr.Step.Title | |
| } | |
| stepSource := "" | |
| if stepInfoPtr.Step.SourceCodeURL != nil { | |
| stepSource = *stepInfoPtr.Step.SourceCodeURL | |
| } | |
| skippable := false | |
| if stepInfoPtr.Step.IsSkippable != nil { | |
| skippable = *stepInfoPtr.Step.IsSkippable | |
| } |
Checklist
README.mdis updated with the changes (if needed)Version
Requires a MAJOR/MINOR/PATCH version update
Context
Changes
Investigation details
Decisions