fix(tag-db): import fs so SG tag database uploads persist - #40
Merged
Conversation
The /upload-sg-tag-file handler calls fs.writeFileSync() but never imported fs, so every upload threw `ReferenceError: fs is not defined` after the handler had already run `rm /data/sg_files/SG_tag_database*`. Net effect: uploading a tag database deleted the existing one and wrote nothing, leaving an empty/missing SG_tag_database.sqlite and causing the SensorGnome interface to fail with `no such table: tags`. Add the missing `import fs from 'fs'`. Co-Authored-By: Claude Opus 4.8 (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.
Problem
Uploading a SensorGnome tag database through the web interface silently destroyed the existing database and stored nothing. The SensorGnome interface then failed with:
i.e.
Error: no such table: tags, because/data/sg_files/SG_tag_database.sqlitewas left empty (0 bytes).Root cause
src/station-interface/routes/sensorgnome/upload-sg-tag-file.jscallsfs.writeFileSync(uri, req.body)but only importedRunCommand—fswas never imported. The handler runs in order:rm /data/sg_files/SG_tag_database*— deletes the current tag DB (succeeds)fs.writeFileSync(...)— throwsReferenceError: fs is not definedSo every upload wiped the old database and wrote nothing. Confirmed on-station in the
station-web-interfacelogs:Fix
Add the missing
import fs from 'fs'.Follow-up (not in this PR)
The handler still
rms the existing DB before writing the new one, so an aborted/invalid upload can still destroy a working database. A safer pattern would write to a temp file and rename into place only on success. Left out here to keep this a focused, minimal fix for the reported bug.Related
Same fix for the
lts_24-06.isobranch: #39🤖 Generated with Claude Code