Skip to content

Commit 08254f1

Browse files
somanshreddyclaude
andcommitted
cli: namespace CLI-originated download/encode error codes with cli_ prefix
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 1fcdae3 commit 08254f1

2 files changed

Lines changed: 19 additions & 19 deletions

File tree

cmd/heygen/video_download.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func newVideoDownloadCmd(ctx *cmdContext) *cobra.Command {
105105
})
106106
if err != nil {
107107
return &clierrors.CLIError{
108-
Code: "internal_error",
108+
Code: "cli_response_encode_error",
109109
Message: fmt.Sprintf("failed to encode response: %v", err),
110110
Hint: "Please report this CLI bug with the command you ran.",
111111
ExitCode: clierrors.ExitGeneral,
@@ -128,7 +128,7 @@ func extractAssetURL(raw json.RawMessage, videoID string, info assetInfo) (strin
128128
}
129129
if err := json.Unmarshal(raw, &resp); err != nil {
130130
return "", &clierrors.CLIError{
131-
Code: "response_parse_error",
131+
Code: "cli_response_parse_error",
132132
Message: "failed to parse the video response",
133133
Hint: "The API response could not be parsed. Retry; if it persists, report it (possible CLI/API mismatch).",
134134
ExitCode: clierrors.ExitGeneral,
@@ -191,7 +191,7 @@ func downloadFile(ctx context.Context, videoURL, dest string) error {
191191
req, err := http.NewRequestWithContext(ctx, http.MethodGet, videoURL, nil)
192192
if err != nil {
193193
return &clierrors.CLIError{
194-
Code: "response_parse_error",
194+
Code: "cli_response_parse_error",
195195
Message: fmt.Sprintf("the download URL returned by the API is unusable: %v", err),
196196
Hint: "Re-fetch a fresh URL: heygen video get <video_id>",
197197
ExitCode: clierrors.ExitGeneral,
@@ -214,14 +214,14 @@ func downloadFile(ctx context.Context, videoURL, dest string) error {
214214
// re-fetch); any other status is the asset host (our storage/CDN) failing.
215215
if resp.StatusCode == http.StatusForbidden || resp.StatusCode == http.StatusNotFound {
216216
return &clierrors.CLIError{
217-
Code: "download_url_expired",
217+
Code: "cli_download_url_expired",
218218
Message: fmt.Sprintf("download link expired or unavailable (HTTP %d)", resp.StatusCode),
219219
Hint: "This download link has expired. Re-fetch a fresh URL: heygen video get <video_id>",
220220
ExitCode: clierrors.ExitGeneral,
221221
}
222222
}
223223
return &clierrors.CLIError{
224-
Code: "asset_download_failed",
224+
Code: "cli_download_failed",
225225
Message: fmt.Sprintf("download failed with HTTP %d", resp.StatusCode),
226226
Hint: "The asset host returned an error fetching the file. This is usually transient — retry shortly.",
227227
ExitCode: clierrors.ExitGeneral,
@@ -234,7 +234,7 @@ func downloadFile(ctx context.Context, videoURL, dest string) error {
234234
tmp, err := os.CreateTemp(dir, ".heygen-download-*.tmp")
235235
if err != nil {
236236
return &clierrors.CLIError{
237-
Code: "file_io_error",
237+
Code: "cli_file_io_error",
238238
Message: fmt.Sprintf("failed to create temp file in %q: %v", dir, err),
239239
Hint: "Could not write locally. Check the destination path and free disk space.",
240240
ExitCode: clierrors.ExitGeneral,
@@ -247,7 +247,7 @@ func downloadFile(ctx context.Context, videoURL, dest string) error {
247247
if copyErr != nil {
248248
_ = os.Remove(tmpPath)
249249
return &clierrors.CLIError{
250-
Code: "download_interrupted",
250+
Code: "cli_download_interrupted",
251251
Message: fmt.Sprintf("download interrupted: %v", copyErr),
252252
Hint: "The transfer was cut off. Retry; the partial file was cleaned up.",
253253
ExitCode: clierrors.ExitGeneral,
@@ -256,7 +256,7 @@ func downloadFile(ctx context.Context, videoURL, dest string) error {
256256
if closeErr != nil {
257257
_ = os.Remove(tmpPath)
258258
return &clierrors.CLIError{
259-
Code: "file_io_error",
259+
Code: "cli_file_io_error",
260260
Message: fmt.Sprintf("failed to finalize download: %v", closeErr),
261261
Hint: "Could not finalize the file locally. Check free disk space.",
262262
ExitCode: clierrors.ExitGeneral,
@@ -269,7 +269,7 @@ func downloadFile(ctx context.Context, videoURL, dest string) error {
269269
if err := os.Rename(tmpPath, dest); err != nil {
270270
_ = os.Remove(tmpPath)
271271
return &clierrors.CLIError{
272-
Code: "file_io_error",
272+
Code: "cli_file_io_error",
273273
Message: fmt.Sprintf("failed to move download to %q: %v", dest, err),
274274
Hint: "Could not write to the destination path. Check permissions and free disk space.",
275275
ExitCode: clierrors.ExitGeneral,

cmd/heygen/video_download_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -406,16 +406,16 @@ func TestVideoDownload_DownloadFails(t *testing.T) {
406406
if res.ExitCode != 1 {
407407
t.Fatalf("ExitCode = %d, want 1\nstderr: %s", res.ExitCode, res.Stderr)
408408
}
409-
if !strings.Contains(res.Stderr, `"code":"asset_download_failed"`) {
410-
t.Fatalf("stderr should carry asset_download_failed (asset-host 5xx):\n%s", res.Stderr)
409+
if !strings.Contains(res.Stderr, `"code":"cli_download_failed"`) {
410+
t.Fatalf("stderr should carry cli_download_failed (asset-host 5xx):\n%s", res.Stderr)
411411
}
412412
if _, err := os.Stat(dest); !os.IsNotExist(err) {
413413
t.Fatalf("expected no output file, stat err = %v", err)
414414
}
415415
}
416416

417417
// A presigned asset URL that 403s or 404s is expired/revoked — a client-side
418-
// download_url_expired, distinct from the asset host failing (asset_download_failed).
418+
// cli_download_url_expired, distinct from the asset host failing (cli_download_failed).
419419
func TestVideoDownload_ExpiredURL(t *testing.T) {
420420
for _, status := range []int{http.StatusForbidden, http.StatusNotFound} {
421421
t.Run(fmt.Sprintf("HTTP_%d", status), func(t *testing.T) {
@@ -444,8 +444,8 @@ func TestVideoDownload_ExpiredURL(t *testing.T) {
444444
if res.ExitCode != 1 {
445445
t.Fatalf("ExitCode = %d, want 1\nstderr: %s", res.ExitCode, res.Stderr)
446446
}
447-
if !strings.Contains(res.Stderr, `"code":"download_url_expired"`) {
448-
t.Fatalf("stderr should carry download_url_expired (HTTP %d on presigned URL):\n%s", status, res.Stderr)
447+
if !strings.Contains(res.Stderr, `"code":"cli_download_url_expired"`) {
448+
t.Fatalf("stderr should carry cli_download_url_expired (HTTP %d on presigned URL):\n%s", status, res.Stderr)
449449
}
450450
if !strings.Contains(res.Stderr, "video get") {
451451
t.Fatalf("expired-URL hint should point to re-fetching via video get:\n%s", res.Stderr)
@@ -455,7 +455,7 @@ func TestVideoDownload_ExpiredURL(t *testing.T) {
455455
}
456456

457457
// The video-get response failing to parse, or yielding an unusable download URL,
458-
// classifies as response_parse_error (not the opaque error code).
458+
// classifies as cli_response_parse_error (not the opaque error code).
459459
func TestVideoDownload_ResponseParseError(t *testing.T) {
460460
t.Run("malformed video-get JSON", func(t *testing.T) {
461461
dest := filepath.Join(t.TempDir(), "x.mp4")
@@ -473,8 +473,8 @@ func TestVideoDownload_ResponseParseError(t *testing.T) {
473473
if res.ExitCode != 1 {
474474
t.Fatalf("ExitCode = %d, want 1\nstderr: %s", res.ExitCode, res.Stderr)
475475
}
476-
if !strings.Contains(res.Stderr, `"code":"response_parse_error"`) {
477-
t.Fatalf("stderr should carry response_parse_error:\n%s", res.Stderr)
476+
if !strings.Contains(res.Stderr, `"code":"cli_response_parse_error"`) {
477+
t.Fatalf("stderr should carry cli_response_parse_error:\n%s", res.Stderr)
478478
}
479479
})
480480

@@ -495,8 +495,8 @@ func TestVideoDownload_ResponseParseError(t *testing.T) {
495495
if res.ExitCode != 1 {
496496
t.Fatalf("ExitCode = %d, want 1\nstderr: %s", res.ExitCode, res.Stderr)
497497
}
498-
if !strings.Contains(res.Stderr, `"code":"response_parse_error"`) {
499-
t.Fatalf("stderr should carry response_parse_error for an unusable URL:\n%s", res.Stderr)
498+
if !strings.Contains(res.Stderr, `"code":"cli_response_parse_error"`) {
499+
t.Fatalf("stderr should carry cli_response_parse_error for an unusable URL:\n%s", res.Stderr)
500500
}
501501
})
502502
}

0 commit comments

Comments
 (0)