-
-
Couldn't load subscription status.
- Fork 3.8k
Add OTA metadata validation v2 #4998
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a073bf3
5ca10f3
0c22163
c66d67d
a04d702
b268aea
d538736
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| Import('env') | ||
| import subprocess | ||
| import json | ||
| import re | ||
|
|
||
| def get_github_repo(): | ||
|
|
@@ -42,7 +43,7 @@ def get_github_repo(): | |
|
|
||
| # Check if it's a GitHub URL | ||
| if 'github.com' not in remote_url.lower(): | ||
| return 'unknown' | ||
| return None | ||
|
|
||
| # Parse GitHub URL patterns: | ||
| # https://github.com/owner/repo.git | ||
|
|
@@ -63,17 +64,53 @@ def get_github_repo(): | |
| if ssh_match: | ||
| return ssh_match.group(1) | ||
|
|
||
| return 'unknown' | ||
| return None | ||
|
|
||
| except FileNotFoundError: | ||
| # Git CLI is not installed or not in PATH | ||
| return 'unknown' | ||
| return None | ||
| except subprocess.CalledProcessError: | ||
| # Git command failed (e.g., not a git repo, no remote, etc.) | ||
| return 'unknown' | ||
| return None | ||
| except Exception: | ||
| # Any other unexpected error | ||
| return 'unknown' | ||
| return None | ||
|
|
||
| repo = get_github_repo() | ||
| env.Append(BUILD_FLAGS=[f'-DWLED_REPO=\\"{repo}\\"']) | ||
| # WLED version is managed by package.json; this is picked up in several places | ||
| # - It's integrated in to the UI code | ||
| # - Here, for wled_metadata.cpp | ||
| # - The output_bins script | ||
| # We always take it from package.json to ensure consistency | ||
| with open("package.json", "r") as package: | ||
| WLED_VERSION = json.load(package)["version"] | ||
|
Comment on lines
+84
to
+85
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add error handling for module-level package.json read. Reading package.json at module level without error handling will cause the entire import to fail with a cryptic error if the file is missing or malformed. This is more critical than runtime errors because it affects script initialization. Apply this diff to add error handling: -with open("package.json", "r") as package:
- WLED_VERSION = json.load(package)["version"]
+try:
+ with open("package.json", "r") as package:
+ WLED_VERSION = json.load(package)["version"]
+except FileNotFoundError:
+ raise FileNotFoundError("package.json not found - required for version metadata")
+except (KeyError, json.JSONDecodeError) as e:
+ raise ValueError(f"Failed to extract version from package.json: {e}")🤖 Prompt for AI Agents |
||
|
|
||
| def has_def(cppdefs, name): | ||
| """ Returns true if a given name is set in a CPPDEFINES collection """ | ||
| for f in cppdefs: | ||
| if isinstance(f, tuple): | ||
| f = f[0] | ||
| if f == name: | ||
| return True | ||
| return False | ||
|
|
||
|
|
||
| def add_wled_metadata_flags(env, node): | ||
| cdefs = env["CPPDEFINES"].copy() | ||
|
|
||
| if not has_def(cdefs, "WLED_REPO"): | ||
| repo = get_github_repo() | ||
| if repo: | ||
| cdefs.append(("WLED_REPO", f"\\\"{repo}\\\"")) | ||
|
|
||
| cdefs.append(("WLED_VERSION", WLED_VERSION)) | ||
|
|
||
| # This transforms the node in to a Builder; it cannot be modified again | ||
| return env.Object( | ||
| node, | ||
| CPPDEFINES=cdefs | ||
| ) | ||
|
|
||
| env.AddBuildMiddleware( | ||
| add_wled_metadata_flags, | ||
| "*/wled_metadata.cpp" | ||
| ) | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for package.json read operation.
Reading package.json without error handling could cause cryptic build failures if the file is missing, malformed, or lacks the "version" field. Build scripts should provide clear error messages.
Apply this diff to add error handling:
📝 Committable suggestion
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's worth the effort right now: raising any exception from support scripts isn't handled well in PlatformIO, any way you slice it it's not easy to read afterwards. (Also there are many more places that depend on this -- if this fails, you'll have half a dozen other build problems, too.) Finally, the whole thing needs to be refactored with the other build scripts to do provenance analysis in one place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@willmmiles, that makes sense! I appreciate the context about PlatformIO's exception handling behavior and the broader refactoring plans. You're right that if
package.jsonis missing or malformed, there would be cascading failures throughout the build anyway, making the specific error location clear enough.Looking forward to seeing the provenance analysis consolidation when you get to that refactoring! 🐰
🧠 Learnings used