MCPcopy Create free account
hub / github.com/Shopify/ghostferry / ReportError

Method ReportError

error_handler.go:25–67  ·  view source on GitHub ↗
(from string, err error)

Source from the content-addressed store, hash-verified

23}
24
25func (this *PanicErrorHandler) ReportError(from string, err error) {
26 logger := LogWithField("tag", "error_handler")
27
28 stateJSON, jsonErr := this.Ferry.SerializeStateToJSON()
29 if jsonErr != nil {
30 logger.WithError(jsonErr).Error("failed to dump state to JSON...")
31 } else {
32 if this.DumpStateToStdoutOnError {
33 fmt.Fprintln(os.Stdout, stateJSON)
34 }
35 }
36
37 // Invoke ErrorCallback if defined
38 if this.ErrorCallback != (HTTPCallback{}) {
39 client := &http.Client{}
40
41 errorData := make(map[string]string)
42 errorData["ErrFrom"] = from
43 errorData["ErrMessage"] = err.Error()
44 errorData["StateDump"] = stateJSON
45
46 errorDataBytes, jsonErr := json.MarshalIndent(errorData, "", " ")
47 if jsonErr != nil {
48 logger.WithField("error", jsonErr).Errorf("ghostferry failed to marshal error data")
49 } else {
50 this.ErrorCallback.Payload = string(errorDataBytes)
51
52 postErr := this.ErrorCallback.Post(client)
53 if postErr != nil {
54 logger.WithField("error", postErr).Errorf("ghostferry failed to notify error")
55 }
56 }
57 }
58
59 var errmsg string
60 if this.DumpStateToStdoutOnError {
61 errmsg = "fatal error detected, state dump in stdout"
62 } else {
63 errmsg = "fatal error detected"
64 }
65 // Print error to STDERR
66 logger.WithError(err).WithField("errfrom", from).Error(errmsg)
67}
68
69func (this *PanicErrorHandler) Fatal(from string, err error) {
70 if atomic.AddInt32(&this.errorCount, 1) > 1 {

Callers 1

FatalMethod · 0.95

Calls 7

LogWithFieldFunction · 0.85
SerializeStateToJSONMethod · 0.80
PostMethod · 0.80
ErrorMethod · 0.65
WithErrorMethod · 0.65
ErrorfMethod · 0.65
WithFieldMethod · 0.65

Tested by

no test coverage detected