Skip to content

fix(lxlweb): don't crash in getHeldBy on missing org - #1649

Merged
andersju merged 1 commit into
developfrom
fix/getheldby-dont-500-on-missing-org
Jul 22, 2026
Merged

fix(lxlweb): don't crash in getHeldBy on missing org#1649
andersju merged 1 commit into
developfrom
fix/getheldby-dont-500-on-missing-org

Conversation

@andersju

Copy link
Copy Markdown
Member

I noticed occasional 500 errors in prod:

[500] GET /find?_q=something&_cursor=15&_limit=20&_offset=0&_sort=&_spell=true
TypeError: Cannot read properties of undefined (reading '_members')
    at getHeldBy (file:///data/packages/lxlweb-4001/build/server/chunks/holdings-BAo2QGfb.js:105:38)
    at getHeldByLibraries (file:///data/packages/lxlweb-4001/build/server/chunks/search.server-DWX7h352.js:505:13)
    at file:///data/packages/lxlweb-4001/build/server/chunks/search.server-DWX7h352.js:271:28
    at Array.map (<anonymous>)
    at asSearchResultItem (file:///data/packages/lxlweb-4001/build/server/chunks/search.server-DWX7h352.js:262:17)
    at asResult (file:///data/packages/lxlweb-4001/build/server/chunks/search.server-DWX7h352.js:239:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
    at async load (file:///data/packages/lxlweb-4001/build/server/chunks/11-B1mPktAO.js:93:24)
    at async fn (file:///data/packages/lxlweb-4001/build/server/index.js:1266:23)
    at async load_server_data (file:///data/packages/lxlweb-4001/build/server/index.js:1257:18)

The problem is that getHeldBy assumes that every org in a user's myLibraries has a matching entry in orgs, but this is not necessarily true, as orgs is the result of getRefinedOrgs(libraries) which keeps only those for which isLibraryOrg is true.

This can happen if the user has favorited an org with no member libraries (if that's possible...?), or if the org (which is stored in a cookie) has been deleted or renamed, or possibly (at startup) due to a race condition if refreshLibraries hasn't finished.

Anyway, for the unlucky visitor this results in virtually all search result pages and individual records simply crashing with a 500 error, until that cookie is cleared. So let's fix that.

@andersju
andersju requested review from kaipoykio and kwahlin July 22, 2026 12:46

@kaipoykio kaipoykio 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.

looks good

@andersju
andersju merged commit cb1d24c into develop Jul 22, 2026
2 checks passed
@andersju
andersju deleted the fix/getheldby-dont-500-on-missing-org branch July 22, 2026 13:07
@andersju

Copy link
Copy Markdown
Member Author

On closer inspection the 500s I saw were probably because refreshLibraries had failed on a couple of the servers, which in turn triggered this. But this fix is still valid, and I'll make a separate PR to make refreshLibraries more robust.

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.

2 participants