fix(backend): use first frame for error identification (#790)

This commit is contained in:
Alex K 2022-10-27 16:29:48 +02:00 committed by GitHub
parent b986c0b591
commit c7520166f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -79,11 +79,36 @@ func WrapIntegrationEvent(m *IntegrationEvent) *ErrorEvent {
}
}
type stackFrame struct {
FileName string `json:"fileName"`
LineNo int `json:"lineNumber"`
ColNo int `json:"columnNumber"`
}
func parseFirstFrame(payload string) (*stackFrame, error) {
var frames []*stackFrame
if err := json.Unmarshal([]byte(payload), &frames); err != nil {
return nil, err
}
if len(frames) == 0 {
return nil, nil
}
return frames[0], nil
}
func (e *ErrorEvent) ID(projectID uint32) string {
hash := fnv.New128a()
hash.Write([]byte(e.Source))
hash.Write([]byte(e.Name))
hash.Write([]byte(e.Message))
hash.Write([]byte(e.Payload))
frame, err := parseFirstFrame(e.Payload)
if err != nil {
log.Printf("Can't parse stackframe ((( %v ))): %v", e.Payload, err)
}
if frame != nil {
hash.Write([]byte(frame.FileName))
hash.Write([]byte(strconv.Itoa(frame.LineNo)))
hash.Write([]byte(strconv.Itoa(frame.ColNo)))
}
return strconv.FormatUint(uint64(projectID), 16) + hex.EncodeToString(hash.Sum(nil))
}