Skip to content

fix: drop non-string scalar aliases in metadata conversion - #382

Merged
RAIT-09 merged 2 commits into
devfrom
fix/frontmatter-alias-normalization
Aug 5, 2026
Merged

fix: drop non-string scalar aliases in metadata conversion#382
RAIT-09 merged 2 commits into
devfrom
fix/frontmatter-alias-normalization

Conversation

@RAIT-09

@RAIT-09 RAIT-09 commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Description

Follow-up to #377, covering the remaining CodeRabbit comment: the scalar branch of convertToMetadata() was still unfiltered, so a truthy non-string scalar (e.g. aliases: 42) leaked into NoteMetadata as [42].

Instead of patching that one branch, this centralizes frontmatter alias normalization into a single module-level helper (normalizeFrontmatterAliases) used by both searchNotes() and convertToMetadata() — the duplicated, slightly different normalization is what let the two sites drift apart in the first place. The helper takes unknown and proves stringness with a type predicate, which also removes the misleading as string[] | string | undefined casts (the root cause behind the crash in #354).

Also included:

Verified in Obsidian with the repro notes from #354 (aliases: [null, "TestAlias"], aliases: 42, and the trailing-colon YAML template): no crash, filtering narrows correctly, and normal alias search is unaffected. npm test passes (190/190).

Related issue

Follow-up to #377. Related: #354.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Refactor
  • Other

Checklist

  • npm run lint passes ("Use sentence case for UI text" errors are acceptable for brand names)
  • npm run build passes
  • Tested in Obsidian
  • Existing functionality still works
  • Documentation updated if needed

Testing environment

  • Agent: N/A (the change only affects the @-mention search path; no agent connection involved)
  • OS: macOS

Screenshots

N/A

Summary by CodeRabbit

  • Bug Fixes
    • Improved note search and metadata handling for aliases.
    • Consistently excludes malformed, empty, or unsupported alias values.

…lizer

Follow-up to #377: a truthy non-string scalar (e.g. aliases: 42) still
leaked into NoteMetadata. Centralize frontmatter alias normalization in
one helper used by both searchNotes and convertToMetadata.
@RAIT-09 RAIT-09 self-assigned this Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f904aea6-990e-4df8-bb5f-c25816164bbb

📥 Commits

Reviewing files that changed from the base of the PR and between 9266e15 and 0bc2a98.

📒 Files selected for processing (1)
  • src/services/vault-service.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/services/vault-service.ts

📝 Walkthrough

Walkthrough

This PR adds a shared helper to normalize frontmatter aliases. Note search and metadata conversion now use the same logic. Non-string and empty-string aliases are excluded.

Changes

Alias normalization flow

Layer / File(s) Summary
Shared alias normalization and usage
src/services/vault-service.ts
normalizeFrontmatterAliases converts frontmatter alias values into arrays of non-empty strings. searchNotes uses the helper for fuzzy-search fields. convertToMetadata uses the helper and exposes aliases only when valid strings remain.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Poem

🐇 Clean aliases hop in line,
Empty ones stay behind.
Search and metadata share the trail,
While valid strings never fail.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the primary bug fix: excluding non-string scalar aliases during metadata conversion.
Description check ✅ Passed The description covers the change, related issues, type, checklist, testing environment, validation results, and screenshots status.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/frontmatter-alias-normalization

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/services/vault-service.ts`:
- Around line 127-128: Update the alias normalization logic near the list
construction and string filter so scalar and array inputs apply the same
empty-string rule; if empty aliases are invalid, exclude empty strings from both
forms. Add tests covering aliases supplied as "" and [""] and verify neither
produces an alias or empty search field.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 09fd9c4b-83b8-4550-ab38-0af8b49116b4

📥 Commits

Reviewing files that changed from the base of the PR and between 5d8a1c5 and 9266e15.

📒 Files selected for processing (1)
  • src/services/vault-service.ts

Comment thread src/services/vault-service.ts Outdated
Review follow-up on #382: scalar "" was dropped by truthiness while [""]
survived the type-only filter. Unify on "non-empty strings only".
@RAIT-09
RAIT-09 merged commit 4e73435 into dev Aug 5, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant