mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-04-11 11:41:53 +02:00
ABAP: Add details for EOF errors (#4442)
* Add details for EOF errors * Add testcase * remove test * Add unit test
This commit is contained in:
parent
d0e587729d
commit
994e87479d
@ -29,7 +29,6 @@ func abapEnvironmentCloneGitRepo(config abapEnvironmentCloneGitRepoOptions, _ *t
|
||||
}
|
||||
|
||||
client := piperhttp.Client{}
|
||||
|
||||
// error situations should stop execution through log.Entry().Fatal() call which leads to an os.Exit(1) in the end
|
||||
err := runAbapEnvironmentCloneGitRepo(&config, &autils, &client)
|
||||
if err != nil {
|
||||
@ -76,9 +75,9 @@ func runAbapEnvironmentCloneGitRepo(config *abapEnvironmentCloneGitRepoOptions,
|
||||
logString := repo.GetCloneLogString()
|
||||
errorString := "Clone of " + logString + " failed on the ABAP system"
|
||||
|
||||
log.Entry().Info("-------------------------")
|
||||
abaputils.AddDefaultDashedLine()
|
||||
log.Entry().Info("Start cloning " + logString)
|
||||
log.Entry().Info("-------------------------")
|
||||
abaputils.AddDefaultDashedLine()
|
||||
|
||||
// Triggering the Clone of the repository into the ABAP Environment system
|
||||
uriConnectionDetails, errorTriggerClone, didCheckoutPullInstead := triggerClone(repo, connectionDetails, client)
|
||||
@ -99,7 +98,7 @@ func runAbapEnvironmentCloneGitRepo(config *abapEnvironmentCloneGitRepoOptions,
|
||||
log.Entry().Info("The " + logString + " was cloned successfully")
|
||||
}
|
||||
}
|
||||
log.Entry().Info("-------------------------")
|
||||
abaputils.AddDefaultDashedLine()
|
||||
log.Entry().Info("All repositories were cloned successfully")
|
||||
return nil
|
||||
}
|
||||
@ -191,12 +190,12 @@ func handleCloneError(resp *http.Response, err error, cloneConnectionDetails aba
|
||||
// As an intermediate workaround, we react to the error message A4C_A2G/257 that gets thrown, if the repository had already been cloned
|
||||
// In this case, a checkout branch and a pull will be performed
|
||||
alreadyCloned = true
|
||||
log.Entry().Infof("-------------------------")
|
||||
log.Entry().Infof("-------------------------")
|
||||
abaputils.AddDefaultDashedLine()
|
||||
abaputils.AddDefaultDashedLine()
|
||||
log.Entry().Infof("%s", "The repository / software component has already been cloned on the ABAP Environment system ")
|
||||
log.Entry().Infof("%s", "A `checkout branch` and a `pull` will be performed instead")
|
||||
log.Entry().Infof("-------------------------")
|
||||
log.Entry().Infof("-------------------------")
|
||||
abaputils.AddDefaultDashedLine()
|
||||
abaputils.AddDefaultDashedLine()
|
||||
checkoutOptions := abapEnvironmentCheckoutBranchOptions{
|
||||
Username: cloneConnectionDetails.User,
|
||||
Password: cloneConnectionDetails.Password,
|
||||
@ -214,8 +213,8 @@ func handleCloneError(resp *http.Response, err error, cloneConnectionDetails aba
|
||||
if returnedError != nil {
|
||||
return
|
||||
}
|
||||
log.Entry().Infof("-------------------------")
|
||||
log.Entry().Infof("-------------------------")
|
||||
abaputils.AddDefaultDashedLine()
|
||||
abaputils.AddDefaultDashedLine()
|
||||
pullOptions := abapEnvironmentPullGitRepoOptions{
|
||||
Username: cloneConnectionDetails.User,
|
||||
Password: cloneConnectionDetails.Password,
|
||||
|
@ -95,9 +95,9 @@ func handlePull(repo abaputils.Repository, pullConnectionDetails abaputils.Conne
|
||||
logString := repo.GetPullLogString()
|
||||
errorString := "Pull of the " + logString + " failed on the ABAP system"
|
||||
|
||||
log.Entry().Info("-------------------------")
|
||||
abaputils.AddDefaultDashedLine()
|
||||
log.Entry().Info("Start pulling the " + logString)
|
||||
log.Entry().Info("-------------------------")
|
||||
abaputils.AddDefaultDashedLine()
|
||||
|
||||
uriConnectionDetails, err := triggerPull(repo, pullConnectionDetails, client)
|
||||
if err != nil {
|
||||
@ -183,7 +183,7 @@ func checkPullRepositoryConfiguration(options abapEnvironmentPullGitRepoOptions)
|
||||
}
|
||||
|
||||
func finishPullLogs() {
|
||||
log.Entry().Info("-------------------------")
|
||||
abaputils.AddDefaultDashedLine()
|
||||
log.Entry().Info("All repositories were pulled successfully")
|
||||
}
|
||||
|
||||
|
@ -186,11 +186,20 @@ func HandleHTTPError(resp *http.Response, err error, message string, connectionD
|
||||
if resp == nil {
|
||||
// Response is nil in case of a timeout
|
||||
log.Entry().WithError(err).WithField("ABAP Endpoint", connectionDetails.URL).Error("Request failed")
|
||||
|
||||
match, _ := regexp.MatchString(".*EOF$", err.Error())
|
||||
if match {
|
||||
AddDefaultDashedLine()
|
||||
log.Entry().Infof("%s", "A connection could not be established to the ABAP system. The typical root cause is the network configuration (firewall, IP allowlist, etc.)")
|
||||
AddDefaultDashedLine()
|
||||
}
|
||||
|
||||
log.Entry().Infof("Error message: %s,", err.Error())
|
||||
} else {
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
log.Entry().WithField("StatusCode", resp.Status).Error(message)
|
||||
log.Entry().WithField("StatusCode", resp.Status).WithField("User", connectionDetails.User).WithField("URL", connectionDetails.URL).Error(message)
|
||||
|
||||
errorText, errorCode, parsingError := GetErrorDetailsFromResponse(resp)
|
||||
if parsingError != nil {
|
||||
@ -239,6 +248,16 @@ func ConvertTime(logTimeStamp string) time.Time {
|
||||
return t
|
||||
}
|
||||
|
||||
// AddDefaultDashedLine adds 25 dashes
|
||||
func AddDefaultDashedLine() {
|
||||
log.Entry().Infof(strings.Repeat("-", 25))
|
||||
}
|
||||
|
||||
// AddDefaultDebugLine adds 25 dashes in debug
|
||||
func AddDebugDashedLine() {
|
||||
log.Entry().Debugf(strings.Repeat("-", 25))
|
||||
}
|
||||
|
||||
/*******************************
|
||||
* Structs for specific steps *
|
||||
*******************************/
|
||||
|
@ -13,6 +13,7 @@ import (
|
||||
"github.com/SAP/jenkins-library/pkg/log"
|
||||
"github.com/SAP/jenkins-library/pkg/mock"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus/hooks/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@ -350,4 +351,21 @@ func TestHandleHTTPError(t *testing.T) {
|
||||
assert.EqualError(t, err, fmt.Sprintf("%s", receivedErr.Error()))
|
||||
log.Entry().Info(err.Error())
|
||||
})
|
||||
|
||||
t.Run("EOF Error", func(t *testing.T) {
|
||||
|
||||
message := "Custom Error Message"
|
||||
errorValue := "Received Error EOF"
|
||||
receivedErr := errors.New(errorValue)
|
||||
|
||||
_, hook := test.NewNullLogger()
|
||||
log.RegisterHook(hook)
|
||||
|
||||
err := HandleHTTPError(nil, receivedErr, message, ConnectionDetailsHTTP{})
|
||||
|
||||
assert.EqualError(t, err, fmt.Sprintf("%s", receivedErr.Error()))
|
||||
assert.Equal(t, 5, len(hook.Entries), "Expected a different number of entries")
|
||||
assert.Equal(t, `A connection could not be established to the ABAP system. The typical root cause is the network configuration (firewall, IP allowlist, etc.)`, hook.AllEntries()[2].Message, "Expected a different message")
|
||||
hook.Reset()
|
||||
})
|
||||
}
|
||||
|
@ -62,7 +62,7 @@ func PrintLogs(repositoryName string, connectionDetails ConnectionDetailsHTTP, c
|
||||
for _, logEntryForDetails := range entity.ToLogOverview.Results {
|
||||
printLog(logEntryForDetails, connectionDetails, client)
|
||||
}
|
||||
log.Entry().Infof("-------------------------")
|
||||
AddDefaultDashedLine()
|
||||
|
||||
return
|
||||
}
|
||||
@ -151,14 +151,14 @@ func allLogsHaveBeenPrinted(entity LogProtocolResults, page int, err error) bool
|
||||
func printHeader(logEntry LogResultsV2) {
|
||||
if logEntry.Status != `Success` {
|
||||
log.Entry().Infof("\n")
|
||||
log.Entry().Infof("-------------------------")
|
||||
AddDefaultDashedLine()
|
||||
log.Entry().Infof("%s (%v)", logEntry.Name, ConvertTime(logEntry.Timestamp))
|
||||
log.Entry().Infof("-------------------------")
|
||||
AddDefaultDashedLine()
|
||||
} else {
|
||||
log.Entry().Debugf("\n")
|
||||
log.Entry().Debugf("-------------------------")
|
||||
AddDebugDashedLine()
|
||||
log.Entry().Debugf("%s (%v)", logEntry.Name, ConvertTime(logEntry.Timestamp))
|
||||
log.Entry().Debugf("-------------------------")
|
||||
AddDebugDashedLine()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user