mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-26 19:00:05 +08:00
rename: service_vedem.go and CV related error codes
This commit is contained in:
@@ -79,18 +79,16 @@ var (
|
|||||||
MobileUIPopupError = errors.New("mobile UI popup error") // 78
|
MobileUIPopupError = errors.New("mobile UI popup error") // 78
|
||||||
)
|
)
|
||||||
|
|
||||||
// OCR related: [80, 90)
|
// CV related: [80, 90)
|
||||||
var (
|
var (
|
||||||
OCREnvMissedError = errors.New("OCR env missed error") // 80
|
CVEnvMissedError = errors.New("CV env missed error") // 80
|
||||||
OCRRequestError = errors.New("OCR prepare request error") // 81
|
CVRequestError = errors.New("CV prepare request error") // 81
|
||||||
OCRServiceConnectionError = errors.New("OCR service connect error") // 82
|
CVServiceConnectionError = errors.New("CV service connect error") // 82
|
||||||
OCRResponseError = errors.New("OCR parse response error") // 83
|
CVResponseError = errors.New("CV parse response error") // 83
|
||||||
OCRTextNotFoundError = errors.New("OCR text not found") // 84
|
CVResultNotFoundError = errors.New("CV result not found") // 84
|
||||||
LoopActionNotFoundError = errors.New("loop action not found error") // 85
|
LoopActionNotFoundError = errors.New("loop action not found error") // 85
|
||||||
)
|
)
|
||||||
|
|
||||||
// CV related: [90, 100)
|
|
||||||
|
|
||||||
var errorsMap = map[error]int{
|
var errorsMap = map[error]int{
|
||||||
// environment
|
// environment
|
||||||
InvalidPython3Venv: 9,
|
InvalidPython3Venv: 9,
|
||||||
@@ -144,12 +142,12 @@ var errorsMap = map[error]int{
|
|||||||
MobileUIPopupError: 78,
|
MobileUIPopupError: 78,
|
||||||
|
|
||||||
// OCR related
|
// OCR related
|
||||||
OCREnvMissedError: 80,
|
CVEnvMissedError: 80,
|
||||||
OCRRequestError: 81,
|
CVRequestError: 81,
|
||||||
OCRServiceConnectionError: 82,
|
CVServiceConnectionError: 82,
|
||||||
OCRResponseError: 83,
|
CVResponseError: 83,
|
||||||
OCRTextNotFoundError: 84,
|
CVResultNotFoundError: 84,
|
||||||
LoopActionNotFoundError: 85,
|
LoopActionNotFoundError: 85,
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsErrorPredefined(err error) bool {
|
func IsErrorPredefined(err error) bool {
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ func (t OCRTexts) FindText(text string, options ...ActionOption) (result OCRText
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(results) == 0 {
|
if len(results) == 0 {
|
||||||
return OCRText{}, errors.Wrap(code.OCRTextNotFoundError,
|
return OCRText{}, errors.Wrap(code.CVResultNotFoundError,
|
||||||
fmt.Sprintf("text %s not found in %v", text, t.texts()))
|
fmt.Sprintf("text %s not found in %v", text, t.texts()))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,7 +137,7 @@ func (t OCRTexts) FindText(text string, options ...ActionOption) (result OCRText
|
|||||||
|
|
||||||
// index out of range
|
// index out of range
|
||||||
if idx >= len(results) || idx < 0 {
|
if idx >= len(results) || idx < 0 {
|
||||||
return OCRText{}, errors.Wrap(code.OCRTextNotFoundError,
|
return OCRText{}, errors.Wrap(code.CVResultNotFoundError,
|
||||||
fmt.Sprintf("text %s found %d, index %d out of range", text, len(results), idx))
|
fmt.Sprintf("text %s found %d, index %d out of range", text, len(results), idx))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,7 +154,7 @@ func (t OCRTexts) FindTexts(texts []string, options ...ActionOption) (results OC
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(results) != len(texts) {
|
if len(results) != len(texts) {
|
||||||
return nil, errors.Wrap(code.OCRTextNotFoundError,
|
return nil, errors.Wrap(code.CVResultNotFoundError,
|
||||||
fmt.Sprintf("texts %s not found in %v", texts, t.texts()))
|
fmt.Sprintf("texts %s not found in %v", texts, t.texts()))
|
||||||
}
|
}
|
||||||
return results, nil
|
return results, nil
|
||||||
@@ -203,21 +203,21 @@ func (s *veDEMImageService) GetImage(imageBuf *bytes.Buffer) (imageResult ImageR
|
|||||||
|
|
||||||
formWriter, err := bodyWriter.CreateFormFile("image", "screenshot.png")
|
formWriter, err := bodyWriter.CreateFormFile("image", "screenshot.png")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(code.OCRRequestError,
|
err = errors.Wrap(code.CVRequestError,
|
||||||
fmt.Sprintf("create form file error: %v", err))
|
fmt.Sprintf("create form file error: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
size, err := formWriter.Write(imageBuf.Bytes())
|
size, err := formWriter.Write(imageBuf.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(code.OCRRequestError,
|
err = errors.Wrap(code.CVRequestError,
|
||||||
fmt.Sprintf("write form error: %v", err))
|
fmt.Sprintf("write form error: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bodyWriter.Close()
|
err = bodyWriter.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(code.OCRRequestError,
|
err = errors.Wrap(code.CVRequestError,
|
||||||
fmt.Sprintf("close body writer error: %v", err))
|
fmt.Sprintf("close body writer error: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -233,7 +233,7 @@ func (s *veDEMImageService) GetImage(imageBuf *bytes.Buffer) (imageResult ImageR
|
|||||||
|
|
||||||
req, err = http.NewRequest("POST", env.VEDEM_IMAGE_URL, copiedBodyBuf)
|
req, err = http.NewRequest("POST", env.VEDEM_IMAGE_URL, copiedBodyBuf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(code.OCRRequestError,
|
err = errors.Wrap(code.CVRequestError,
|
||||||
fmt.Sprintf("construct request error: %v", err))
|
fmt.Sprintf("construct request error: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,7 @@ func (s *veDEMImageService) GetImage(imageBuf *bytes.Buffer) (imageResult ImageR
|
|||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
if resp == nil {
|
if resp == nil {
|
||||||
err = code.OCRServiceConnectionError
|
err = code.CVServiceConnectionError
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,13 +275,13 @@ func (s *veDEMImageService) GetImage(imageBuf *bytes.Buffer) (imageResult ImageR
|
|||||||
|
|
||||||
results, err := ioutil.ReadAll(resp.Body)
|
results, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err = errors.Wrap(code.OCRResponseError,
|
err = errors.Wrap(code.CVResponseError,
|
||||||
fmt.Sprintf("read response body error: %v", err))
|
fmt.Sprintf("read response body error: %v", err))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
err = errors.Wrap(code.OCRResponseError,
|
err = errors.Wrap(code.CVResponseError,
|
||||||
fmt.Sprintf("unexpected response status code: %d, results: %v",
|
fmt.Sprintf("unexpected response status code: %d, results: %v",
|
||||||
resp.StatusCode, string(results)))
|
resp.StatusCode, string(results)))
|
||||||
return
|
return
|
||||||
@@ -293,7 +293,7 @@ func (s *veDEMImageService) GetImage(imageBuf *bytes.Buffer) (imageResult ImageR
|
|||||||
log.Error().Err(err).
|
log.Error().Err(err).
|
||||||
Str("response", string(results)).
|
Str("response", string(results)).
|
||||||
Msg("json unmarshal veDEM image response body failed")
|
Msg("json unmarshal veDEM image response body failed")
|
||||||
err = errors.Wrap(code.OCRResponseError,
|
err = errors.Wrap(code.CVResponseError,
|
||||||
"json unmarshal veDEM image response body error")
|
"json unmarshal veDEM image response body error")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -312,14 +312,14 @@ func (s *veDEMImageService) GetImage(imageBuf *bytes.Buffer) (imageResult ImageR
|
|||||||
|
|
||||||
func checkEnv() error {
|
func checkEnv() error {
|
||||||
if env.VEDEM_IMAGE_URL == "" {
|
if env.VEDEM_IMAGE_URL == "" {
|
||||||
return errors.Wrap(code.OCREnvMissedError, "VEDEM_IMAGE_URL missed")
|
return errors.Wrap(code.CVEnvMissedError, "VEDEM_IMAGE_URL missed")
|
||||||
}
|
}
|
||||||
log.Info().Str("VEDEM_IMAGE_URL", env.VEDEM_IMAGE_URL).Msg("get env")
|
log.Info().Str("VEDEM_IMAGE_URL", env.VEDEM_IMAGE_URL).Msg("get env")
|
||||||
if env.VEDEM_IMAGE_AK == "" {
|
if env.VEDEM_IMAGE_AK == "" {
|
||||||
return errors.Wrap(code.OCREnvMissedError, "VEDEM_IMAGE_AK missed")
|
return errors.Wrap(code.CVEnvMissedError, "VEDEM_IMAGE_AK missed")
|
||||||
}
|
}
|
||||||
if env.VEDEM_IMAGE_SK == "" {
|
if env.VEDEM_IMAGE_SK == "" {
|
||||||
return errors.Wrap(code.OCREnvMissedError, "VEDEM_IMAGE_SK missed")
|
return errors.Wrap(code.CVEnvMissedError, "VEDEM_IMAGE_SK missed")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -478,7 +478,7 @@ func (u UIResults) GetUIResult(options ...ActionOption) (UIResult, error) {
|
|||||||
|
|
||||||
uiResults := u.FilterScope(actionOptions.AbsScope)
|
uiResults := u.FilterScope(actionOptions.AbsScope)
|
||||||
if len(uiResults) == 0 {
|
if len(uiResults) == 0 {
|
||||||
return UIResult{}, errors.Wrap(code.OCRTextNotFoundError,
|
return UIResult{}, errors.Wrap(code.CVResultNotFoundError,
|
||||||
"ui types not found in scope")
|
"ui types not found in scope")
|
||||||
}
|
}
|
||||||
// get index
|
// get index
|
||||||
@@ -489,7 +489,7 @@ func (u UIResults) GetUIResult(options ...ActionOption) (UIResult, error) {
|
|||||||
|
|
||||||
// index out of range
|
// index out of range
|
||||||
if idx >= len(uiResults) || idx < 0 {
|
if idx >= len(uiResults) || idx < 0 {
|
||||||
return UIResult{}, errors.Wrap(code.OCRTextNotFoundError,
|
return UIResult{}, errors.Wrap(code.CVResultNotFoundError,
|
||||||
fmt.Sprintf("ui types index %d out of range", idx))
|
fmt.Sprintf("ui types index %d out of range", idx))
|
||||||
}
|
}
|
||||||
return uiResults[idx], nil
|
return uiResults[idx], nil
|
||||||
Reference in New Issue
Block a user