Skip to content

Add error handling to SDK version function - #104

Merged
dru1x merged 3 commits into
mainfrom
90-correct-sdk-version-caching
Sep 6, 2026
Merged

Add error handling to SDK version function#104
dru1x merged 3 commits into
mainfrom
90-correct-sdk-version-caching

Conversation

@dru1x

@dru1x dru1x commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Summary

Adds error handling to cover edge cases that might result in the SDK version caching being skipped and fatal errors being emitted.

Changes

  • Replaced the function-local static $version cache with class-level self::$sdkVersion/self::$sdkVersionResolved properties, so "has this been computed" is tracked independently of the value itself.
  • A falsy/null result is now cached correctly instead of being recomputed on every call.
  • Extracted the resolution logic into resolveSdkVersion(string $composerJsonPath): string, guarded with is_readable() and a try/catch (Throwable) around the JSON_THROW_ON_ERROR decode and InstalledVersions::getPrettyVersion() call, falling back to 'unknown' instead of emitting a fatal error.

Testing

Added to tests/Unit/ExpoPushConnectorTest.php:

  • resolveSdkVersion() still resolves the real installed version from the project's actual composer.json.
  • Falls back to 'unknown' when composer.json is missing, or malformed.
  • sdkVersion() returns a cached value without recomputing, including a cached falsy value ('') — the direct regression test for the caching bug.

Related Issues

Fixes #90

@dru1x
dru1x requested a review from liamduckett August 27, 2026 16:12
@dru1x dru1x self-assigned this Aug 27, 2026
@dru1x dru1x added the bug Something isn't working label Aug 27, 2026
Comment thread src/ExpoPushConnector.php Outdated
Comment thread src/ExpoPushConnector.php Outdated
Comment thread tests/Unit/ExpoPushConnectorTest.php
@dru1x
dru1x requested a review from liamduckett September 4, 2026 12:16
@dru1x
dru1x merged commit 735b3e6 into main Sep 6, 2026
7 checks passed
@dru1x
dru1x deleted the 90-correct-sdk-version-caching branch September 6, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExpoPushConnector::sdkVersion() can fatal, and its version caching never actually caches

2 participants