Skip to content

fix(amazon-location-service): fix sample bugs from the #250 review - #294

Open
TheSaiEaranti wants to merge 7 commits into
awslabs:mainfrom
TheSaiEaranti:fix-location-269-followups
Open

TheSaiEaranti wants to merge 7 commits into
awslabs:mainfrom
TheSaiEaranti:fix-location-269-followups

Conversation

@TheSaiEaranti

Copy link
Copy Markdown

This fixes the six follow-ups that #269 tracks from the #250 review. Five are bugs in the JavaScript and Kotlin samples in the amazon-location-service references, and one is a pair of numbered lists in calculate-routes.md that show every item as "1.". Each item is its own commit, followed by the version bump.

Related

Fixes #269, which collects the review follow-ups from #250.

Changes

  • address-verification.md: waitForJob looped on GetJob with no deadline, a ThrottlingException that outlasted the SDK's retries ended the wait, and the "back off" comment sat above a fixed 30 s sleep. It now takes maxWaitMs (6 hours by default), keeps polling through ThrottlingException and InternalServerException, backs off from 30 s to 5 minutes, and throws at the deadline. The text above it now points long-running jobs and Lambda callers at EventBridge. triage() tested !mailable, so every record without a Mailable value was rejected. It now sends those records, and records with an ErrorType, to review, and the delivery indicators line says to treat a missing value as unknown. I went that way because the Amazon Location docs only list true/false for these columns and don't say whether they are always present. If you know they are, that sentence can just say so.
  • google-migration-android.md, Pattern 3: routePoints was never defined, and Point.fromLngLat(it.second, it.first) assumed (lat, lon) pairs. The sample now calls calculateRoutes with legGeometryFormat = GeometryFormat.Simple and maps each leg's lineString, which is already [lng, lat]. I didn't use the line suggested in amazon-location-service: follow-ups from #250 review #269 as written. It doesn't compile against georoutes 1.8.51, where geometry and lineString are nullable, and lineString is only filled when the request asks for Simple (the default, FlexiblePolyline, returns geometry.polyline). google-migration-web.md already recommends Simple for migrations.
  • device-tracking.md: the map.on("load") block and the live poll read only the first page of ListDevicePositions (at most 100 devices), and the async setInterval callback could start a poll while a slow one was still running, so older positions could be applied after newer ones. A listAllDevicePositions() helper now follows NextToken, both blocks use it, and the poll is a loop that schedules the next run 15 s after the previous one finishes and logs a failed poll. Beyond the list in amazon-location-service: follow-ups from #250 review #269, I also paginated the history block, which had the same one-page gap that the Best Practices list in this file warns about. It is one hunk if you'd rather leave it out.
  • google-migration-android.md, MapActivity: it never called mapView.onCreate(savedInstanceState) and didn't forward the other lifecycle calls that the MapLibre 13.1.0 MapView javadoc says must come from the parent Activity. It now calls onCreate before getMapAsync and overrides onStart, onResume, onPause, onStop, onSaveInstanceState, onLowMemory and onDestroy in the order from the review. Also beyond the list: the style URL used $API_KEY, a private const inside AmazonLocationAuth's companion object, so the class didn't compile. It now has its own apiKey placeholder, which is also easy to drop.
  • calculate-routes.md: the item bodies under "When to Use Simple Format" and "When to Use FlexiblePolyline Format" were at column 0, which closes the list after every item, so all 11 items rendered as "1.". Explicit numbers alone fail MD029 here (9 errors, since each one-item list has to start at 1), so I indented each item body by 3 spaces and numbered the items 1-5 and 1-6. The diff is nearly all whitespace and is easiest to read with whitespace hidden (?w=1), where it is 10 lines. The ##### Bandwidth savings heading is a sentence again, now with a bold label.
  • zone-alerts.md: the BatchEvaluateGeofences sample threw away the response. It now checks response.Errors and logs each failed device, as the Batch Operation Errors section of the same file says to.
  • Bumped amazon-location-service to 1.1.1 in .claude-plugin/marketplace.json and both plugin manifests.

Verification:

  • JavaScript (items 1, 3, 6): I ran each changed block as written against @aws-sdk/client-location 3.1159.0, with a stubbed HTTP handler and a fake clock.
    • main: a job stuck in Running is still polled after 72 simulated hours, and 3 throttled responses in a row end the wait. 250 devices give 100 markers, and a slow poll overlaps the next one and moves markers back to older positions. A failed BatchEvaluateGeofences entry prints nothing.
    • this branch: the wait gives up at 6 hours and keeps going through throttling. All 250 devices and all 1,080 history positions come back, polls never overlap, and the failed entry is logged.
  • node --check on each changed block, and tsc --checkJs (5.9.3 and 7.0.2) against the SDK and maplibre-gl 5.24.0 types: no errors beyond the two that main already has on lines this doesn't change.
  • Kotlin (items 2, 4): compiled the Pattern 3 and MapActivity samples with kotlinc 2.4.21 against android.jar 35, org.maplibre.gl:android-sdk:13.1.0, android-plugin-annotation:4.0.0, androidx.appcompat:appcompat:1.7.0 and aws.sdk.kotlin:georoutes-jvm:1.8.51, adding only the imports and enclosing function the snippets assume. Main fails with unresolved reference 'routePoints' and unresolved reference 'API_KEY', and this branch compiles with no warnings. I only compiled them. I didn't run either sample on a device or emulator.
  • calculate-routes.md: markdown-it 15.0.3, commonmark.js 0.31.2 and cmark-gfm (cmarkgfm 2025.10.22) render 11 one-item lists on main and two lists numbered 1-5 and 1-6 on this branch. The 41 fenced code blocks have the same content before and after.
  • markdownlint-cli2 0.17.2, dprint check, the lint:manifests ajv checks, node tools/validate-cross-refs.cjs, uv run tools/validate-references.py, uv run tools/validate-size.py and uv run --with pytest pytest tools plugins (132 passed): all pass, with the same output as on main.

Acknowledgment

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

waitForJob polled GetJob in a while (true) with no deadline. A
ThrottlingException that outlasted the SDK's own retries ended the
wait, and the "back off" comment sat above a constant 30 s sleep.

It now takes maxWaitMs (6 hours by default), keeps polling through
ThrottlingException and InternalServerException, backs off from 30 s
up to 5 minutes, and throws once the deadline passes. The prose points
long-running jobs and Lambda callers at EventBridge, and the GetJob
error list names the transient errors.

triage() used !mailable, so it rejected every record with no Mailable
value. It now sends those records to review, along with any record
that has an ErrorType, and the delivery indicators line says to treat
a missing value as unknown.
The Android route display sample mapped routePoints, which is never
defined, and read each element as Pair(lat, lon).

It now calls CalculateRoutes with legGeometryFormat set to
GeometryFormat.Simple and builds the line from each leg's lineString,
which is already in [lng, lat] order. geometry and lineString are
nullable in the georoutes model classes, so the access uses ?. and
orEmpty(). The default format, FlexiblePolyline, fills
geometry.polyline instead of lineString, and the comment says so.
The map load block and the live poll in device-tracking.md read only
the first page of ListDevicePositions, although the same file says to
follow NextToken. The live poll also used an async setInterval
callback, so a slow or throttled poll could still be running when the
next one started, and an older response could be applied after a
newer one.

Add listAllDevicePositions(), which follows NextToken, and use it in
both blocks. The live poll is now a loop that schedules the next poll
15 seconds after the current one finishes, and catches a failed poll
so the loop keeps going. The history block also follows NextToken
now, as the Best Practices list asks.
MapActivity created a MapView but never called mapView.onCreate and
forwarded none of the other lifecycle calls, which MapLibre's MapView
javadoc says must come from the parent Activity or Fragment. Call
mapView.onCreate(savedInstanceState) after setContentView, and
override onStart, onResume, onPause, onStop, onSaveInstanceState,
onLowMemory and onDestroy to forward them.

The style URL also used $API_KEY, which is a private constant inside
AmazonLocationAuth's companion object, so the sample did not compile.
It now uses an apiKey placeholder property.
The numbered items under "When to Use Simple Format" and "When to Use
FlexiblePolyline Format" kept their code fences, prose and sub-bullets
at column 0. That ends the list after every item, so each section
rendered as a run of one-item lists that all showed "1.".

Indent each item body by 3 spaces so each section is one list, and
number the items 1-5 and 1-6. Numbering alone would fail MD029, which
wants each of those one-item lists to start at 1. The code inside the
fences is unchanged.

Also turn the "##### Bandwidth savings: ..." heading back into a
sentence, now with a bold label.
The Option B sample in zone-alerts.md discarded the response, so
per-device failures reported in its Errors array went unnoticed,
although the Batch Operation Errors section of the same file says to
always check that array. Keep the response and log each failed device,
the same way device-tracking.md does for BatchUpdateDevicePosition.
@TheSaiEaranti
TheSaiEaranti requested review from a team as code owners October 28, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

amazon-location-service: follow-ups from #250 review

1 participant