aboutsummaryrefslogtreecommitdiffstats
path: root/models/asymkey
diff options
context:
space:
mode:
authordelvh <leon@kske.dev>2022-10-24 21:29:17 +0200
committerGitHub <noreply@github.com>2022-10-24 20:29:17 +0100
commit0ebb45cfe7606adf021ad359d6fbfcefc54360a5 (patch)
tree541b75d083213e93bbbfadbdc5d560c739543903 /models/asymkey
parent7c11a73833f3aa9783015e5e13871d3c298d3ef6 (diff)
downloadgitea-0ebb45cfe7606adf021ad359d6fbfcefc54360a5.tar.gz
gitea-0ebb45cfe7606adf021ad359d6fbfcefc54360a5.zip
Replace all instances of fmt.Errorf(%v) with fmt.Errorf(%w) (#21551)
Found using `find . -type f -name '*.go' -print -exec vim {} -c ':%s/fmt\.Errorf(\(.*\)%v\(.*\)err/fmt.Errorf(\1%w\2err/g' -c ':wq' \;` Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Andrew Thornton <art27@cantab.net> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Diffstat (limited to 'models/asymkey')
-rw-r--r--models/asymkey/gpg_key.go2
-rw-r--r--models/asymkey/ssh_key.go2
-rw-r--r--models/asymkey/ssh_key_deploy.go2
-rw-r--r--models/asymkey/ssh_key_fingerprint.go2
-rw-r--r--models/asymkey/ssh_key_parse.go22
-rw-r--r--models/asymkey/ssh_key_principals.go2
6 files changed, 16 insertions, 16 deletions
diff --git a/models/asymkey/gpg_key.go b/models/asymkey/gpg_key.go
index 78dc453e0d..83774533aa 100644
--- a/models/asymkey/gpg_key.go
+++ b/models/asymkey/gpg_key.go
@@ -226,7 +226,7 @@ func DeleteGPGKey(doer *user_model.User, id int64) (err error) {
if IsErrGPGKeyNotExist(err) {
return nil
}
- return fmt.Errorf("GetPublicKeyByID: %v", err)
+ return fmt.Errorf("GetPublicKeyByID: %w", err)
}
// Check if user has access to delete this key.
diff --git a/models/asymkey/ssh_key.go b/models/asymkey/ssh_key.go
index 9f95bb5baf..7ed4ad6b3f 100644
--- a/models/asymkey/ssh_key.go
+++ b/models/asymkey/ssh_key.go
@@ -130,7 +130,7 @@ func AddPublicKey(ownerID int64, name, content string, authSourceID int64) (*Pub
LoginSourceID: authSourceID,
}
if err = addKey(ctx, key); err != nil {
- return nil, fmt.Errorf("addKey: %v", err)
+ return nil, fmt.Errorf("addKey: %w", err)
}
return key, committer.Commit()
diff --git a/models/asymkey/ssh_key_deploy.go b/models/asymkey/ssh_key_deploy.go
index fd8388e61d..d5c981da47 100644
--- a/models/asymkey/ssh_key_deploy.go
+++ b/models/asymkey/ssh_key_deploy.go
@@ -151,7 +151,7 @@ func AddDeployKey(repoID int64, name, content string, readOnly bool) (*DeployKey
pkey.Content = content
pkey.Name = name
if err = addKey(ctx, pkey); err != nil {
- return nil, fmt.Errorf("addKey: %v", err)
+ return nil, fmt.Errorf("addKey: %w", err)
}
}
diff --git a/models/asymkey/ssh_key_fingerprint.go b/models/asymkey/ssh_key_fingerprint.go
index 747a7e6473..788d58dbab 100644
--- a/models/asymkey/ssh_key_fingerprint.go
+++ b/models/asymkey/ssh_key_fingerprint.go
@@ -95,7 +95,7 @@ func CalcFingerprint(publicKeyContent string) (string, error) {
log.Info("%s", publicKeyContent)
return "", err
}
- return "", fmt.Errorf("%s: %v", fnName, err)
+ return "", fmt.Errorf("%s: %w", fnName, err)
}
return fp, nil
}
diff --git a/models/asymkey/ssh_key_parse.go b/models/asymkey/ssh_key_parse.go
index 3f52a4e9e0..2462310ed9 100644
--- a/models/asymkey/ssh_key_parse.go
+++ b/models/asymkey/ssh_key_parse.go
@@ -44,7 +44,7 @@ const ssh2keyStart = "---- BEGIN SSH2 PUBLIC KEY ----"
func extractTypeFromBase64Key(key string) (string, error) {
b, err := base64.StdEncoding.DecodeString(key)
if err != nil || len(b) < 4 {
- return "", fmt.Errorf("invalid key format: %v", err)
+ return "", fmt.Errorf("invalid key format: %w", err)
}
keyLength := int(binary.BigEndian.Uint32(b))
@@ -85,7 +85,7 @@ func parseKeyString(content string) (string, error) {
t, err := extractTypeFromBase64Key(keyContent)
if err != nil {
- return "", fmt.Errorf("extractTypeFromBase64Key: %v", err)
+ return "", fmt.Errorf("extractTypeFromBase64Key: %w", err)
}
keyType = t
} else {
@@ -104,14 +104,14 @@ func parseKeyString(content string) (string, error) {
var pk rsa.PublicKey
_, err2 := asn1.Unmarshal(block.Bytes, &pk)
if err2 != nil {
- return "", fmt.Errorf("failed to parse DER encoded public key as either PKIX or PEM RSA Key: %v %v", err, err2)
+ return "", fmt.Errorf("failed to parse DER encoded public key as either PKIX or PEM RSA Key: %v %w", err, err2)
}
pub = &pk
}
sshKey, err := ssh.NewPublicKey(pub)
if err != nil {
- return "", fmt.Errorf("unable to convert to ssh public key: %v", err)
+ return "", fmt.Errorf("unable to convert to ssh public key: %w", err)
}
content = string(ssh.MarshalAuthorizedKey(sshKey))
}
@@ -138,7 +138,7 @@ func parseKeyString(content string) (string, error) {
// If keyType is not given, extract it from content. If given, validate it.
t, err := extractTypeFromBase64Key(keyContent)
if err != nil {
- return "", fmt.Errorf("extractTypeFromBase64Key: %v", err)
+ return "", fmt.Errorf("extractTypeFromBase64Key: %w", err)
}
if len(keyType) == 0 {
keyType = t
@@ -149,7 +149,7 @@ func parseKeyString(content string) (string, error) {
// Finally we need to check whether we can actually read the proposed key:
_, _, _, _, err := ssh.ParseAuthorizedKey([]byte(keyType + " " + keyContent + " " + keyComment))
if err != nil {
- return "", fmt.Errorf("invalid ssh public key: %v", err)
+ return "", fmt.Errorf("invalid ssh public key: %w", err)
}
return keyType + " " + keyContent + " " + keyComment, nil
}
@@ -191,7 +191,7 @@ func CheckPublicKeyString(content string) (_ string, err error) {
keyType, length, err = SSHKeyGenParsePublicKey(content)
}
if err != nil {
- return "", fmt.Errorf("%s: %v", fnName, err)
+ return "", fmt.Errorf("%s: %w", fnName, err)
}
log.Trace("Key info [native: %v]: %s-%d", setting.SSH.StartBuiltinServer, keyType, length)
@@ -220,7 +220,7 @@ func SSHNativeParsePublicKey(keyLine string) (string, int, error) {
if strings.Contains(err.Error(), "ssh: unknown key algorithm") {
return "", 0, ErrKeyUnableVerify{err.Error()}
}
- return "", 0, fmt.Errorf("ParsePublicKey: %v", err)
+ return "", 0, fmt.Errorf("ParsePublicKey: %w", err)
}
// The ssh library can parse the key, so next we find out what key exactly we have.
@@ -267,12 +267,12 @@ func SSHNativeParsePublicKey(keyLine string) (string, int, error) {
func writeTmpKeyFile(content string) (string, error) {
tmpFile, err := os.CreateTemp(setting.SSH.KeyTestPath, "gitea_keytest")
if err != nil {
- return "", fmt.Errorf("TempFile: %v", err)
+ return "", fmt.Errorf("TempFile: %w", err)
}
defer tmpFile.Close()
if _, err = tmpFile.WriteString(content); err != nil {
- return "", fmt.Errorf("WriteString: %v", err)
+ return "", fmt.Errorf("WriteString: %w", err)
}
return tmpFile.Name(), nil
}
@@ -281,7 +281,7 @@ func writeTmpKeyFile(content string) (string, error) {
func SSHKeyGenParsePublicKey(key string) (string, int, error) {
tmpName, err := writeTmpKeyFile(key)
if err != nil {
- return "", 0, fmt.Errorf("writeTmpKeyFile: %v", err)
+ return "", 0, fmt.Errorf("writeTmpKeyFile: %w", err)
}
defer func() {
if err := util.Remove(tmpName); err != nil {
diff --git a/models/asymkey/ssh_key_principals.go b/models/asymkey/ssh_key_principals.go
index 7a5c234f6f..e0d407af35 100644
--- a/models/asymkey/ssh_key_principals.go
+++ b/models/asymkey/ssh_key_principals.go
@@ -51,7 +51,7 @@ func AddPrincipalKey(ownerID int64, content string, authSourceID int64) (*Public
LoginSourceID: authSourceID,
}
if err = db.Insert(ctx, key); err != nil {
- return nil, fmt.Errorf("addKey: %v", err)
+ return nil, fmt.Errorf("addKey: %w", err)
}
if err = committer.Commit(); err != nil {