Repository navigation
Description
Summary
OgcApiEndpoint.csapiCollections crashes with TypeError: Cannot read properties of null (reading 'collections') when the endpoint's landing page does not advertise a link with rel: "data" (or its long-URI variant). Five sibling collection getters share the same bug pattern.
The crash is triggered by a real, conformant CSAPI server: the OpenSensorHub demo (http://45.55.99.236:8080/sensorhub/api) cited in PR #136's own validation list.
Reproduction
import { OgcApiEndpoint } from '@camptocamp/ogc-client';
const endpoint = new OgcApiEndpoint('http://45.55.99.236:8080/sensorhub/api');
console.log(await endpoint.hasConnectedSystems); // true (correct)
console.log(await endpoint.csapiCollections); // ❌ throwsStack trace:
TypeError: Cannot read properties of null (reading 'collections')
at parseCollections (dist/dist-node.js:2873:14)
at process.processTicksAndRejections (node:internal/process/task_queues:104:5)
Root cause
Two interacting issues:
1. csapiCollections doesn't null-check data (the immediate crash)
src/ogc-api/endpoint.ts:230-236:
get csapiCollections(): Promise<string[]> {
return Promise.all([this.data, this.hasConnectedSystems])
.then(([data, hasCSAPI]) => (hasCSAPI ? data : { collections: [] }))
.then(parseCollections) // ← parseCollections(null) throws
...Compare to the sibling allCollections, which correctly null-checks before calling parseCollections:
return this.data.then((dataDocument) =>
dataDocument ? parseCollections(dataDocument) : []
);The same null-deref pattern is present in 5 other getters sharing the Promise.all([this.data, this.hasX]).then(...).then(parseCollections) shape:
| Line | Getter |
|---|---|
| 187 | recordCollections |
| 198 | featureCollections |
| 206 | edrCollections |
| 244 | vectorTileCollections |
| 257 | mapTileCollections |
2. Why data is null here (separate concern, broader fix)
collectionsUrl only follows links with rel: "data" or http://www.opengis.net/def/rel/ogc/1.0/data. OpenSensorHub's landing page uses rel: "collections" instead:
{
"rel": "collections",
"title": "Collections available on this server",
"href": "http://45.55.99.236:8080/sensorhub/api/collections",
"type": "application/json"
}So collectionsUrl resolves to null, data resolves to null, and every dependent getter then crashes.
OGC API Common Part 2 specifies data as the canonical rel — OpenSensorHub is technically out of spec — but rel: "collections" is widely seen in the wild, and after the immediate null-deref is fixed, the library still won't discover any collections from these servers. Worth considering whether collectionsUrl should additionally accept rel: "collections" for compatibility.
Proposed fix
Minimum (unblocks the crash, no behavior change)
Mirror the allCollections null-guard in all six affected getters. Single-token edit per getter:
- .then(([data, hasCSAPI]) => (hasCSAPI ? data : { collections: [] }))
+ .then(([data, hasCSAPI]) => (hasCSAPI && data ? data : { collections: [] }))I've applied this to csapiCollections locally and verified the OpenSensorHub case now returns { hasConnectedSystems: true, collections: [] } cleanly (instead of crashing). The same diff applied to the other 5 getters would make them robust by symmetry.
Recommended (also fixes the empty-collections downstream issue)
Additionally, accept rel: "collections" in collectionsUrl:
- ['data', 'http://www.opengis.net/def/rel/ogc/1.0/data'],
+ ['data', 'http://www.opengis.net/def/rel/ogc/1.0/data', 'collections'],This is a pragmatic compatibility win for OpenSensorHub-style servers; happy to defer to maintainers on whether this belongs here vs. being treated as a server-conformance issue.
Why this matters / context
I'm building a Python ADK agent (Google Gemini) that uses @camptocamp/ogc-client/csapi via a Node CLI subprocess to query CSAPI endpoints from natural language. This is the second consumer of the library beyond ogc-csapi-explorer, so the bug surfaced immediately when probing the public test servers cited in PR #136.
Cross-references:
- This bug is unrelated to (but discovered while pursuing) the use case behind deferred issue Deferred enhancement: SWE Common–aware result-vector extraction (out-of-scope until upstream broadens scope) #171.
- The 52°North demo (
csa.demo.52north.org) is also broken in a separate way — its/conformanceno longer declares any CSAPI URI, sohasConnectedSystemscorrectly returnsfalse. Probably a server-side regression worth flagging to that team.
Environment
- Node
v24.15.0, npm11.12.1 - Snapshot:
OS4CSAPI/ogc-client-CSAPI_2phase-7branch - Built locally with
npm run build - Probed against OpenSensorHub on 2026-05-03
Narasimha Sharma Narayanam (@nsnarayanam )
Activity
nsnarayanam commentedon May 3, 2026
After patching
csapiCollectionslocally and continuing to probe OpenSensorHub, two related issues blocked further library use. Both involve the library's strictness vs. real-world server shape. Filing as a follow-up here rather than separate issues since they're discovered in the same session and share the same reproducer.Issue 3:
parseCollectionsignoresfeatureType-based CSAPI signalingsrc/ogc-api/info.ts:294-301flags a collection ashasConnectedSystems: trueonly when its links include arelmatching^ogc-cs:.+$:OpenSensorHub doesn't put
ogc-cs:*rels on its collections — it signals the resource family at the collection level viafeatureType:{ "id": "all_systems", "itemType": "feature", "featureType": "system", // ← this is the CSAPI signal "links": [ { "rel": "self", "href": "..." }, { "rel": "items", "href": "systems" } ] }Result:
csapiCollectionsreturns[]against an OpenSensorHub server that clearly serves CSAPI (its conformance doc declaresogcapi-connectedsystems-1/1.0/conf/coreand the root advertisesrel: "systems",rel: "datastreams"etc.).Possible fix: also accept
collection.featureTypein{system, datastream, datastreams, observation, observations, samplingFeature, featuresOfInterest, procedure, deployment}as a CSAPI signal:I recognize this is a judgement call about how generously the library should map server-side conventions. Open to deferring it as a server-conformance issue if you'd prefer servers to advertise
ogc-cs:rels on their collections.Issue 4:
getCollectionDocumentfollowsselflink blindly without validating the resultsrc/ogc-api/endpoint.ts:359-377:OpenSensorHub returns malformed
selflinks on collection items — they point to the parent/collectionsURL instead of the per-collection URL:{ "id": "all_systems", "links": [ { "rel": "self", "href": "http://45.55.99.236:8080/sensorhub/api/collections" } ] }So
getCollectionDocument('all_systems')returns the parent{collections: [...], links: [...]}document. ThencreateCSAPIBuildercorrectly rejects it:The server is plainly wrong here. But the library has enough information to detect the mismatch and fall back to URL construction (the existing
elsebranch already does this). A simple post-fetch validation:.then(async (collection) => { if (hasLinks(collection, ['self'])) { - return fetchLink(collection, 'self', this.baseUrl); + const fetched = await fetchLink(collection, 'self', this.baseUrl); + // If the self link returned a doc whose id doesn't match what we asked for, + // fall through to URL construction (defensive against bad server self links). + if (fetched && typeof fetched.id === 'string' && fetched.id === collectionId) { + return fetched; + } } return fetchDocument(getChildPath(await this.collectionsUrl, collectionId)); });Trades zero behavior change for conformant servers against graceful degradation for non-conformant ones. Happy to PR if accepted.
Summary table (running tally for OpenSensorHub interop)
csapiCollectionsnull-derefcollectionsUrlrejectsrel: "collections"parseCollectionsignoresfeatureTypegetCollectionDocumentblindself-link followNet: against this one publicly-cited test server, four distinct fixes are needed end-to-end before
createCSAPIBuilder('weather-stations')succeeds. Two of those are server-side bugs (OpenSensorHub maintainers should know), but in all four cases the library could be more permissive without weakening its correctness.I've worked around all four locally and can confirm
createCSAPIBuilderthen succeeds against OpenSensorHub end-to-end. For ongoing agent development I'm switching to a local conformant mock to remove the moving parts; happy to share that mock if it'd be useful as a CI fixture.— Narasimha Sharma Narayanam (@nsnarayanam)
nsnarayanam commentedon May 3, 2026
Follow-up: repo for the second-consumer agent that surfaced these bugs: https://github.com/nsnarayanam/ogc-csapi-agent
Sam-Bolling commentedon May 3, 2026
Greetings, @nsnarayanam, thank you for your interest in the CSAPI client library work and identifying these issues. I will work on them as time permits. I also added your repository to the repositories of interest for the OGC CSAPI SWG's participation guide in the OGC's upcoming code sprint on 11-13MAY2026. The participation guide is here if you are interested and available to join us: https://os4csapi.github.io/code-sprint-guide/builder-days-2026/.
Respectfully,
Sam
nsnarayanam commentedon May 4, 2026
research(phase-9): fold in evidence from ogc-csapi-explorer/docs/impl…
research(phase-9): fold in evidence from OSHConnect-Python/docs/research
research(phase-9): reframe doc with #188 as input to existing research
research(phase-9): rework COAs around actual donation workflow
research(phase-9): add full-scope live-testing experiment plan