fix(text): pass error (not texture) to SDF font 'failed' handler#53
Merged
Conversation
EventEmitter invokes listeners as (target, data), so the error payload from a Texture's 'failed' event is the second argument. The SDF font loader's handler read it as a single parameter, so it rejected the font-load promise and logged with the Texture instance instead of the actual TextureError. The font still failed correctly, but the rejection value and console output were the wrong object, hurting diagnostics for SDF font load failures. The bogus `(error: Error)` annotation also masked it, since `on()`'s listener type is `(target: any, data: any)`. Fix the handler to `(_target, error: TextureError)` and add a regression test that drives loadFont to the failed branch and asserts it rejects with the emitted error rather than the emitting texture. Co-Authored-By: Claude Opus 4.8 (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.
Problem
EventEmitterinvokes listeners as(target, data)— every listener's first argument is the emitting object, and the payload is the second argument (EventEmitter.emitcallslistener(this, data)).Texture.setState('failed')emits the error as that second argument (this.emit('failed', this._error)), and the canonical handler type isTextureFailedEventHandler = (target: any, error: TextureError) => void.The SDF font loader's
failedhandler instead read it as a single parameter:So at runtime
errorwas the Texture instance, not the error. The font-load promise still rejected (control flow was fine), but it rejected with — and logged — the texture object instead of the actualTextureError, hurting diagnostics for SDF font load failures.TypeScript didn't catch it because
on()'s listener signature is(target: any, data: any), so the bogus(error: Error)annotation was silently accepted.Every other texture-event listener in the codebase already uses the correct shape (
CoreNode.onTextureFailed = (_, error) =>,SubTexture.onParentTxFailed = (target, error) =>); this was the lone exception.Fix
(_target, error: TextureError).Error→ the realTextureError).loadFontto the failed branch and asserts it rejects with the emitted error (and logs it), not the emitting texture. Verified the test fails on the old code and passes on the fix.Scope
One-line behavioral fix + test. No API changes. Independent of any other in-flight work.
🤖 Generated with Claude Code