fix(windows): json unmarshal errors in telemetry and pg-delta declarative sync#5128
Open
fix(windows): json unmarshal errors in telemetry and pg-delta declarative sync#5128
Conversation
…tive sync Three Windows-only failures, all surfacing as JSON parse errors: 1. telemetry: any field-level unmarshal error (e.g. session_last_active stored as a number) now recreates state instead of propagating, since identity fields aren't worth surfacing an error for. 2. pg-delta declarative sync: containerRef now normalises Windows path separators with filepath.ToSlash so paths like supabase\.temp\pgdelta\catalog-baseline.json resolve correctly inside the Linux edge-runtime container. 3. pg-delta export/diff: parse callers (DeclarativeExportPgDeltaRef, ExportCatalogPgDelta, pgcache.exportCatalog) now surface stderr when stdout is empty, instead of failing later with "unexpected end of JSON input". DiffPgDeltaRef intentionally still accepts empty stdout as a legitimate "no schema changes" result. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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
Three Windows-only failures, all surfacing as JSON parse errors. None reproduce on macOS or Linux.
Reported errors
1.
supabase telemetry disableThe on-disk
~/.supabase/telemetry.jsonhadsession_last_activestored as a number (epoch millis) instead of an RFC3339 string —time.Time.UnmarshalJSONrejects numbers.LoadOrCreateStateonly handledos.ErrNotExist, so the parse error propagated and the command crashed.2.
supabase db schema declarative sync --experimental(export step)The catalog file path was constructed on Windows with
filepath.Join, which produces\separators.containerRefprefixed it with/workspace/and passed it to the Linux edge-runtime container, which cannot read backslash paths. Before this PR the subprocess crashed silently and the user only saw the much less helpfulunexpected end of JSON inputfromjson.Unmarshalon empty stdout — surfacing stderr is what made the underlying path bug visible in the first place.3.
supabase db schema declarative sync --experimental(diff step)For the export and catalog scripts, empty stdout means the subprocess crashed. For the diff script, empty stdout means there are simply no schema changes. The empty-stdout guard therefore lives in the export and catalog callers (which require non-empty output), and the diff caller correctly accepts empty stdout as "no changes".
Fixes
internal/telemetry/state.go: sentinelerrMalformedStateso any unmarshal failure (*json.SyntaxError,*json.UnmarshalTypeError,time.Time.UnmarshalJSON, …) recreates state. Identity fields are not worth surfacing an error for; losing them is harmless.internal/db/diff/pgdelta.go:containerRefrunsfilepath.ToSlashso Windows paths normalise before being passed into the Linux container.DeclarativeExportPgDeltaRefandExportCatalogPgDeltanow error with stderr when stdout is empty, instead of failing later withunexpected end of JSON input.internal/db/pgcache/cache.go: same empty-stdout guard onexportCatalog.Test plan
go build ./...TestLoadOrCreateState/recovers_from_corrupted_state_file— table covering empty file, truncated JSON,session_last_activeas number,session_last_activeas malformed stringTestContainerRef— Windows path with\separators, Unix path passthrough, postgres URL passthroughgo run . telemetry disableagainst the actually-corrupted file → succeeds, file rewritten with valid JSONgo run . db schema declarative sync --experimental --yes→No schema changes found(previously crashed withunexpected end of JSON input)🤖 Generated with Claude Code