Add Buhin#onMissing callback for surfacing missing references#16
Add Buhin#onMissing callback for surfacing missing references#16MasKusuno wants to merge 1 commit into
Conversation
Adds an optional `onMissing` handler to the `Buhin` class that is invoked when `search` is called with a name not registered in the store. This allows callers to surface data inconsistencies that would otherwise be silently dropped by the engine — for example, when building fonts from large dumps where a missing buhin causes downstream `99:` instructions to disappear without any warning. The handler may return a string (used as the lookup result) or undefined (falls back to the default empty string). Throwing from the handler is also supported for fail-fast use cases. Defaults to `null`, so existing callers see no behavior change. Refs kurgm#14
Quantitative validation in a downstream font buildI gave the new SetupThe pipeline pushes the entire GlyphWiki dump (~2.5M entries) into I patched our local copy of Numbers
Two findings worth sharing:
Implications for the APIThe original PR description framed this purely as a diagnostic hook ("surface data inconsistencies"). The validation above shows it doubles as a clean recovery mechanism: returning a string from the handler lets callers patch missing references without having to traverse and rewrite the dump beforehand. In other words, Happy to address review feedback whenever you have time. Thanks again for the suggestion in #14 that motivated the API! |
Summary
This PR addresses #14 by adding an opt-in
onMissingcallback to theBuhinclass, following the API design you suggested.API
search(name)is unchanged whenonMissingisnull(the default). When a handler is set andnameis absent from the store:undefined(or nothing), the default""fallback is preserved.onMissingis not invoked for names that are present in the store, even if their stored value is"".Example
Why this is non-breaking
null, sosearchbehaves identically to today's implementation when callers don't set it.searchis unchanged; only its internal lookup path gains the optional callback step.BuhinMissingHandleris a new exported type; existing imports are unaffected.Tests
test/index.jsgains aBuhin#onMissingblock covering:onMissing === null, missing name returns"").""takes precedence over the handler.99:target surfaces throughonMissingduringmakeGlyph.Existing tests continue to pass.
Note on the
name@NcorrectionThank you for the follow-up clarification — I had indeed conflated revision suffixes with variant siblings. I'll be revisiting our downstream pre-processing logic separately; the engine-side improvement here is independent of that misunderstanding and remains valuable on its own.
Refs #14