fix(files): throw on empty REST body to avoid TypeError after self-replace#215
Merged
Conversation
When desktop-mode replaces itself live, REST routes briefly re-register and a 2xx response can land with an empty or unparseable body. The files REST client previously returned `null as T`, which crashed the folder-hydration consumer with `Cannot read properties of null (reading 'placements')`. Throw at the boundary instead — the existing `.catch` handlers log a clear "files REST 200: empty or unparseable body" line and the desktop layer keeps working after a refresh. Refs #212.
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
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.
Summary
When desktop-mode replaces itself live (Plugins window → Upload .zip → Replace), REST routes briefly re-register and a 2xx response can land with an empty or unparseable body. The files REST client previously returned
null as T, which crashed the folder-hydration consumer insrc/desktop-files/layer.tswith:Fix at the boundary: in
src/desktop-files/rest.ts'scall(), throw when the body isnullon a 2xx. Every consumer in the files module expects a shaped object, so a null body is never legitimate. The existing.catchhandlers now log a single meaningful line:Boundary fix > per-consumer guard: one change covers
listPlacements,listFolders,restoreTrashedItem, etc., and produces a clearer signal than silently no-op'ing.The
409 (Conflict)console line that also appears in the issue is expected — it's the server's "this plugin folder already exists, replace?" signal thatupload-dialog.tshandles correctly. Out of scope for this PR.Refs #212.
Test plan
npm run lint,tsc --noEmit,npm run test:jsall pass.