Skip to content

fix(nodered): fix FileNotFoundError and PermissionError in preBuild#823

Open
MarcosJRcwb wants to merge 1 commit intoSensorsIot:masterfrom
MarcosJRcwb:fix/nodered-prebuild-errors
Open

fix(nodered): fix FileNotFoundError and PermissionError in preBuild#823
MarcosJRcwb wants to merge 1 commit intoSensorsIot:masterfrom
MarcosJRcwb:fix/nodered-prebuild-errors

Conversation

@MarcosJRcwb
Copy link
Copy Markdown

Problem

Two bugs were found in .templates/nodered/build.py during a fresh Node-RED setup:

Bug 1 — FileNotFoundError on first-time setup

addons_list.yml is optional and is generated via the Options menu. However, open(addonsFile) was called unconditionally before the os.path.exists() check, causing an immediate crash when the file does not yet exist:

FileNotFoundError: [Errno 2] No such file or directory: './services/nodered/addons_list.yml'

Bug 2 — PermissionError when Dockerfile was previously created as root

If the user ran menu.sh with sudo at any point, the generated Dockerfile is owned by root. On the next build run as a regular user, writing the Dockerfile fails with:

PermissionError: [Errno 13] Permission denied: './services/nodered/Dockerfile'

There was no actionable error message — the user had no way to know what went wrong or how to fix it.

Fix

  • Bug 1: Moved open(addonsFile) inside the os.path.exists() guard so the file is only opened when it actually exists.
  • Bug 2: Wrapped the Dockerfile write in a try/except PermissionError block that prints a clear message with the exact chown command needed to resolve the issue.

Testing

Reproduced both errors on a Raspberry Pi running IOTstack. Applied the fix and confirmed clean builds with and without addons_list.yml present.

…erfile write

- Fix FileNotFoundError: addons_list.yml open() was called unconditionally
  before the os.path.exists() check, causing a crash on first-time setup
  when addons_list.yml has not yet been generated via Options menu.
  File is now only opened inside the exists() guard.

- Fix PermissionError: writing services/nodered/Dockerfile now wrapped in
  try/except. If a previous build was run as sudo/root, the Dockerfile is
  owned by root and the current user cannot overwrite it. The error now
  prints a clear actionable message with the chown command to fix it.
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