summaryrefslogtreecommitdiff
path: root/strava
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-08-11 14:19:01 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-08-11 14:19:01 +0200
commit7d13374eec8c33c4e14cc5b0c3de36e4f620ce0e (patch)
tree98a20ee73f34863ddb5938aa5eb29346e4a5db56 /strava
parent1da94931188c35c06dd032aadce2799fc13db1dd (diff)
fix: Continue Strava import after invalid activities
Diffstat (limited to 'strava')
-rw-r--r--strava/sync.go4
-rw-r--r--strava/sync_test.go20
2 files changed, 24 insertions, 0 deletions
diff --git a/strava/sync.go b/strava/sync.go
index 762b41a..45b13d3 100644
--- a/strava/sync.go
+++ b/strava/sync.go
@@ -1,6 +1,7 @@
package strava
import (
+ "errors"
"fmt"
"net/url"
"strconv"
@@ -137,6 +138,9 @@ func (c *Client) activityStreams(id int64) (activityStreams, error) {
}
func activityGPX(activity Activity, streams activityStreams) ([]byte, error) {
+ if len(streams.LatLng) == 0 {
+ return nil, errors.New("activity has no track points")
+ }
points := make([]gpx.GPXPoint, len(streams.LatLng))
for i := range streams.LatLng {
point := gpx.GPXPoint{}
diff --git a/strava/sync_test.go b/strava/sync_test.go
index f810206..c55f97b 100644
--- a/strava/sync_test.go
+++ b/strava/sync_test.go
@@ -112,3 +112,23 @@ func TestGet(t *testing.T) {
require.True(t, found)
assert.Equal(t, 0.0, powerValue)
}
+
+func TestGetRejectsActivityWithoutTrackPoints(t *testing.T) {
+ client := newTestClient(t, func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ switch r.URL.Path {
+ case "/activities/14701658670":
+ _, err := w.Write([]byte(`{"id":14701658670,"name":"Empty activity","type":"Ride","sport_type":"Ride","start_date":"2026-01-01T10:00:00Z"}`))
+ require.NoError(t, err)
+ case "/activities/14701658670/streams":
+ _, err := w.Write([]byte(`{"latlng":{"data":[]}}`))
+ require.NoError(t, err)
+ default:
+ http.NotFound(w, r)
+ }
+ })
+
+ _, _, err := client.Get(14701658670)
+
+ require.EqualError(t, err, "activity has no track points")
+}