fix(error-handler): coerce apiContext->key to public_key string#85
Merged
Merged
Conversation
ErrorHandler::handleException()/handleError() bound $this->apiContext->key
directly into the KyteError.api_key string column. Api.php sets
$this->key = new ModelObject(KyteAPIKey) — so mysqli_stmt::execute()
threw "Object of class Kyte\Core\ModelObject could not be converted
to string" *inside* the error handler. The secondary fatal swallowed
the original error and surfaced to clients as a blank HTTP 500.
Pre-existing ErrorHandler tests set context->key = null, missing the
ModelObject path entirely. That's why the regression shipped in
v4.4.0 and v4.4.1.
Fix: extract the scalar public_key string for logging:
'api_key' => isset($this->apiContext->key->public_key)
? (string)$this->apiContext->key->public_key : null
Falls back to null when ->key is unset or the ModelObject hasn't been
retrieved. public_key is the audit-relevant value the column was
designed to hold.
Regression test ErrorHandlerSensitivityTest::
testApiContextKeyAsModelObjectLogsPublicKeyString exercises the real
ModelObject path with a created KyteAPIKey fixture.
All 182 tests pass.
Patch-level fix. No schema changes. Composer update is sufficient.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
/Sessionand/DoctorLensMarkup$this->apiContext->key(aModelObject) bound into a string column → mysqli secondary fatal → original error swallowedpublic_keystring for logging; falls back to null when ModelObject is unloadedWhy this slipped past tests
Pre-existing ErrorHandler tests set
$context->key = null, so they never exercised the ModelObject path. Regression test added.Test plan
testApiContextKeyAsModelObjectLogsPublicKeyStringcreates a realKyteAPIKeyModelObject, sets it ascontext->key, callshandleException, asserts the row writes withapi_keycontaining the public_key stringcontext->key = nullpath still works (no regression)Rollout
Patch v4.4.2. No schema changes. Customer impact severe — needs to ship asap.
🤖 Generated with Claude Code