github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/cdc/model/errors.go (about) 1 // Copyright 2020 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package model 15 16 import ( 17 "database/sql/driver" 18 "encoding/json" 19 "errors" 20 "time" 21 22 cerror "github.com/pingcap/tiflow/pkg/errors" 23 ) 24 25 // RunningError represents some running error from cdc components, such as processor. 26 type RunningError struct { 27 Time time.Time `json:"time"` 28 Addr string `json:"addr"` 29 Code string `json:"code"` 30 Message string `json:"message"` 31 } 32 33 // ShouldFailChangefeed return true if a running error contains a changefeed not retry error. 34 func (e RunningError) ShouldFailChangefeed() bool { 35 return cerror.ShouldFailChangefeed(errors.New(e.Message + e.Code)) 36 } 37 38 // Value implements the driver.Valuer interface 39 func (e RunningError) Value() (driver.Value, error) { 40 return json.Marshal(e) 41 } 42 43 // Scan implements the sql.Scanner interface 44 func (e *RunningError) Scan(value interface{}) error { 45 b, ok := value.([]byte) 46 if !ok { 47 return errors.New("type assertion to []byte failed") 48 } 49 50 return json.Unmarshal(b, e) 51 }