Skip to content

Commit e91670d

Browse files
committed
fix: add missing optional backtrace field types
1 parent 5c97548 commit e91670d

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

internal/hbapi/types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,12 @@ type NoticeRequest struct {
122122
// BacktraceEntry represents a single entry in the error backtrace
123123
type BacktraceEntry struct {
124124
Number StringOrInt `json:"number"`
125+
Column *StringOrInt `json:"column,omitempty"`
125126
File string `json:"file"`
126127
Method string `json:"method"`
128+
Class string `json:"class,omitempty"`
129+
Type string `json:"type,omitempty"`
130+
Args []interface{} `json:"args,omitempty"`
127131
Source map[string]interface{} `json:"source,omitempty"`
128132
Context string `json:"context,omitempty"`
129133
}

internal/hbapi/types_test.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,48 @@ func TestBacktraceEntry_UnmarshalJSON(t *testing.T) {
116116
},
117117
wantErr: false,
118118
},
119+
{
120+
name: "backtrace entry with all optional fields",
121+
input: `{
122+
"number": "25",
123+
"column": 15,
124+
"file": "/app/models/user.rb",
125+
"method": "authenticate",
126+
"class": "User",
127+
"type": "instance",
128+
"args": ["email@example.com", "password"],
129+
"source": {"25": "user = User.find_by(email: email)"},
130+
"context": "app"
131+
}`,
132+
want: BacktraceEntry{
133+
Number: "25",
134+
Column: func() *StringOrInt { s := StringOrInt("15"); return &s }(),
135+
File: "/app/models/user.rb",
136+
Method: "authenticate",
137+
Class: "User",
138+
Type: "instance",
139+
Args: []interface{}{"email@example.com", "password"},
140+
Source: map[string]interface{}{"25": "user = User.find_by(email: email)"},
141+
Context: "app",
142+
},
143+
wantErr: false,
144+
},
145+
{
146+
name: "backtrace entry with column as string",
147+
input: `{
148+
"number": 42,
149+
"column": "8",
150+
"file": "/lib/helper.js",
151+
"method": "processData"
152+
}`,
153+
want: BacktraceEntry{
154+
Number: "42",
155+
Column: func() *StringOrInt { s := StringOrInt("8"); return &s }(),
156+
File: "/lib/helper.js",
157+
Method: "processData",
158+
},
159+
wantErr: false,
160+
},
119161
}
120162

121163
for _, tt := range tests {
@@ -139,6 +181,26 @@ func TestBacktraceEntry_UnmarshalJSON(t *testing.T) {
139181
if entry.Context != tt.want.Context {
140182
t.Errorf("BacktraceEntry.Context = %v, want %v", entry.Context, tt.want.Context)
141183
}
184+
// Check Column
185+
if tt.want.Column != nil && entry.Column != nil {
186+
if string(*entry.Column) != string(*tt.want.Column) {
187+
t.Errorf("BacktraceEntry.Column = %v, want %v", *entry.Column, *tt.want.Column)
188+
}
189+
} else if (tt.want.Column == nil) != (entry.Column == nil) {
190+
t.Errorf("BacktraceEntry.Column = %v, want %v", entry.Column, tt.want.Column)
191+
}
192+
// Check Class
193+
if entry.Class != tt.want.Class {
194+
t.Errorf("BacktraceEntry.Class = %v, want %v", entry.Class, tt.want.Class)
195+
}
196+
// Check Type
197+
if entry.Type != tt.want.Type {
198+
t.Errorf("BacktraceEntry.Type = %v, want %v", entry.Type, tt.want.Type)
199+
}
200+
// Check Args length
201+
if len(entry.Args) != len(tt.want.Args) {
202+
t.Errorf("BacktraceEntry.Args length = %v, want %v", len(entry.Args), len(tt.want.Args))
203+
}
142204
}
143205
})
144206
}

0 commit comments

Comments
 (0)