# fix(search): resolve unpadded hymn numbers falling back to placeholder lyrics in expert entry

**URL:** <https://forum.rodydavis.dev/t/fix-search-resolve-unpadded-hymn-numbers-falling-back-to-placeholder-lyrics-in-expert-entry/354>\
**Category:** Issues & Bugs\
**Tags:** bug, external-user, migrated\
**Created:** [November 17, 2026, 3:36pm UTC](https://forum.rodydavis.dev/t/fix-search-resolve-unpadded-hymn-numbers-falling-back-to-placeholder-lyrics-in-expert-entry/354 "2026-11-17T15:36:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://forum.rodydavis.dev/images/discourse-logo-sketch-small.png) [@system](https://forum.rodydavis.dev/u/system)\
**Post date:** [November 17, 2026, 3:36pm UTC](https://forum.rodydavis.dev/t/fix-search-resolve-unpadded-hymn-numbers-falling-back-to-placeholder-lyrics-in-expert-entry/354/1 "2026-11-17T15:36:06Z")

</div>

Tried to use expert input of two songs, 40;44 and both pulled up lyrics for Amazing Grace AND O How I Love Jesus

---

<div class="post-metadata">

**Author:** ![rodydavis](https://forum.rodydavis.dev/user_avatar/forum.rodydavis.dev/rodydavis/32/8_2.png) [@rodydavis](https://forum.rodydavis.dev/u/rodydavis)\
**Post date:** [November 18, 2026, 11:02am UTC](https://forum.rodydavis.dev/t/fix-search-resolve-unpadded-hymn-numbers-falling-back-to-placeholder-lyrics-in-expert-entry/354/2 "2026-11-18T11:02:08Z")

</div>

### Automated Issue Triage

#### Root Cause Analysis

When entering unpadded hymn numbers such as `40;44` in the Omnibox expert entry:

1. `ExpertEntryController.parse("40;44")` (`packages/sfw_desktop/lib/utils/expert_entry_parser.dart`) parses two commands: `("40", null)` and `("44", null)`, and `OmniboxCommandDialog._submit()` (`packages/sfw_desktop/lib/widgets/omnibox_command_dialog.dart`) invokes `_executeScriptString("40;44")`.
2. In `_executeScriptString()` (`packages/sfw_desktop/lib/main.dart`, lines 335–343), catalog lookup uses strict string equality:

```dart
final hymn = catalog.firstWhere(
  (h) => h.number.trim().toLowerCase() == cmd.toLowerCase(),
  orElse: () => HymnMetadata(
    id: 'hymn_$cmd',
    number: cmd,
    hymnalId: 'rjs',
    title: 'Hymn $cmd',
  ),
);

```

3. Catalog numbers in `packages/sfw_desktop/assets/metadata.json` are zero-padded to 3 digits (e.g., `"040"` for _God’s Love and Power_, `"044"` for _To God Be the Glory_). Because `"040" != "40"` and `"044" != "44"`, `firstWhere` falls back to `orElse` and synthesizes dummy `HymnMetadata` entries with IDs `hymn_40` and `hymn_44`.
4. `fetchHymnPortionData()` (`packages/sfw_desktop/lib/services/hymn_service.dart`, lines 270–339) fails to fetch FlatBuffers for those nonexistent IDs from CDN/API and falls back to `generateFallbackFlatbuffer()` (lines 149–191), which returns hardcoded placeholder lyrics (`Verse 1`: _“Amazing grace! How sweet the sound…”_, `Chorus`: _“O how I love Jesus…”_) and caches them in Drift (`appDatabase.hymnsCache`).

#### Relevant Codebase Files & Symbols

- `packages/sfw_desktop/lib/main.dart` — `_executeScriptString` (strict `h.number` equality & `orElse` synthetic `HymnMetadata` fallback)
- `packages/sfw_desktop/lib/utils/hymn_search_utils.dart` — `searchHymns` / `_calculateMatchScore` (already supports zero-padded & numeric number matching via `int.tryParse` and suffix extraction)
- `packages/sfw_desktop/lib/services/hymn_service.dart` — `fetchHymnPortionData`, `generateFallbackFlatbuffer`
- `packages/sfw_desktop/lib/widgets/omnibox_command_dialog.dart` — `OmniboxCommandDialog._submit`
- `packages/sfw_desktop/lib/utils/expert_entry_parser.dart` — `ExpertEntryController.parse`
- `packages/sfw_desktop/assets/metadata.json` — zero-padded hymn number catalog entries (`"040"`, `"044"`, etc.)

#### Implementation Notes

- Update the hymn lookup in `_executeScriptString()` to match normalized/numeric hymn numbers (e.g., exact string match first, then numeric/unpadded match using the same logic as `searchHymns()` in `hymn_search_utils.dart`), rather than requiring leading zeros.
- When a hymn number genuinely does not exist in the catalog, avoid silently generating and caching `generateFallbackFlatbuffer()` placeholder lyrics under `hymn_<cmd>` in `appDatabase.hymnsCache`; instead surface a warning or skip unresolved entries.

#### Metadata Updates Applied

- **Title** : Updated to `fix(search): resolve unpadded hymn numbers falling back to placeholder lyrics in expert entry`
- **Labels** : Confirmed `bug` (`8`) and added `external user` (`54`)

---

<div class="post-metadata">

**Author:** ![system](https://forum.rodydavis.dev/images/discourse-logo-sketch-small.png) [@system](https://forum.rodydavis.dev/u/system)\
**Post date:** [November 28, 2026, 12:59am UTC](https://forum.rodydavis.dev/t/fix-search-resolve-unpadded-hymn-numbers-falling-back-to-placeholder-lyrics-in-expert-entry/354/3 "2026-11-28T00:59:14Z")

</div>

Closed on November 28, 2026, 12:59am UTC


