Skip to content

refactor: Extract catchNotFound storage helper#1072

Merged
jirispilka merged 1 commit into
masterfrom
claude/apify-mcp-quick-wins-fysrwa-catch-notfound
Jul 10, 2026
Merged

refactor: Extract catchNotFound storage helper#1072
jirispilka merged 1 commit into
masterfrom
claude/apify-mcp-quick-wins-fysrwa-catch-notfound

Conversation

@jirispilka

Copy link
Copy Markdown
Collaborator

Part of #1066 (checkbox: catchNotFound(promise) helper).

What we're solving

Three storage tools — get_dataset_items.ts, get_dataset_schema.ts, get_key_value_store_keys.ts — each inlined the same 404→null .catch block plus a near-verbatim comment explaining an Apify SDK quirk: list methods (listItems(), listKeys()) throw ApifyApiError on a missing storage, unlike .get()/.getStatistics()/.getRecord() which soft-catch 404. Tuning the logic or the explanation meant editing three places in sync.

How

Add a generic catchNotFound<T>(promise: Promise<T>): Promise<T | null> to storage_helpers.ts: resolves to the value, returns null on a 404, rethrows any other error. Each call site wraps its list call in catchNotFound(...) and keeps its existing if (!x) return respondUserError('… not found.') guard. The SDK-quirk explanation now lives once, in the helper's doc comment.

Behavior is unchanged — the existing 404 and non-404-rethrow unit tests for all three tools pass unmodified.

Alternatives considered

  • A generic utils/ home — rejected; the quirk is storage-SDK-specific and storage_helpers.ts already exists as the shared home.
  • Keeping a pointer comment at each call site — rejected; recreates the duplication being removed.

Scope note

Only these three files duplicate the pattern. get_dataset.ts/get_key_value_store_record.ts call .get()/.getRecord(), which already soft-catch 404 in the SDK — nothing to convert.

Verification

  • Oracle green: type-check clean, lint 0/0, check:agents passed, test:unit 959 passed / 2 skipped (targeted 404 tests: 41 passed), format no-op.
  • Scope: 4 source files, no test changes.

🤖 Generated with Claude Code

https://claude.ai/code/session_016pXZvhEoE6Lz3DpBSL3n1Y


Generated by Claude Code

What we're solving: three storage tools (get_dataset_items,
get_dataset_schema, get_key_value_store_keys) each inlined the same
404-to-null .catch block plus a near-verbatim comment explaining an Apify
SDK quirk (list methods throw on a missing storage, unlike .get()/.getRecord()
which soft-catch 404). Tuning the logic or the explanation meant editing
three places in sync.

How: add a generic catchNotFound<T>(promise) helper to storage_helpers.ts
that resolves to the value, returns null on a 404, and rethrows any other
error. Each call site wraps its list call in catchNotFound(...) and keeps
its existing "not found" guard. The SDK-quirk explanation now lives once,
in the helper's doc comment. Behavior is unchanged; existing 404 and
non-404 unit tests pass unmodified.

Alternatives considered: a generic utils/ home (rejected — the quirk is
storage-SDK-specific and storage_helpers.ts already exists); keeping a
pointer comment at each call site (rejected — recreates the duplication).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016pXZvhEoE6Lz3DpBSL3n1Y
@jirispilka jirispilka marked this pull request as ready for review July 9, 2026 21:41
@jirispilka jirispilka requested a review from MQ37 July 9, 2026 21:41
@jirispilka jirispilka requested review from RobertCrupa and removed request for MQ37 July 10, 2026 07:12
@jirispilka jirispilka merged commit 86c2694 into master Jul 10, 2026
13 checks passed
@jirispilka jirispilka deleted the claude/apify-mcp-quick-wins-fysrwa-catch-notfound branch July 10, 2026 08:48
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.

4 participants