Skip to content

Commit 8461c8e

Browse files
committed
make errors conformant to golangs standard
1 parent a8701d4 commit 8461c8e

File tree

7 files changed

+25
-25
lines changed

7 files changed

+25
-25
lines changed

cmd/admin_auth_ldap.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func parseLdapConfig(c *cli.Command, config *ldap.Source) error {
257257
if c.IsSet("security-protocol") {
258258
p, ok := findLdapSecurityProtocolByName(c.String("security-protocol"))
259259
if !ok {
260-
return fmt.Errorf("Unknown security protocol name: %s", c.String("security-protocol"))
260+
return fmt.Errorf("unknown security protocol name: %s", c.String("security-protocol"))
261261
}
262262
config.SecurityProtocol = p
263263
}
@@ -359,7 +359,7 @@ func (a *authService) getAuthSource(ctx context.Context, c *cli.Command, authTyp
359359
}
360360

361361
if authSource.Type != authType {
362-
return nil, fmt.Errorf("Invalid authentication type. expected: %s, actual: %s", authType.String(), authSource.Type.String())
362+
return nil, fmt.Errorf("invalid authentication type. expected: %s, actual: %s", authType.String(), authSource.Type.String())
363363
}
364364

365365
return authSource, nil

cmd/admin_auth_ldap_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func TestAddLdapBindDn(t *testing.T) {
134134
"--user-filter", "(memberOf=cn=user-group,ou=example,dc=domain,dc=org)",
135135
"--email-attribute", "mail",
136136
},
137-
errMsg: "Unknown security protocol name: zzzzz",
137+
errMsg: "unknown security protocol name: zzzzz",
138138
},
139139
// case 3
140140
{
@@ -351,7 +351,7 @@ func TestAddLdapSimpleAuth(t *testing.T) {
351351
"--email-attribute", "mail",
352352
"--user-dn", "cn=%s,ou=Users,dc=domain,dc=org",
353353
},
354-
errMsg: "Unknown security protocol name: zzzzz",
354+
errMsg: "unknown security protocol name: zzzzz",
355355
},
356356
// case 3
357357
{
@@ -861,7 +861,7 @@ func TestUpdateLdapBindDn(t *testing.T) {
861861
"--id", "1",
862862
"--security-protocol", "xxxxx",
863863
},
864-
errMsg: "Unknown security protocol name: xxxxx",
864+
errMsg: "unknown security protocol name: xxxxx",
865865
},
866866
// case 22
867867
{
@@ -880,7 +880,7 @@ func TestUpdateLdapBindDn(t *testing.T) {
880880
Type: auth.OAuth2,
881881
Cfg: &ldap.Source{},
882882
},
883-
errMsg: "Invalid authentication type. expected: LDAP (via BindDN), actual: OAuth2",
883+
errMsg: "invalid authentication type. expected: LDAP (via BindDN), actual: OAuth2",
884884
},
885885
// case 24
886886
{
@@ -1252,7 +1252,7 @@ func TestUpdateLdapSimpleAuth(t *testing.T) {
12521252
"--id", "1",
12531253
"--security-protocol", "xxxxx",
12541254
},
1255-
errMsg: "Unknown security protocol name: xxxxx",
1255+
errMsg: "unknown security protocol name: xxxxx",
12561256
},
12571257
// case 18
12581258
{
@@ -1271,7 +1271,7 @@ func TestUpdateLdapSimpleAuth(t *testing.T) {
12711271
Type: auth.PAM,
12721272
Cfg: &ldap.Source{},
12731273
},
1274-
errMsg: "Invalid authentication type. expected: LDAP (simple auth), actual: PAM",
1274+
errMsg: "invalid authentication type. expected: LDAP (simple auth), actual: PAM",
12751275
},
12761276
// case 20
12771277
{

cmd/admin_user_delete.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,11 @@ func runDeleteUser(ctx context.Context, c *cli.Command) error {
7373
return err
7474
}
7575
if c.IsSet("username") && user.LowerName != strings.ToLower(strings.TrimSpace(c.String("username"))) {
76-
return fmt.Errorf("The user %s who has email %s does not match the provided username %s", user.Name, c.String("email"), c.String("username"))
76+
return fmt.Errorf("the user %s who has email %s does not match the provided username %s", user.Name, c.String("email"), c.String("username"))
7777
}
7878

7979
if c.IsSet("id") && user.ID != c.Int64("id") {
80-
return fmt.Errorf("The user %s does not match the provided id %d", user.Name, c.Int64("id"))
80+
return fmt.Errorf("the user %s does not match the provided id %d", user.Name, c.Int64("id"))
8181
}
8282

8383
return user_service.DeleteUser(ctx, user, c.Bool("purge"))

cmd/admin_user_delete_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ func TestAdminUserDeleteFailure(t *testing.T) {
7676
{
7777
name: "user exists but provided username does not match",
7878
args: []string{"delete", "--email", "testuser@gitea.local", "--username", "wrongusername"},
79-
expectedErr: "The user testuser who has email testuser@gitea.local does not match the provided username wrongusername",
79+
expectedErr: "the user testuser who has email testuser@gitea.local does not match the provided username wrongusername",
8080
},
8181
{
8282
name: "user exists but provided id does not match",
8383
args: []string{"delete", "--username", "testuser", "--id", "999"},
84-
expectedErr: "The user testuser does not match the provided id 999",
84+
expectedErr: "the user testuser does not match the provided id 999",
8585
},
8686
{
8787
name: "no required flags are provided",

cmd/cert.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,17 @@ func runCert(_ context.Context, c *cli.Command) error {
118118
case "P521":
119119
priv, err = ecdsa.GenerateKey(elliptic.P521(), rand.Reader)
120120
default:
121-
err = fmt.Errorf("Unrecognized elliptic curve: %q", c.String("ecdsa-curve"))
121+
err = fmt.Errorf("unrecognized elliptic curve: %q", c.String("ecdsa-curve"))
122122
}
123123
if err != nil {
124-
return fmt.Errorf("Failed to generate private key: %w", err)
124+
return fmt.Errorf("failed to generate private key: %w", err)
125125
}
126126

127127
var notBefore time.Time
128128
if startDate := c.String("start-date"); startDate != "" {
129129
notBefore, err = time.Parse("Jan 2 15:04:05 2006", startDate)
130130
if err != nil {
131-
return fmt.Errorf("Failed to parse creation date %w", err)
131+
return fmt.Errorf("failed to parse creation date %w", err)
132132
}
133133
} else {
134134
notBefore = time.Now()
@@ -139,7 +139,7 @@ func runCert(_ context.Context, c *cli.Command) error {
139139
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
140140
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
141141
if err != nil {
142-
return fmt.Errorf("Failed to generate serial number: %w", err)
142+
return fmt.Errorf("failed to generate serial number: %w", err)
143143
}
144144

145145
template := x509.Certificate{
@@ -172,34 +172,34 @@ func runCert(_ context.Context, c *cli.Command) error {
172172

173173
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, publicKey(priv), priv)
174174
if err != nil {
175-
return fmt.Errorf("Failed to create certificate: %w", err)
175+
return fmt.Errorf("failed to create certificate: %w", err)
176176
}
177177

178178
certOut, err := os.Create(c.String("out"))
179179
if err != nil {
180-
return fmt.Errorf("Failed to open cert.pem for writing: %w", err)
180+
return fmt.Errorf("failed to open cert.pem for writing: %w", err)
181181
}
182182
err = pem.Encode(certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
183183
if err != nil {
184-
return fmt.Errorf("Failed to encode certificate: %w", err)
184+
return fmt.Errorf("failed to encode certificate: %w", err)
185185
}
186186
err = certOut.Close()
187187
if err != nil {
188-
return fmt.Errorf("Failed to write cert: %w", err)
188+
return fmt.Errorf("failed to write cert: %w", err)
189189
}
190190
fmt.Fprintln(c.Writer, "Written cert.pem")
191191

192192
keyOut, err := os.OpenFile(c.String("keyout"), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)
193193
if err != nil {
194-
return fmt.Errorf("Failed to open key.pem for writing: %w", err)
194+
return fmt.Errorf("failed to open key.pem for writing: %w", err)
195195
}
196196
err = pem.Encode(keyOut, pemBlockForKey(priv))
197197
if err != nil {
198-
return fmt.Errorf("Failed to encode key: %w", err)
198+
return fmt.Errorf("failed to encode key: %w", err)
199199
}
200200
err = keyOut.Close()
201201
if err != nil {
202-
return fmt.Errorf("Failed to write key: %w", err)
202+
return fmt.Errorf("failed to write key: %w", err)
203203
}
204204
fmt.Fprintln(c.Writer, "Written key.pem")
205205
return nil

cmd/cert_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ func TestCertCommandFailures(t *testing.T) {
8686
"--host", "localhost",
8787
"--ecdsa-curve", "invalid-curve",
8888
},
89-
errMsg: "Unrecognized elliptic curve",
89+
errMsg: "unrecognized elliptic curve",
9090
},
9191
{
9292
name: "Key generation failure",

cmd/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ func runHookPostReceive(ctx context.Context, c *cli.Command) error {
312312

313313
// First of all run update-server-info no matter what
314314
if _, _, err := git.NewCommand("update-server-info").RunStdString(ctx, nil); err != nil {
315-
return fmt.Errorf("Failed to call 'git update-server-info': %w", err)
315+
return fmt.Errorf("failed to call 'git update-server-info': %w", err)
316316
}
317317

318318
// Now if we're an internal don't do anything else

0 commit comments

Comments
 (0)