Freika/dawarich · warning
Failed to parse track segments for marker update:
Error message
Failed to parse track segments for marker update:
What it means
The track-segment marker update path reads feature.properties.segments the same way as the click path: a string value is passed to JSON.parse, and a malformed string throws. Unlike the click path, this handler returns early on failure, so segment markers are not created at all for that track.
Source
Thrown at app/javascript/controllers/maps/maplibre/event_handlers.js:1093
* Update track segment markers when track geometry changes
* Called after track recalculation to move emoji markers to new positions
* @param {Object} feature - The updated track GeoJSON feature
*/
updateTrackMarkers(feature) {
if (!this.selectedTrackFeature) return
if (!feature || !feature.geometry || feature.geometry.type !== "LineString")
return
// Parse segments from feature properties
let segments = []
try {
const props = feature.properties || {}
segments =
typeof props.segments === "string"
? JSON.parse(props.segments)
: props.segments || []
} catch (err) {
console.warn("Failed to parse track segments for marker update:", err)
return
}
const trackId = feature.properties?.id
this._createTrackSegmentMarkers(trackId, feature, segments)
}
/**
* Zoom the map to fit a specific segment's bounds
* @param {Object} segment - Segment data with start_index and end_index
*/
_zoomToSegment(segment) {
if (!this.selectedTrackFeature || !segment) return
const coords = this.selectedTrackFeature.geometry?.coordinates
if (!coords || coords.length < 2) return
const startIdx = Math.max(0, segment.start_index || 0)View on GitHub (pinned to 97fad417c5)
Solutions
- Inspect the failing feature's properties.segments in the debugger to find the exact JSON syntax error
- Fix the producing serializer or importer to emit valid segment JSON
- Share one safe-parse helper between the click path and the marker path so both degrade identically
- If markers matter for this track, fall back to re-fetching via fetchTrackWithSegments instead of returning silently
Example fix
// before
try {
const props = feature.properties || {}
segments =
typeof props.segments === "string"
? JSON.parse(props.segments)
: props.segments || []
} catch (err) {
console.warn("Failed to parse track segments for marker update:", err)
return
}
// after
const props = feature.properties || {}
const segments = safeParseSegments(props.segments) // shared helper, never throws
if (!segments.length) return
this._createTrackSegmentMarkers(trackId, feature, segments) Defensive patterns
Strategy: validation
Validate before calling
const raw = feature.properties?.segments
const looksParsable =
Array.isArray(raw) ||
(typeof raw === "string" && raw.trimStart().startsWith("["))
if (!looksParsable) return // avoid JSON.parse on obviously wrong payloads Type guard
/** @param {unknown} raw @returns {boolean} */
function isParsableSegments(raw) {
if (Array.isArray(raw)) return true
if (typeof raw !== "string") return false
const t = raw.trim()
return t.startsWith("[") && t.endsWith("]")
} Try / catch
try {
segments = safeParseSegments(props.segments)
} catch (err) {
console.warn("Failed to parse track segments for marker update:", err)
return // skip markers for this track only; do not break the surrounding loop
} Prevention
- Validate payloads at the API boundary once, not in every consumer
- Keep a single shared safe-parse utility for segments used by click, hover, and marker paths
- Log the track id alongside the warning so bad data can be traced to a specific record
When it happens
Trigger: A track feature whose segments property is an invalid JSON string (truncated response, double encoding, NaN in the payload); features built by hand or cached from an older API version; marker refresh triggered by a live track update that carries a partial payload.
Common situations: Marker updates after live track pushes with incomplete data; switching between tiled and non-tiled point sources; stale caches from an upgraded backend; tracks imported by older importers that produced malformed segment JSON.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Failed to parse track segments:
- Could not classify zip contents -- file may be corrupted
- [EventHandlers] Failed to highlight track:
- Failed to add photos layer:
- Failed to load scratch layer:
AI-assisted analysis of Freika/dawarich@97fad417c5 (2026-08-21).
Data as JSON: /api/errors/083f9c301ee2f7c3.
Report an issue: GitHub.