Skip to content

Commit 1875fe0

Browse files
authored
refactor!: Do not capitalize error strings (#3446)
BREAKING CHANGE: Some error strings are slightly modified - please do not rely on error text in general.
1 parent b8c2253 commit 1875fe0

File tree

8 files changed

+17
-15
lines changed

8 files changed

+17
-15
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ linters-settings:
6060
errorf: true
6161
strconcat: false
6262
revive:
63+
# Set below 0.8 to enable error-strings rule.
64+
confidence: 0.6
6365
rules:
6466
- name: blank-imports
6567
- name: bool-literal-in-expr

example/codespaces/newreposecretwithxcrypto/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func addRepoSecret(ctx context.Context, client *github.Client, owner string, rep
134134
}
135135

136136
if _, err := client.Codespaces.CreateOrUpdateRepoSecret(ctx, owner, repo, encryptedSecret); err != nil {
137-
return fmt.Errorf("Codespaces.CreateOrUpdateRepoSecret returned error: %v", err)
137+
return fmt.Errorf("client.Codespaces.CreateOrUpdateRepoSecret returned error: %v", err)
138138
}
139139

140140
return nil
@@ -143,7 +143,7 @@ func addRepoSecret(ctx context.Context, client *github.Client, owner string, rep
143143
func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName string, secretValue string) (*github.EncryptedSecret, error) {
144144
decodedPublicKey, err := base64.StdEncoding.DecodeString(publicKey.GetKey())
145145
if err != nil {
146-
return nil, fmt.Errorf("base64.StdEncoding.DecodeString was unable to decode public key: %v", err)
146+
return nil, fmt.Errorf("unable to decode public key: %v", err)
147147
}
148148

149149
var boxKey [32]byte

example/codespaces/newusersecretwithxcrypto/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,17 @@ func addUserSecret(ctx context.Context, client *github.Client, secretName, secre
129129
}
130130

131131
if _, err := client.Codespaces.CreateOrUpdateUserSecret(ctx, encryptedSecret); err != nil {
132-
return fmt.Errorf("Codespaces.CreateOrUpdateUserSecret returned error: %v", err)
132+
return fmt.Errorf("client.Codespaces.CreateOrUpdateUserSecret returned error: %v", err)
133133
}
134134

135135
if owner != "" && repo != "" {
136136
r, _, err := client.Repositories.Get(ctx, owner, repo)
137137
if err != nil {
138-
return fmt.Errorf("Repositories.Get returned error: %v", err)
138+
return fmt.Errorf("client.Repositories.Get returned error: %v", err)
139139
}
140140
_, err = client.Codespaces.AddSelectedRepoToUserSecret(ctx, encryptedSecret.Name, r)
141141
if err != nil {
142-
return fmt.Errorf("Codespaces.AddSelectedRepoToUserSecret returned error: %v", err)
142+
return fmt.Errorf("client.Codespaces.AddSelectedRepoToUserSecret returned error: %v", err)
143143
}
144144
fmt.Printf("Added secret %q to %v/%v\n", secretName, owner, repo)
145145
}

example/newreposecretwithlibsodium/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func addRepoSecret(ctx context.Context, client *github.Client, owner string, rep
130130
}
131131

132132
if _, err := client.Actions.CreateOrUpdateRepoSecret(ctx, owner, repo, encryptedSecret); err != nil {
133-
return fmt.Errorf("Actions.CreateOrUpdateRepoSecret returned error: %v", err)
133+
return fmt.Errorf("client.Actions.CreateOrUpdateRepoSecret returned error: %v", err)
134134
}
135135

136136
return nil

example/newreposecretwithxcrypto/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func addRepoSecret(ctx context.Context, client *github.Client, owner string, rep
134134
}
135135

136136
if _, err := client.Actions.CreateOrUpdateRepoSecret(ctx, owner, repo, encryptedSecret); err != nil {
137-
return fmt.Errorf("Actions.CreateOrUpdateRepoSecret returned error: %v", err)
137+
return fmt.Errorf("client.Actions.CreateOrUpdateRepoSecret returned error: %v", err)
138138
}
139139

140140
return nil

github/github.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ func WithVersion(version string) RequestOption {
519519
// request body.
520520
func (c *Client) NewRequest(method, urlStr string, body interface{}, opts ...RequestOption) (*http.Request, error) {
521521
if !strings.HasSuffix(c.BaseURL.Path, "/") {
522-
return nil, fmt.Errorf("BaseURL must have a trailing slash, but %q does not", c.BaseURL)
522+
return nil, fmt.Errorf("baseURL must have a trailing slash, but %q does not", c.BaseURL)
523523
}
524524

525525
u, err := c.BaseURL.Parse(urlStr)
@@ -565,7 +565,7 @@ func (c *Client) NewRequest(method, urlStr string, body interface{}, opts ...Req
565565
// Body is sent with Content-Type: application/x-www-form-urlencoded.
566566
func (c *Client) NewFormRequest(urlStr string, body io.Reader, opts ...RequestOption) (*http.Request, error) {
567567
if !strings.HasSuffix(c.BaseURL.Path, "/") {
568-
return nil, fmt.Errorf("BaseURL must have a trailing slash, but %q does not", c.BaseURL)
568+
return nil, fmt.Errorf("baseURL must have a trailing slash, but %q does not", c.BaseURL)
569569
}
570570

571571
u, err := c.BaseURL.Parse(urlStr)
@@ -597,7 +597,7 @@ func (c *Client) NewFormRequest(urlStr string, body io.Reader, opts ...RequestOp
597597
// Relative URLs should always be specified without a preceding slash.
598598
func (c *Client) NewUploadRequest(urlStr string, reader io.Reader, size int64, mediaType string, opts ...RequestOption) (*http.Request, error) {
599599
if !strings.HasSuffix(c.UploadURL.Path, "/") {
600-
return nil, fmt.Errorf("UploadURL must have a trailing slash, but %q does not", c.UploadURL)
600+
return nil, fmt.Errorf("uploadURL must have a trailing slash, but %q does not", c.UploadURL)
601601
}
602602
u, err := c.UploadURL.Parse(urlStr)
603603
if err != nil {

github/github_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ func TestErrorResponse_Is(t *testing.T) {
21802180
},
21812181
"errors have different types": {
21822182
wantSame: false,
2183-
otherError: errors.New("Github"),
2183+
otherError: errors.New("github"),
21842184
},
21852185
}
21862186

@@ -2250,7 +2250,7 @@ func TestRateLimitError_Is(t *testing.T) {
22502250
"errors have different types": {
22512251
wantSame: false,
22522252
err: err,
2253-
otherError: errors.New("Github"),
2253+
otherError: errors.New("github"),
22542254
},
22552255
}
22562256

@@ -2337,7 +2337,7 @@ func TestAbuseRateLimitError_Is(t *testing.T) {
23372337
"errors have different types": {
23382338
wantSame: false,
23392339
err: err,
2340-
otherError: errors.New("Github"),
2340+
otherError: errors.New("github"),
23412341
},
23422342
}
23432343

@@ -2369,7 +2369,7 @@ func TestAcceptedError_Is(t *testing.T) {
23692369
},
23702370
"errors have different types": {
23712371
wantSame: false,
2372-
otherError: errors.New("Github"),
2372+
otherError: errors.New("github"),
23732373
},
23742374
}
23752375

github/repos_rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ func (r *RepositoryRule) UnmarshalJSON(data []byte) error {
567567
default:
568568
r.Type = ""
569569
r.Parameters = nil
570-
return fmt.Errorf("RepositoryRule.Type %q is not yet implemented, unable to unmarshal (%#v)", repositoryRule.Type, repositoryRule)
570+
return fmt.Errorf("repositoryRule.Type %q is not yet implemented, unable to unmarshal (%#v)", repositoryRule.Type, repositoryRule)
571571
}
572572

573573
return nil

0 commit comments

Comments
 (0)