Skip to content

feat: add ArtifactsError type definitions#6710

Open
dmmulroy wants to merge 2 commits intocloudflare:mainfrom
dmmulroy:dillon/artifacts-error-types
Open

feat: add ArtifactsError type definitions#6710
dmmulroy wants to merge 2 commits intocloudflare:mainfrom
dmmulroy:dillon/artifacts-error-types

Conversation

@dmmulroy
Copy link
Copy Markdown

What

Add ArtifactsError and ArtifactsErrorCode TypeScript type definitions to the Artifacts binding.

Changes

types/defines/artifacts.d.ts:

  • ArtifactsErrorCode — union of all error code strings (ALREADY_EXISTS, NOT_FOUND, INVALID_INPUT, etc.)
  • ArtifactsError — extends Error with readonly code: ArtifactsErrorCode and readonly numericCode: number
  • @throws {ArtifactsError} annotations on all Artifacts and ArtifactsRepo methods

Follows the same interface extends Error pattern used by StreamError, ImagesError, and MediaError.

Snapshot

generated-snapshot/ needs regeneration — CI will flag the diff and produce the updated snapshot artifact. I was unable to run just generate-types locally due to a bazel cache issue unrelated to this change.

Add typed error surface for the Artifacts binding:

- ArtifactsErrorCode: union of all error code strings
- ArtifactsError: extends Error with readonly code, numericCode
- @throws annotations on all Artifacts and ArtifactsRepo methods

Follows the same interface-extends-Error pattern used by StreamError,
ImagesError, and MediaError.

Note: generated-snapshot/ needs regeneration via `just generate-types`.
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.55%. Comparing base (a99ab15) to head (5b45871).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6710      +/-   ##
==========================================
- Coverage   66.57%   66.55%   -0.02%     
==========================================
  Files         402      402              
  Lines      115911   115856      -55     
  Branches    19407    19406       -1     
==========================================
- Hits        77167    77110      -57     
+ Misses      27165    27161       -4     
- Partials    11579    11585       +6     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dmmulroy dmmulroy marked this pull request as ready for review May 1, 2026 21:22
@dmmulroy dmmulroy requested review from a team as code owners May 1, 2026 21:22
@dmmulroy dmmulroy requested a review from jamesopstad May 1, 2026 21:22
@jamesopstad
Copy link
Copy Markdown
Contributor

/bonk review this PR

Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI-generated review (by OpenCode). May contain inaccuracies — please verify.

Summary: The types look well-structured and follow existing Cloudflare binding error patterns. A few items to address:

  • The generated-snapshot/ files should not be hand-edited — CI should regenerate them. The manual edits will likely be overwritten and may cause the snapshot CI check to fail until just generate-types is run.
  • Several error codes in ArtifactsErrorCode are never referenced in any @throws annotation. Either they can be thrown (and should be documented) or they're unused.
  • Minor: the import() method documents INVALID_INPUT for bad URLs, but a more specific INVALID_URL code exists in the union and seems like a better fit.

Comment on lines +149 to +161
type ArtifactsErrorCode =
| 'ALREADY_EXISTS'
| 'NOT_FOUND'
| 'IMPORT_IN_PROGRESS'
| 'FORK_IN_PROGRESS'
| 'INVALID_INPUT'
| 'INVALID_REPO_NAME'
| 'INVALID_TTL'
| 'INVALID_URL'
| 'REMOTE_AUTH_REQUIRED'
| 'UPSTREAM_UNAVAILABLE'
| 'MEMORY_LIMIT'
| 'INTERNAL_ERROR';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Five of the twelve error codes — INVALID_URL, REMOTE_AUTH_REQUIRED, UPSTREAM_UNAVAILABLE, MEMORY_LIMIT, INTERNAL_ERROR — are defined in the union but never appear in any @throws annotation. A few questions:

  1. Can any method throw INTERNAL_ERROR? If so, it might be worth adding a blanket note (e.g., on the Artifacts interface JSDoc) that any method may throw with INTERNAL_ERROR.
  2. INVALID_URL seems like a natural fit for import() — is INVALID_INPUT used there instead, or can both be thrown?
  3. REMOTE_AUTH_REQUIRED and UPSTREAM_UNAVAILABLE presumably relate to import() or fork() with external remotes — consider documenting those.

Having undocumented codes in the union is fine if they're needed for instanceof/code matching, but the discoverability is much better with @throws annotations.

* @param params Source URL and optional branch/depth, plus target name and options.
* @returns Repo metadata with initial token.
* @throws {ArtifactsError} with code `INVALID_REPO_NAME` if the target name is invalid.
* @throws {ArtifactsError} with code `INVALID_INPUT` if the source URL is not valid HTTPS.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INVALID_INPUT is documented here for invalid source URLs, but the ArtifactsErrorCode union includes a more specific INVALID_URL code. Is INVALID_INPUT the code actually returned by the runtime for bad URLs, or should this be INVALID_URL?

},
): Promise<ArtifactsCreateRepoResult>;
}
// ── Error types ──────────────────────────────────────────────────────────────
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per repo convention (types/AGENTS.md, AGENTS.md): files in generated-snapshot/ should not be edited directly — they are overwritten by just generate-types. The correct workflow is to change only types/defines/artifacts.d.ts and let CI regenerate the snapshots (or run just generate-types locally).

The PR description mentions a local bazel cache issue prevented running generation. That's understandable, but the hand-edited snapshots may diverge from what the generator actually produces (e.g., quote style, blank line handling, comment formatting). CI should flag this; if it does, the snapshot commit can be dropped and regenerated in CI.

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented May 5, 2026

Review posted successfully. Here's a summary of the feedback I left on PR #6710:

3 inline comments:

  1. types/defines/artifacts.d.ts:149-161 — Five error codes (INVALID_URL, REMOTE_AUTH_REQUIRED, UPSTREAM_UNAVAILABLE, MEMORY_LIMIT, INTERNAL_ERROR) are in the ArtifactsErrorCode union but never appear in any @throws annotation. Asked whether they should be documented on specific methods, especially import() and fork().

  2. types/defines/artifacts.d.ts:210 — The import() method documents INVALID_INPUT for bad source URLs, but a more specific INVALID_URL code exists in the union. Flagged a possible mismatch.

  3. types/generated-snapshot/experimental/index.d.ts:11894 — Per repo convention, generated-snapshot/ files should not be hand-edited. The PR description acknowledges a local bazel issue prevented running just generate-types, but the manual edits may diverge from generator output. CI should flag this.

github run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants