Fix contextless 'Not Found' error logging on startup, bump to 0.4.5#15
Merged
Conversation
The didFinishLaunching handler caught API failures with
`this.log.error(error?.data?.error ?? error)`, which for a Tesla/
Teslemetry API error (tesla-fleet-api rejects with `{status, data}`)
logs only the bare error string - e.g. a repeating "[Teslemetry]
Not Found" with no indication of which request failed or why.
Split the metadata() and products_by_type() calls so each failure
is caught and logged individually with the operation name, HTTP
status, and error body (falling back to the full error for non-API
rejections like network failures), matching the status/data logging
pattern already used elsewhere in vehicle.ts and energy.ts.
Also bumps to 0.4.5. tesla-fleet-api's pinned ^0.2.0 is already the
latest published version, so no library update was needed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
[Teslemetry] Not Foundlog with no indication of what failed (npmhomebridge-teslemetry0.4.4, reported by a user)platform.ts'sdidFinishLaunchinghandler caught the account-discovery API chain (metadata()->products_by_type()) with a singlethis.log.error(error?.data?.error ?? error).tesla-fleet-api's_request()rejects with{ status, data }on any non-OK HTTP response, so a 404 logs literally just the string"Not Found"- no operation name, no status code, nothing.metadata()andproducts_by_type()now each have their own.catch()that logs the operation name, HTTP status, and error body (data.error), falling back to the full error object for non-API-shaped rejections (e.g. network failures). Matches the${op} failed: ${status}: ${data.error}logging pattern already used invehicle.ts/energy.ts.metadata()to reject with{status: 404, data: {error: "Not Found"}}against the compileddist/platform.jsand confirming the current code logs bare"Not Found"; confirmed the fix logsTeslemetry metadata request failed (status 404): Not Foundinstead.products_by_type()failures (e.g. a 500).teslemetrybranch. The root cause was already fixed properly in the new (private, unpublished) monorepo plugin; this port keeps npm users unblocked in the meantime.tesla-fleet-apipinned at^0.2.0is already the latest published version (0.2.0, published 2024-07-21) - no newer release exists, so no dependency bump was made or needed.0.4.4->0.4.5inpackage.json.What Changed
src/platform.ts: split the single.then(..., errorHandler)at the end of the metadata/products discovery chain into per-call.catch()handlers with contextual messages; downstream logic (accessory creation, registration) is unchanged, just reindented under the new nesting.package.json: version0.4.4->0.4.5.AGENTS.md(new): documents the multi-branch publish model and thetesla-fleet-api{status, data}rejection shape, so future error-logging fixes in this repo follow the same pattern.Risk Assessment
Low. The change only affects the
.catch()branches of the startup account-discovery chain - the success path (accessory creation/registration) is untouched logic, just re-indented. No dependency version changed. Verified withtsc --noEmit,eslint --max-warnings=0, andnpm run build, all clean.Testing
npx tsc --noEmit- passes.npm run lint- passes with--max-warnings=0.npm run build- passes.dist/platform.js, constructedTeslaFleetApiPlatformwith mockedhomebridgelog/apiobjects, and drovedidFinishLaunchingthrough four scenarios:metadata()rejects with{status: 404, data: {error: "Not Found"}}-> logsTeslemetry metadata request failed (status 404): Not Found(previously bareNot Found).products_by_type()rejects with{status: 500, data: {error: "Internal Server Error"}}-> logsTeslemetry products request failed (status 500): Internal Server Error.metadata()rejects with a plainTypeError("fetch failed")(non-API-shaped, e.g. network failure) -> logsTeslemetry metadata request failed: TypeError: fetch failedinstead ofstatus undefined: undefined.metadata()/products_by_type()resolve, empty scopes/products) -> no error logs,registerPlatformAccessoriesstill called correctly.Publishing remains manual via
publish.sh- that step is the captain's, after merge.Full narrative / original brief
STOPGAP fix for the published HomeBridge plugin (npm
homebridge-teslemetry0.4.4), which builds from this repo'steslemetrybranch, not the defaultdevbranch.A user reported the plugin failing with only a bare
[Teslemetry] Not Foundlog line repeating, with zero context about what failed. That defect was root-caused and fixed in the new monorepo plugin (contextless error logging on a streaming/config-update failure path), but the monorepo plugin is private/unpublished, so npm users run this legacy code. This PR pushes the fix here as a stopgap, together with a library-update assessment (tesla-fleet-apiis already at latest), and bumps the package version to 0.4.5.