Freika/dawarich · warning
Failed to apply speed colors to route:
Error message
Failed to apply speed colors to route:
What it means
applySpeedColors splits each route LineString into speed-colored sub-segments; every feature is processed inside its own try/catch. On failure the original uncolored feature is pushed instead, so the route still renders but without speed coloring for that feature. The warning includes the feature's properties.id (when present) to identify the bad record.
Source
Thrown at app/javascript/maps_maplibre/utils/speed_colors.js:229
// Same color — extend current segment with p2
currentCoords.push([p2.longitude, p2.latitude])
}
}
// Flush last segment
if (currentCoords.length >= 2) {
features.push({
type: "Feature",
geometry: { type: "LineString", coordinates: currentCoords },
properties: {
...feature.properties,
id: `${feature.properties.id}-seg-${segIdx}`,
color: currentColor,
},
})
}
} catch (error) {
console.warn(
"Failed to apply speed colors to route:",
feature.properties?.id,
error,
)
features.push(feature)
}
}
return { type: "FeatureCollection", features }
}
View on GitHub (pinned to 97fad417c5)
Solutions
- Use the logged properties.id to find the exact feature in the collection and inspect its geometry and timestamps
- Filter upstream: require geometry.coordinates.length >= 2 and numeric timestamps before processing
- Default missing ids before processing so segment ids stay meaningful
- Add a serializer guarantee that routes always carry the fields speed coloring needs
Example fix
// before
for (const feature of collection.features) {
try {
/* split and color */
} catch (error) {
console.warn("Failed to apply speed colors to route:", feature.properties?.id, error)
features.push(feature)
}
}
// after
for (const feature of collection.features) {
const coords = feature?.geometry?.coordinates
if (!Array.isArray(coords) || coords.length < 2 || !feature.properties?.id) {
features.push(feature) // skip coloring, keep the route
continue
}
/* split and color */
} Defensive patterns
Strategy: validation
Validate before calling
function isColorableRoute(feature) {
const coords = feature?.geometry?.coordinates
return (
Array.isArray(coords) &&
coords.length >= 2 &&
coords.every((c) => Array.isArray(c) && c.length >= 2 && c.every(Number.isFinite))
)
} Type guard
/** @param {unknown} feature @returns {boolean} */
function isColorableRoute(feature) {
const coords = feature?.geometry?.coordinates
return Array.isArray(coords) && coords.length >= 2 && Boolean(feature.properties?.id)
} Try / catch
try {
features.push(...splitBySpeed(feature))
} catch (error) {
console.warn("Failed to apply speed colors to route:", feature.properties?.id, error)
features.push(feature) // keep the original so the route stays visible
} Prevention
- Validate coordinate arrays and required properties before transform pipelines
- Push the original feature on per-item failure so one bad record cannot un-color an entire route set
- Include the feature id in the warning so bad source data can be traced
When it happens
Trigger: A feature with null/absent geometry or empty coordinates; missing timestamps making speed math produce NaN; properties.id undefined so the generated segment id contains 'undefined'; coordinates containing non-numeric values that break distance calculations.
Common situations: Imported routes with sparse or malformed GPX data; APIs returning features whose properties lack the time field; hand-built GeoJSON fixtures; a FeatureCollection meant for a different layer fed to the speed-color transform.
Related errors
- Failed to parse track segments:
- Failed to add photos layer:
- Could not classify zip contents -- file may be corrupted
- [EventHandlers] Failed to highlight track:
- Failed to parse track segments for marker update:
AI-assisted analysis of Freika/dawarich@97fad417c5 (2026-08-21).
Data as JSON: /api/errors/8ad63c0251c2130b.
Report an issue: GitHub.