fix(nodered): fix FileNotFoundError and PermissionError in preBuild#823
Open
MarcosJRcwb wants to merge 1 commit intoSensorsIot:masterfrom
Open
fix(nodered): fix FileNotFoundError and PermissionError in preBuild#823MarcosJRcwb wants to merge 1 commit intoSensorsIot:masterfrom
MarcosJRcwb wants to merge 1 commit intoSensorsIot:masterfrom
Conversation
…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.
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
Two bugs were found in
.templates/nodered/build.pyduring a fresh Node-RED setup:Bug 1 — FileNotFoundError on first-time setup
addons_list.ymlis optional and is generated via the Options menu. However,open(addonsFile)was called unconditionally before theos.path.exists()check, causing an immediate crash when the file does not yet exist:Bug 2 — PermissionError when Dockerfile was previously created as root
If the user ran
menu.shwithsudoat any point, the generatedDockerfileis owned byroot. On the next build run as a regular user, writing the Dockerfile fails with:There was no actionable error message — the user had no way to know what went wrong or how to fix it.
Fix
open(addonsFile)inside theos.path.exists()guard so the file is only opened when it actually exists.try/except PermissionErrorblock that prints a clear message with the exactchowncommand 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.ymlpresent.