(from string, err error)
| 23 | } |
| 24 | |
| 25 | func (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 | |
| 69 | func (this *PanicErrorHandler) Fatal(from string, err error) { |
| 70 | if atomic.AddInt32(&this.errorCount, 1) > 1 { |
no test coverage detected