Skip to content

refactor: added some type guards#1833

Merged
pedrolamas merged 1 commit into
fluidd-core:developfrom
pedrolamas:pedrolamas/type-guards
May 9, 2026
Merged

refactor: added some type guards#1833
pedrolamas merged 1 commit into
fluidd-core:developfrom
pedrolamas:pedrolamas/type-guards

Conversation

@pedrolamas

Copy link
Copy Markdown
Member

Improved code resilience by adding some type-guards through the app.

Also removed the obsolete socket state error property.

Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
@pedrolamas pedrolamas added this to the 1.37 milestone May 9, 2026
@pedrolamas pedrolamas requested a review from Copilot May 9, 2026 15:25
@pedrolamas pedrolamas added the Code - Optimizations Everything that relates to code optimizations! label May 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves runtime resilience by adding safer type guards around JSON parsing in a few hotspots (gcode parsing, string formatting, and drag/drop data transfer), and simplifies the socket store state by removing the obsolete socket.error field.

Changes:

  • Added defensive JSON parsing + runtime shape validation for polygon data and string-array parsing.
  • Hardened drag/drop DataTransfer parsing by validating the payload and returning null on failure; updated consumers to handle null.
  • Removed the error property from SocketState and tightened websocket error response typing.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/workers/parseGcode.ts Adds guarded JSON parsing for EXCLUDE_OBJECT_DEFINE polygon data to avoid worker crashes on malformed input.
src/util/string-formatters.ts Ensures getStringArray only returns parsed JSON when it’s truly a string[], otherwise falls back to splitting.
src/util/file-data-transfer.ts Adds a type guard + try/catch around DataTransfer JSON parsing and returns null on invalid payloads.
src/store/socket/types.ts Removes the obsolete SocketState.error field.
src/store/socket/state.ts Drops error from the socket default state.
src/store/socket/actions.ts Adds a helper to safely extract error messages from JSON-ish strings; types onSocketError payload.
src/plugins/socketClient.ts Tightens websocket API error typing to SocketError.
src/components/widgets/job-queue/JobQueue.vue Handles null from drag/drop file payload parsing before using it.
src/components/widgets/gcode-preview/GcodePreviewCard.vue Handles null from drag/drop file payload parsing before using it.
src/components/widgets/filesystem/FileSystem.vue Handles null from drag/drop file payload parsing and adjusts drop flow accordingly.

@pedrolamas pedrolamas merged commit ff6690e into fluidd-core:develop May 9, 2026
8 checks passed
@pedrolamas pedrolamas deleted the pedrolamas/type-guards branch May 9, 2026 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Code - Optimizations Everything that relates to code optimizations!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants