Skip to content

Fix debugger upload path for C/C++ function blocks#701

Open
manux81 wants to merge 5 commits into
Autonomy-Logic:developmentfrom
manux81:fix/cpp-debugger-upload-path
Open

Fix debugger upload path for C/C++ function blocks#701
manux81 wants to merge 5 commits into
Autonomy-Logic:developmentfrom
manux81:fix/cpp-debugger-upload-path

Conversation

@manux81
Copy link
Copy Markdown

@manux81 manux81 commented Mar 24, 2026

Summary

Fix the debugger upload flow so C/C++ function blocks are preprocessed consistently.

Problem

When debugger MD5 verification failed and the user chose to upload the current project, the UI invoked runCompileProgram with raw project data instead of preprocessed project data.

This caused C/C++ function block source to pass through the IEC ST/XML pipeline as plain text during the second compilation path, producing different generated sources and causing iec2c to fail.

Fix

Apply preprocessPous() before calling runCompileProgram from the debugger mismatch upload flow, and stop early if validation fails.

Validation

  • Verified the updated flow uses preprocessed project data
  • Confirmed lint passes on the modified file

Summary by CodeRabbit

  • Bug Fixes

    • Added validation check to prevent invalid project data from being processed during debugging.
    • Ensured latest project data is used in debug workflows instead of potentially stale versions.
  • Refactor

    • Consolidated project preprocessing logic for improved consistency across compilation and debugging workflows.

When debugger MD5 verification failed and the user chose to upload the current project, the UI called runCompileProgram with the raw project data instead of the preprocessed project data.

That bypassed preprocessPous() for the second compilation path, so C/C++ function block bodies were sent through the IEC ST/XML pipeline as plain source code. In practice this produced a different second source set and caused iec2c to fail on invalid IL/ST instructions such as C comments, #include directives, and setup()/loop() declarations.

This change applies the same preprocessPous() step used by the normal compile and debug flows before invoking runCompileProgram from the debugger mismatch flow, and aborts early if C/C++ validation fails.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 24, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 82159a51-0be9-43ac-9803-1cdd0f355aa8

📥 Commits

Reviewing files that changed from the base of the PR and between 1a83859 and 70e090f.

📒 Files selected for processing (1)
  • src/renderer/components/_organisms/workspace-activity-bar/default.tsx

Walkthrough

The PR refactors preprocessing logic in the workspace activity bar component by introducing a prepareProjectForCompile helper function that centralizes project data preprocessing and validation, updating compile and debugger flows to use this helper, and adding early termination on validation failures.

Changes

Cohort / File(s) Summary
Preprocessing Consolidation
src/renderer/components/_organisms/workspace-activity-bar/default.tsx
Introduced prepareProjectForCompile helper to centralize preprocessPous calls with logging. Updated compile trigger and simulator-target debugger paths to use this helper. Modified debugger upload-then-verify flow to fetch latest project state from store and added early termination on validation failure before compile invocation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #625: Modifies the same workspace activity bar file and affects debugger/simulator compile flow; aligns with the preprocessing consolidation and control flow improvements introduced here.

Poem

🐰 Preprocessing hops from place to place,
Now gathered in one cozy space!
The debugger checks before it flies,
With validation's watchful eyes. ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main fix: ensuring C/C++ function blocks are preprocessed in the debugger upload path, which is the core change in this PR.
Description check ✅ Passed The description provides a clear problem statement, explains the fix, and includes validation steps. However, it lacks references to issue/Jira tickets and doesn't include the DOD checklist from the template.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/renderer/components/_organisms/workspace-activity-bar/default.tsx (1)

897-909: Good fix—consider sharing the compile-prep block.

This upload path now repeats the same preprocessPous(...)/validationFailed gate used at Lines 108-116 and 580-588. Since this PR exists because one compile path drifted, pulling that prep into a small helper would make the runCompileProgram/runDebugCompilation call sites much harder to desync again.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/components/_organisms/workspace-activity-bar/default.tsx` around
lines 897 - 909, Extract the repeated preprocessing + validation gate into a
small helper (e.g., prepareProjectForCompile) that calls
preprocessPous(projectData, isSimulatorTarget(currentBoardInfo), (level,
message) => consoleActions.addLog(...)) and returns { processedProjectData,
validationFailed }; replace the duplicated blocks before
window.bridge.runCompileProgram and before the runDebugCompilation call with
this helper and ensure you still call setIsDebuggerProcessing(false) and return
when validationFailed is true; keep the same arguments passed to
runCompileProgram (processedProjectData, targetIpAddress, runtimeJwtToken) so
call sites remain identical except for using the helper.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/renderer/components/_organisms/workspace-activity-bar/default.tsx`:
- Around line 897-909: Extract the repeated preprocessing + validation gate into
a small helper (e.g., prepareProjectForCompile) that calls
preprocessPous(projectData, isSimulatorTarget(currentBoardInfo), (level,
message) => consoleActions.addLog(...)) and returns { processedProjectData,
validationFailed }; replace the duplicated blocks before
window.bridge.runCompileProgram and before the runDebugCompilation call with
this helper and ensure you still call setIsDebuggerProcessing(false) and return
when validationFailed is true; keep the same arguments passed to
runCompileProgram (processedProjectData, targetIpAddress, runtimeJwtToken) so
call sites remain identical except for using the helper.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 854a4f37-a7a9-40b7-a83d-631dfdf84f63

📥 Commits

Reviewing files that changed from the base of the PR and between 8817969 and a7f9328.

📒 Files selected for processing (1)
  • src/renderer/components/_organisms/workspace-activity-bar/default.tsx

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/renderer/components/_organisms/workspace-activity-bar/default.tsx (1)

895-895: Consider fetching project data fresh from the store for consistency.

Within handleMd5Verification, other data is fetched fresh from the store (lines 655, 790, 894), but prepareProjectForCompile() uses projectData captured in the component's closure. In long-running async flows with potential delays (e.g., the setTimeout at line 939), the closure-captured data could become stale relative to the store.

This is a pre-existing pattern and low risk, but for consistency you could consider passing project data explicitly:

♻️ Optional: Fetch fresh project data in async handlers
  const prepareProjectForCompile = () => {
-   return preprocessPous(projectData, isCurrentBoardSimulator, (level, message) =>
+   const { project } = useOpenPLCStore.getState()
+   return preprocessPous(project.data, isCurrentBoardSimulator, (level, message) =>
      addLog({ id: crypto.randomUUID(), level, message }),
    )
  }

Alternatively, fetch project data at the call site and pass it:

const prepareProjectForCompile = (data: PLCProjectData) => {
  return preprocessPous(data, isCurrentBoardSimulator, (level, message) =>
    addLog({ id: crypto.randomUUID(), level, message }),
  )
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/renderer/components/_organisms/workspace-activity-bar/default.tsx` at
line 895, The closure-captured projectData used by prepareProjectForCompile can
become stale in long-running async flows (e.g., handleMd5Verification); update
prepareProjectForCompile to accept PLCProjectData as an explicit argument and
change callers (including the call inside handleMd5Verification) to fetch the
latest projectData from the store before invoking it so the function uses fresh
data; reference prepareProjectForCompile and handleMd5Verification to locate and
update the implementation and call sites, and preserve the existing addLog
callback behavior when you refactor.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/renderer/components/_organisms/workspace-activity-bar/default.tsx`:
- Line 895: The closure-captured projectData used by prepareProjectForCompile
can become stale in long-running async flows (e.g., handleMd5Verification);
update prepareProjectForCompile to accept PLCProjectData as an explicit argument
and change callers (including the call inside handleMd5Verification) to fetch
the latest projectData from the store before invoking it so the function uses
fresh data; reference prepareProjectForCompile and handleMd5Verification to
locate and update the implementation and call sites, and preserve the existing
addLog callback behavior when you refactor.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 696005ce-c5cd-4275-8df1-10f743ba5616

📥 Commits

Reviewing files that changed from the base of the PR and between a7f9328 and 1a83859.

📒 Files selected for processing (1)
  • src/renderer/components/_organisms/workspace-activity-bar/default.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant