{"record":{"id":"8ad63c0251c2130b","repo":"Freika/dawarich","slug":"failed-to-apply-speed-colors-to-route","errorCode":null,"errorMessage":"Failed to apply speed colors to route:","messagePattern":"Failed to apply speed colors to route:","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"app/javascript/maps_maplibre/utils/speed_colors.js","lineNumber":229,"sourceCode":"          // Same color — extend current segment with p2\n          currentCoords.push([p2.longitude, p2.latitude])\n        }\n      }\n\n      // Flush last segment\n      if (currentCoords.length >= 2) {\n        features.push({\n          type: \"Feature\",\n          geometry: { type: \"LineString\", coordinates: currentCoords },\n          properties: {\n            ...feature.properties,\n            id: `${feature.properties.id}-seg-${segIdx}`,\n            color: currentColor,\n          },\n        })\n      }\n    } catch (error) {\n      console.warn(\n        \"Failed to apply speed colors to route:\",\n        feature.properties?.id,\n        error,\n      )\n      features.push(feature)\n    }\n  }\n\n  return { type: \"FeatureCollection\", features }\n}\n","sourceCodeStart":211,"sourceCodeEnd":240,"githubUrl":"https://github.com/Freika/dawarich/blob/97fad417c5a11b0eb11157890635e015723a2e97/app/javascript/maps_maplibre/utils/speed_colors.js#L211-L240","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nfor (const feature of collection.features) {\n  try {\n    /* split and color */\n  } catch (error) {\n    console.warn(\"Failed to apply speed colors to route:\", feature.properties?.id, error)\n    features.push(feature)\n  }\n}\n// after\nfor (const feature of collection.features) {\n  const coords = feature?.geometry?.coordinates\n  if (!Array.isArray(coords) || coords.length < 2 || !feature.properties?.id) {\n    features.push(feature) // skip coloring, keep the route\n    continue\n  }\n  /* split and color */\n}","handlingStrategy":"validation","validationCode":"function isColorableRoute(feature) {\n  const coords = feature?.geometry?.coordinates\n  return (\n    Array.isArray(coords) &&\n    coords.length >= 2 &&\n    coords.every((c) => Array.isArray(c) && c.length >= 2 && c.every(Number.isFinite))\n  )\n}","typeGuard":"/** @param {unknown} feature @returns {boolean} */\nfunction isColorableRoute(feature) {\n  const coords = feature?.geometry?.coordinates\n  return Array.isArray(coords) && coords.length >= 2 && Boolean(feature.properties?.id)\n}","tryCatchPattern":"try {\n  features.push(...splitBySpeed(feature))\n} catch (error) {\n  console.warn(\"Failed to apply speed colors to route:\", feature.properties?.id, error)\n  features.push(feature) // keep the original so the route stays visible\n}","preventionTips":["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"],"tags":["geojson","speed-colors","routes","dawarich","data-validation"],"backgroundTag":"geojson-feature-invalid","analyzedSha":"97fad417c5a11b0eb11157890635e015723a2e97","analyzedAt":"2026-08-21T17:04:17.778Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}