Skip to content

Commit

Permalink
Add details for EOF errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMieg committed Jul 3, 2023
1 parent 1befaa8 commit 6a9574a
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 19 deletions.
19 changes: 9 additions & 10 deletions cmd/abapEnvironmentCloneGitRepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions cmd/abapEnvironmentPullGitRepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -183,7 +183,7 @@ func checkPullRepositoryConfiguration(options abapEnvironmentPullGitRepoOptions)
}

func finishPullLogs() {
log.Entry().Info("-------------------------")
abaputils.AddDefaultDashedLine()
log.Entry().Info("All repositories were pulled successfully")
}

Expand Down
21 changes: 20 additions & 1 deletion pkg/abaputils/abaputils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 *
*******************************/
Expand Down
10 changes: 5 additions & 5 deletions pkg/abaputils/manageGitRepositoryUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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()
}
}

Expand Down

0 comments on commit 6a9574a

Please sign in to comment.