Skip to content

Commit 81bf39e

Browse files
authored
fix(repohub): implement Error() for custom errors (#196)
The Error() method was not implemented for custom errors in repohub, so when a caller uses it, we end up with a segfault. This fixes it by implementing that method.
1 parent b7dd592 commit 81bf39e

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

repohub/pkg/fetcher/fetcher.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,6 @@ func (f *Fetcher) Sync(index int, totalRepoCount int, r *models.Repository) bool
118118
quarantinedReason = string(gitrekt.QuarantineReasonCloneTimeout)
119119
}
120120

121-
if _, ok := err.(*gitrekt.AuthTimeoutError); ok {
122-
f.putRepoInQuarantine(repo, gitrekt.QuarantineReasonAuthTimeout)
123-
124-
quarantined = true
125-
quarantinedReason = string(gitrekt.QuarantineReasonAuthTimeout)
126-
}
127-
128121
if _, ok := err.(*gitrekt.AuthFailedError); ok {
129122
f.putRepoInQuarantine(repo, gitrekt.QuarantineReasonNotFound)
130123

repohub/pkg/gitrekt/errors.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,27 @@
11
package gitrekt
22

3-
type NotFoundError struct{ error }
4-
type AuthFailedError struct{ error }
3+
import "fmt"
54

6-
type TimeoutError struct{ error }
7-
type AuthTimeoutError struct{ error }
5+
type NotFoundError struct {
6+
Output string
7+
}
8+
9+
func (e *NotFoundError) Error() string {
10+
return fmt.Sprintf("repository not found: %s", e.Output)
11+
}
12+
13+
type AuthFailedError struct {
14+
Output string
15+
}
16+
17+
func (e *AuthFailedError) Error() string {
18+
return fmt.Sprintf("authentication failed: %s", e.Output)
19+
}
20+
21+
type TimeoutError struct {
22+
Output string
23+
}
24+
25+
func (e *TimeoutError) Error() string {
26+
return fmt.Sprintf("timeout: %s", e.Output)
27+
}

repohub/pkg/gitrekt/update_or_clone.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,17 +227,17 @@ func (o *UpdateOrCloneOperation) gitRemoteConfig() error {
227227

228228
func (o *UpdateOrCloneOperation) parseError(output []byte, err error) error {
229229
if strings.Contains(string(output), "remote: Repository not found") {
230-
return &NotFoundError{}
230+
return &NotFoundError{Output: string(output)}
231231
}
232232

233233
if strings.Contains(string(output), "fatal: Authentication failed") {
234-
return &AuthFailedError{}
234+
return &AuthFailedError{Output: string(output)}
235235
}
236236

237237
if exiterr, ok := err.(*exec.ExitError); ok {
238238
if status, ok := exiterr.Sys().(syscall.WaitStatus); ok {
239239
if status.ExitStatus() == -1 && strings.Contains(err.Error(), "killed") {
240-
return &TimeoutError{}
240+
return &TimeoutError{Output: string(output)}
241241
}
242242
}
243243
}

0 commit comments

Comments
 (0)