diff --git a/artifactory/services/system.go b/artifactory/services/system.go index 5c1ba817c..5e10c068d 100644 --- a/artifactory/services/system.go +++ b/artifactory/services/system.go @@ -44,9 +44,8 @@ func (ss *SystemService) GetVersion() (string, error) { return "", err } var version artifactoryVersion - err = json.Unmarshal(body, &version) - if err != nil { - return "", errorutils.CheckErrorf("couldn't parse Artifactory server response: " + err.Error()) + if err = json.Unmarshal(body, &version); err != nil { + return "", errorutils.CheckErrorf("couldn't parse JFrog Artifactory server version response: " + err.Error()) } return strings.TrimSpace(version.Version), nil } @@ -123,7 +122,7 @@ func (ss *SystemService) sendGet(endpoint string) ([]byte, error) { return nil, err } if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK, http.StatusCreated); err != nil { - return nil, fmt.Errorf("failed while attempting to get Artifactory %s:\n%s", endpoint, err.Error()) + return nil, fmt.Errorf("got unexpected server response while attempting to get JFrog Artifactory %s:\n%s", endpoint, err.Error()) } log.Debug("Artifactory response:", resp.Status) return body, nil diff --git a/distribution/services/version.go b/distribution/services/version.go index ec72ad09c..77ed0042b 100644 --- a/distribution/services/version.go +++ b/distribution/services/version.go @@ -28,16 +28,15 @@ func (vs *VersionService) GetDistributionVersion() (string, error) { httpDetails := vs.DistDetails.CreateHttpClientDetails() resp, body, _, err := vs.client.SendGet(vs.DistDetails.GetUrl()+"api/v1/system/info", true, &httpDetails) if err != nil { - return "", err + return "", errors.New("failed while attempting to get JFrog Distribution version: " + err.Error()) } if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK); err != nil { - return "", errors.New("failed while attempting to get Distribution version:\n" + err.Error()) + return "", errors.New("got unexpected server response while attempting to get JFrog Distribution version:\n" + err.Error()) } var version distributionVersion - err = json.Unmarshal(body, &version) - if err != nil { - return "", errorutils.CheckErrorf("couldn't parse Distribution server response: " + err.Error()) + if err = json.Unmarshal(body, &version); err != nil { + return "", errorutils.CheckErrorf("couldn't parse JFrog Distribution server version version response: " + err.Error()) } return strings.TrimSpace(version.Version), nil } diff --git a/http/httpclient/client.go b/http/httpclient/client.go index d33c1582e..24f24adb8 100644 --- a/http/httpclient/client.go +++ b/http/httpclient/client.go @@ -114,7 +114,8 @@ func (jc *HttpClient) Send(method, url string, content []byte, followRedirect, c LogMsgPrefix: logMsgPrefix, ErrorMessage: fmt.Sprintf("Failure occurred while sending %s request to %s", method, url), ExecutionHandler: func() (bool, error) { - req, err := jc.createReq(method, url, content) + var req *http.Request + req, err = jc.createReq(method, url, content) if err != nil { return true, err } diff --git a/pipelines/services/system.go b/pipelines/services/system.go index 446d3f7e2..17ad24439 100644 --- a/pipelines/services/system.go +++ b/pipelines/services/system.go @@ -25,18 +25,17 @@ func (ss *SystemService) GetSystemInfo() (*PipelinesSystemInfo, error) { httpDetails := ss.ServiceDetails.CreateHttpClientDetails() resp, body, _, err := ss.client.SendGet(ss.ServiceDetails.GetUrl()+"api/v1/system/info", true, &httpDetails) if err != nil { - return nil, err + return nil, errors.New("failed while attempting to get JFrog Pipelines version: " + err.Error()) } if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK); err != nil { if resp.StatusCode == http.StatusNotFound { return nil, &PipelinesNotAvailableError{InnerError: err} } - return nil, errors.New("failed while attempting to get Pipelines version:\n" + err.Error()) + return nil, errors.New("got unexpected server response while attempting to get JFrog Pipelines version:\n" + err.Error()) } var sysInfo PipelinesSystemInfo - err = json.Unmarshal(body, &sysInfo) - if err != nil { - return nil, errorutils.CheckErrorf("couldn't parse Pipelines server response: " + err.Error()) + if err = json.Unmarshal(body, &sysInfo); err != nil { + return nil, errorutils.CheckErrorf("couldn't parse JFrog Pipelines server response: " + err.Error()) } return &sysInfo, nil } diff --git a/utils/git.go b/utils/git.go index ea290b1b4..4eac352a1 100644 --- a/utils/git.go +++ b/utils/git.go @@ -141,8 +141,8 @@ func (m *GitManager) readUrl() { IsNextLineUrl = true } } - if err != nil { - m.err = err + if err := scanner.Err(); err != nil { + m.err = errorutils.CheckError(err) return } if !strings.HasSuffix(originUrl, ".git") { @@ -233,8 +233,8 @@ func (m *GitManager) readRevisionFromRef(refPath string) { revision = strings.TrimSpace(text) break } - if err != nil { - m.err = err + if err := scanner.Err(); err != nil { + m.err = errorutils.CheckError(err) return } m.revision = revision @@ -271,8 +271,8 @@ func (m *GitManager) readRevisionFromPackedRef(ref string) { return } } - if err != nil { - m.err = err + if err = scanner.Err(); err != nil { + m.err = errorutils.CheckError(err) return } } diff --git a/utils/utils.go b/utils/utils.go index f577eb6e5..ed81ba2d3 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -27,7 +27,7 @@ import ( const ( Development = "development" Agent = "jfrog-client-go" - Version = "1.34.1" + Version = "1.34.2" ) type MinVersionProduct string diff --git a/xray/services/entitlements.go b/xray/services/entitlements.go index 8dae574f4..f7c5b0354 100644 --- a/xray/services/entitlements.go +++ b/xray/services/entitlements.go @@ -2,6 +2,7 @@ package services import ( "encoding/json" + "errors" "fmt" "net/http" @@ -30,16 +31,20 @@ func (es *EntitlementsService) IsEntitled(featureId string) (entitled bool, err httpDetails := es.XrayDetails.CreateHttpClientDetails() resp, body, _, err := es.client.SendGet(es.XrayDetails.GetUrl()+"api/v1/entitlements/feature/"+featureId, true, &httpDetails) if err != nil { + err = errors.New("failed while attempting to get JFrog Xray entitlements response: " + err.Error()) return } if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK); err != nil { - return false, fmt.Errorf("failed while attempting to get Xray entitlements response for %s:\n%s", featureId, err.Error()) + err = fmt.Errorf("got unexpected server response while attempting to get JFrog Xray entitlements response for %s:\n%s", featureId, err.Error()) + return } var userEntitlements entitlements if err = json.Unmarshal(body, &userEntitlements); err != nil { - return false, errorutils.CheckErrorf("couldn't parse Xray server response: " + err.Error()) + err = errorutils.CheckErrorf("couldn't parse JFrog Xray server entitlements response: " + err.Error()) + return } - return userEntitlements.Entitled, nil + entitled = userEntitlements.Entitled + return } type entitlements struct { diff --git a/xray/services/scan.go b/xray/services/scan.go index 7ea0b81f1..61908f7e5 100644 --- a/xray/services/scan.go +++ b/xray/services/scan.go @@ -245,7 +245,7 @@ func (ss *ScanService) IsXscEnabled() (xsxVersion string, err error) { url = ss.xrayToXscUrl() resp, body, _, err := ss.client.SendGet(url+XscVersionAPI, false, &httpClientsDetails) if err != nil { - err = errorutils.CheckErrorf("failed to get XSC version, response: " + err.Error()) + err = errorutils.CheckErrorf("failed to get JFrog XSC version, response: " + err.Error()) return } if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK, http.StatusNotFound); err != nil { @@ -257,7 +257,7 @@ func (ss *ScanService) IsXscEnabled() (xsxVersion string, err error) { } versionResponse := XscVersionResponse{} if err = json.Unmarshal(body, &versionResponse); err != nil { - err = errorutils.CheckErrorf("failed to parse XSC server response: " + err.Error()) + err = errorutils.CheckErrorf("failed to parse JFrog XSC server response: " + err.Error()) return } xsxVersion = versionResponse.Version diff --git a/xray/services/version.go b/xray/services/version.go index cb92f2dde..7dbb71809 100644 --- a/xray/services/version.go +++ b/xray/services/version.go @@ -32,15 +32,14 @@ func (vs *VersionService) GetVersion() (string, error) { httpDetails := vs.XrayDetails.CreateHttpClientDetails() resp, body, _, err := vs.client.SendGet(vs.XrayDetails.GetUrl()+"api/v1/system/version", true, &httpDetails) if err != nil { - return "", err + return "", errors.New("failed while attempting to get JFrog Xray version: " + err.Error()) } if err = errorutils.CheckResponseStatusWithBody(resp, body, http.StatusOK); err != nil { - return "", errors.New("failed while attempting to get Xray version:\n" + err.Error()) + return "", errors.New("got unexpected server response while attempting to get JFrog Xray version:\n" + err.Error()) } var version xrayVersion - err = json.Unmarshal(body, &version) - if err != nil { - return "", errorutils.CheckErrorf("couldn't parse Xray server response: " + err.Error()) + if err = json.Unmarshal(body, &version); err != nil { + return "", errorutils.CheckErrorf("couldn't parse JFrog Xray server version response: " + err.Error()) } return strings.TrimSpace(version.Version), nil }