refactor: Extract catchNotFound storage helper#1072
Merged
jirispilka merged 1 commit intoJul 10, 2026
Conversation
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
9 tasks
RobertCrupa
approved these changes
Jul 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.catchblock plus a near-verbatim comment explaining an Apify SDK quirk: list methods (listItems(),listKeys()) throwApifyApiErroron 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>tostorage_helpers.ts: resolves to the value, returnsnullon a 404, rethrows any other error. Each call site wraps its list call incatchNotFound(...)and keeps its existingif (!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
utils/home — rejected; the quirk is storage-SDK-specific andstorage_helpers.tsalready exists as the shared home.Scope note
Only these three files duplicate the pattern.
get_dataset.ts/get_key_value_store_record.tscall.get()/.getRecord(), which already soft-catch 404 in the SDK — nothing to convert.Verification
test:unit959 passed / 2 skipped (targeted 404 tests: 41 passed), format no-op.🤖 Generated with Claude Code
https://claude.ai/code/session_016pXZvhEoE6Lz3DpBSL3n1Y
Generated by Claude Code