Skip to content

Commit 2ee8171

Browse files
author
Tobias Meinhardt
committed
Refactoring of error checking & logging
1 parent c17de60 commit 2ee8171

27 files changed

+427
-403
lines changed

git/logging.go

Lines changed: 121 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -18,123 +18,183 @@ func NewLoggingService(s Service) Service {
1818
}
1919

2020
// SetCICDOrigin for pipeline
21-
func (s loggingService) SetCICDOrigin(origin string) (err error) {
22-
defer l.Log().WithFields(logrus.Fields{
23-
"origin": origin,
24-
"error": err,
25-
}).Info()
21+
func (s loggingService) SetCICDOrigin(origin string) (stdout, stderr bytes.Buffer, err error) {
22+
defer func() {
23+
l.Log().WithFields(logrus.Fields{
24+
"origin": origin,
25+
"stdout": stdout.String(),
26+
"stderr": stderr.String(),
27+
"error": err,
28+
}).Info()
29+
}()
2630
return s.next.SetCICDOrigin(origin)
2731
}
2832

2933
// GitRepoPath returns the path to the root with the .git folder
30-
func (s loggingService) GitRepoPath() (_ string, err error) {
31-
defer l.Log().WithFields(logrus.Fields{
32-
"error": err,
33-
}).Info()
34+
func (s loggingService) GitRepoPath() (repoPath string, stdout, stderr bytes.Buffer, err error) {
35+
defer func() {
36+
l.Log().WithFields(logrus.Fields{
37+
"repoPath": repoPath,
38+
"stdout": stdout.String(),
39+
"stderr": stderr.String(),
40+
"error": err,
41+
}).Info()
42+
}()
3443
return s.next.GitRepoPath()
3544
}
3645

3746
// CurrentBranch returns the current branch name
38-
func (s loggingService) CurrentBranch() (_ glow.Branch, err error) {
39-
defer l.Log().WithFields(logrus.Fields{
40-
"error": err,
41-
}).Info()
47+
func (s loggingService) CurrentBranch() (branch glow.Branch, stdout, stderr bytes.Buffer, err error) {
48+
defer func() {
49+
l.Log().WithFields(logrus.Fields{
50+
"branchName": branch.BranchName(),
51+
"stdout": stdout.String(),
52+
"stderr": stderr.String(),
53+
"error": err,
54+
}).Info()
55+
}()
4256
return s.next.CurrentBranch()
4357
}
4458

4559
// BranchList returns a list of avalilable branches
46-
func (s loggingService) BranchList() (_ []glow.Branch, err error) {
47-
defer l.Log().WithFields(logrus.Fields{
48-
"error": err,
49-
}).Info()
60+
func (s loggingService) BranchList() (_ []glow.Branch, stdout, stderr bytes.Buffer, err error) {
61+
defer func() {
62+
l.Log().WithFields(logrus.Fields{
63+
"stdout": stdout.String(),
64+
"stderr": stderr.String(),
65+
"error": err,
66+
}).Info()
67+
}()
5068
return s.next.BranchList()
5169
}
5270

5371
// Fetch changes
54-
func (s loggingService) Fetch() (err error) {
55-
defer l.Log().WithFields(logrus.Fields{
56-
"error": err,
57-
}).Info()
72+
func (s loggingService) Fetch() (stdout, stderr bytes.Buffer, err error) {
73+
defer func() {
74+
l.Log().WithFields(logrus.Fields{
75+
"stdout": stdout.String(),
76+
"stderr": stderr.String(),
77+
"error": err,
78+
}).Info()
79+
}()
5880
return s.next.Fetch()
5981
}
6082

6183
// Add all changes
62-
func (s loggingService) AddAll() (err error) {
63-
defer l.Log().WithFields(logrus.Fields{
64-
"error": err,
65-
}).Info()
84+
func (s loggingService) AddAll() (stdout, stderr bytes.Buffer, err error) {
85+
defer func() {
86+
l.Log().WithFields(logrus.Fields{
87+
"stdout": stdout.String(),
88+
"stderr": stderr.String(),
89+
"error": err,
90+
}).Info()
91+
}()
6692
return s.next.AddAll()
6793
}
6894

6995
// Stash all changes
70-
func (s loggingService) Stash() (err error) {
71-
defer l.Log().WithFields(logrus.Fields{
72-
"error": err,
73-
}).Info()
96+
func (s loggingService) Stash() (stdout, stderr bytes.Buffer, err error) {
97+
defer func() {
98+
l.Log().WithFields(logrus.Fields{
99+
"stdout": stdout.String(),
100+
"stderr": stderr.String(),
101+
"error": err,
102+
}).Info()
103+
}()
74104
return s.next.Stash()
75105
}
76106

77107
// Pop all stashed changes
78108
func (s loggingService) StashPop() (stdout, stderr bytes.Buffer, err error) {
79-
defer l.Log().WithFields(logrus.Fields{
80-
"error": err,
81-
}).Info()
109+
defer func() {
110+
l.Log().WithFields(logrus.Fields{
111+
"stdout": stdout.String(),
112+
"stderr": stderr.String(),
113+
"error": err,
114+
}).Info()
115+
}()
82116
return s.next.StashPop()
83117
}
84118

85119
// Commit added changes
86-
func (s loggingService) Commit(message string) (err error) {
87-
defer l.Log().WithFields(logrus.Fields{
88-
"error": err,
89-
}).Info()
120+
func (s loggingService) Commit(message string) (stdout, stderr bytes.Buffer, err error) {
121+
defer func() {
122+
l.Log().WithFields(logrus.Fields{
123+
"stdout": stdout.String(),
124+
"stderr": stderr.String(),
125+
"error": err,
126+
}).Info()
127+
}()
90128
return s.next.Commit(message)
91129
}
92130

93131
// Push changes
94132
func (s loggingService) Push(setUpstream bool) (stdout, stderr bytes.Buffer, err error) {
95-
defer l.Log().WithFields(logrus.Fields{
96-
"stdout": stdout.String(),
97-
"stderr": stderr.String(),
98-
"error": err,
99-
}).Info()
133+
defer func() {
134+
l.Log().WithFields(logrus.Fields{
135+
"stdout": stdout.String(),
136+
"stderr": stderr.String(),
137+
"error": err,
138+
}).Info()
139+
}()
100140
return s.next.Push(setUpstream)
101141
}
102142

103143
// Create a new branch
104-
func (s loggingService) Create(b glow.Branch, skipChecks bool) (err error) {
105-
defer l.Log().WithFields(logrus.Fields{
106-
"error": err,
107-
}).Info()
144+
func (s loggingService) Create(b glow.Branch, skipChecks bool) (stdout, stderr bytes.Buffer, err error) {
145+
defer func() {
146+
l.Log().WithFields(logrus.Fields{
147+
"stdout": stdout.String(),
148+
"stderr": stderr.String(),
149+
"error": err,
150+
}).Info()
151+
}()
108152
return s.next.Create(b, skipChecks)
109153
}
110154

111155
// Checkout a branch
112-
func (s loggingService) Checkout(b glow.Branch) (err error) {
113-
defer l.Log().WithFields(logrus.Fields{
114-
"error": err,
115-
}).Info()
156+
func (s loggingService) Checkout(b glow.Branch) (stdout, stderr bytes.Buffer, err error) {
157+
defer func() {
158+
l.Log().WithFields(logrus.Fields{
159+
"stdout": stdout.String(),
160+
"stderr": stderr.String(),
161+
"error": err,
162+
}).Info()
163+
}()
116164
return s.next.Checkout(b)
117165
}
118166

119167
// CleanupBranches removes all unused branches
120-
func (s loggingService) CleanupBranches(cleanupGone, cleanupUntracked bool) (err error) {
121-
defer l.Log().WithFields(logrus.Fields{
122-
"error": err,
123-
}).Info()
168+
func (s loggingService) CleanupBranches(cleanupGone, cleanupUntracked bool) (stdout, stderr bytes.Buffer, err error) {
169+
defer func() {
170+
l.Log().WithFields(logrus.Fields{
171+
"stdout": stdout.String(),
172+
"stderr": stderr.String(),
173+
"error": err,
174+
}).Info()
175+
}()
124176
return s.next.CleanupBranches(cleanupGone, cleanupUntracked)
125177
}
126178

127179
// CleanupTags removes tags from local repo
128-
func (s loggingService) CleanupTags(cleanupUntracked bool) (err error) {
129-
defer l.Log().WithFields(logrus.Fields{
130-
"error": err,
131-
}).Info()
180+
func (s loggingService) CleanupTags(cleanupUntracked bool) (stdout, stderr bytes.Buffer, err error) {
181+
defer func() {
182+
l.Log().WithFields(logrus.Fields{
183+
"stdout": stdout.String(),
184+
"stderr": stderr.String(),
185+
"error": err,
186+
}).Info()
187+
}()
132188
return s.next.CleanupTags(cleanupUntracked)
133189
}
134190

135-
func (s loggingService) RemoteBranchExists(branchName string) (err error) {
136-
defer l.Log().WithFields(logrus.Fields{
137-
"error": err,
138-
}).Info()
191+
func (s loggingService) RemoteBranchExists(branchName string) (stdout, stderr bytes.Buffer, err error) {
192+
defer func() {
193+
l.Log().WithFields(logrus.Fields{
194+
"stdout": stdout.String(),
195+
"stderr": stderr.String(),
196+
"error": err,
197+
}).Info()
198+
}()
139199
return s.next.RemoteBranchExists(branchName)
140200
}

0 commit comments

Comments
 (0)