Skip to content

Commit 43b71dd

Browse files
refactor(alpine): remove manual [ERROR]/[WARN]/[HINT] prefixes, use log library levels
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent a544177 commit 43b71dd

3 files changed

Lines changed: 19 additions & 18 deletions

File tree

artifactory/commands/alpine/apkcommand.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package alpine
22

33
import (
4+
"errors"
45
"fmt"
56
"net/url"
67
"os"
@@ -98,7 +99,8 @@ func (apkCmd *ApkCommand) ServerDetails() (*config.ServerDetails, error) {
9899
func (apkCmd *ApkCommand) Run() error {
99100
apkPath, err := exec.LookPath("apk")
100101
if err != nil {
101-
return fmt.Errorf("[ERROR] 'apk' binary not found. Is this an Alpine Linux environment?")
102+
log.Error("'apk' binary not found. Is this an Alpine Linux environment?")
103+
return errors.New("'apk' binary not found. Is this an Alpine Linux environment?")
102104
}
103105

104106
needsAuth := buildInfoSubcmds[apkCmd.commandName] || authOnlySubcmds[apkCmd.commandName]
@@ -113,7 +115,7 @@ func (apkCmd *ApkCommand) Run() error {
113115
if needsBuildInfo {
114116
preSnapshot, err = biUtils.ListInstalledPackages()
115117
if err != nil {
116-
log.Warn("[WARN] Cannot list installed packages — Build Info not captured:", err)
118+
log.Warn("Cannot list installed packages — Build Info not captured:", err)
117119
needsBuildInfo = false
118120
}
119121
}
@@ -127,7 +129,7 @@ func (apkCmd *ApkCommand) Run() error {
127129
if needsBuildInfo {
128130
cacheDir, err = io.CreateTempDir()
129131
if err != nil {
130-
log.Warn("[WARN] Could not create temp cache dir — checksums may be incomplete:", err)
132+
log.Warn("Could not create temp cache dir — checksums may be incomplete:", err)
131133
} else {
132134
defer func() { _ = os.RemoveAll(cacheDir) }()
133135
}
@@ -161,10 +163,9 @@ func (apkCmd *ApkCommand) buildSubprocessEnv(injectAuth bool) ([]string, error)
161163

162164
if apkCmd.serverDetails == nil {
163165
if apkCmd.username != "" || apkCmd.password != "" {
164-
log.Warn("[WARN] --user/--password provided but no server URL is known. " +
165-
"Use --server-id to select a configured server so HTTP_AUTH can be injected.")
166+
log.Warn("--user/--password provided but no server URL is known. Use --server-id to select a configured server so HTTP_AUTH can be injected.")
166167
} else {
167-
log.Warn("[WARN] No JFrog server configured — skipping HTTP_AUTH injection. Run: jf c add")
168+
log.Warn("No JFrog server configured — skipping HTTP_AUTH injection. Run: jf c add")
168169
}
169170
return env, nil
170171
}
@@ -218,7 +219,7 @@ func emitSignatureHint(exitErr *exec.ExitError) {
218219
}
219220
for _, pattern := range sigPatterns {
220221
if strings.Contains(stderr, pattern) {
221-
log.Warn("[HINT] Signature verification failed. Fix: jf apk config --server-id <id> --repo <repo> --apply")
222+
log.Warn("Signature verification failed. Fix: jf apk config --server-id <id> --repo <repo> --apply")
222223
return
223224
}
224225
}
@@ -239,7 +240,7 @@ func (apkCmd *ApkCommand) collectBuildInfo(preSnapshot []biUtils.AlpinePackage,
239240

240241
buildObj, err := buildUtils.PrepareBuildPrerequisites(apkCmd.buildConfiguration)
241242
if err != nil {
242-
log.Warn("[WARN] Build Info publish failed:", err)
243+
log.Warn("Build Info publish failed:", err)
243244
return nil
244245
}
245246

@@ -252,7 +253,7 @@ func (apkCmd *ApkCommand) collectBuildInfo(preSnapshot []biUtils.AlpinePackage,
252253
alpineModule.SetCacheDir(cacheDir)
253254

254255
if err := alpineModule.CollectBuildInfo(); err != nil {
255-
log.Warn("[WARN] Build Info publish failed:", err)
256+
log.Warn("Build Info collection failed:", err)
256257
}
257258
return nil
258259
}

artifactory/commands/alpine/apkconfig.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ func (apkCmd *ApkConfigCommand) Run() error {
115115
// downloadRSAKey fetches the RSA public key from the Artifactory keypair API.
116116
func downloadRSAKey(endpoint string, creds resolvedCredentials) (string, error) {
117117
if creds.Username == "" && creds.Password == "" {
118-
return "", fmt.Errorf("[ERROR] No credentials found for this server. Run: jf c add")
118+
return "", fmt.Errorf("no credentials found for this server. Run: jf c add")
119119
}
120120

121121
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
@@ -133,11 +133,11 @@ func downloadRSAKey(endpoint string, creds resolvedCredentials) (string, error)
133133
switch resp.StatusCode {
134134
case http.StatusOK:
135135
case http.StatusNotFound:
136-
return "", fmt.Errorf("[WARN] No RSA key configured for %q. Use --allow-untrusted or configure a signing key in Artifactory", endpoint)
136+
return "", fmt.Errorf("no RSA key configured for %q. Use --allow-untrusted or configure a signing key in Artifactory", endpoint)
137137
case http.StatusUnauthorized:
138-
return "", fmt.Errorf("[ERROR] Access token expired or invalid. Run: jf c add")
138+
return "", fmt.Errorf("access token expired or invalid. Run: jf c add")
139139
case http.StatusForbidden:
140-
return "", fmt.Errorf("[ERROR] Access token lacks read permission on the repository")
140+
return "", fmt.Errorf("access token lacks read permission on the repository")
141141
default:
142142
return "", fmt.Errorf("unexpected HTTP %d from Artifactory RSA key endpoint", resp.StatusCode)
143143
}

artifactory/commands/alpine/apkupload.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (apkCmd *ApkUploadCommand) Run() error {
129129
log.Info("Upload successful.")
130130

131131
if err := apkCmd.setProperties(target, pkgName, pkgVersion, arch); err != nil {
132-
log.Warn("[WARN] Failed to set artifact properties:", err)
132+
log.Warn("Failed to set artifact properties:", err)
133133
}
134134

135135
collectBuildInfo, err := apkCmd.buildConfiguration.IsCollectBuildInfo()
@@ -138,7 +138,7 @@ func (apkCmd *ApkUploadCommand) Run() error {
138138
}
139139
if collectBuildInfo {
140140
if err := apkCmd.recordBuildInfoArtifact(filename, pkgName, pkgVersion, arch, fileDetails.Checksum); err != nil {
141-
log.Warn("[WARN] Build Info artifact recording failed:", err)
141+
log.Warn("Build Info artifact recording failed:", err)
142142
}
143143
}
144144
return nil
@@ -173,11 +173,11 @@ func (apkCmd *ApkUploadCommand) uploadFile(uploadURL string, creds resolvedCrede
173173
case http.StatusCreated, http.StatusOK:
174174
return nil
175175
case http.StatusUnauthorized:
176-
return fmt.Errorf("[ERROR] Access token expired or invalid. Run: jf c add")
176+
return fmt.Errorf("access token expired or invalid. Run: jf c add")
177177
case http.StatusForbidden:
178-
return fmt.Errorf("[ERROR] Insufficient permissions to deploy to repository %q", apkCmd.repoKey)
178+
return fmt.Errorf("insufficient permissions to deploy to repository %q", apkCmd.repoKey)
179179
case http.StatusConflict:
180-
return fmt.Errorf("[ERROR] Artifact already exists at the target path (repo policy blocks overwrite)")
180+
return fmt.Errorf("artifact already exists at the target path (repo policy blocks overwrite)")
181181
default:
182182
body, _ := io.ReadAll(resp.Body)
183183
return fmt.Errorf("upload failed with HTTP %d: %s", resp.StatusCode, string(body))

0 commit comments

Comments
 (0)