fix(ci): handle empty API responses safely in azure_marketplace_publi… - #4208
Open
shellyco-code wants to merge 1 commit into
Open
fix(ci): handle empty API responses safely in azure_marketplace_publi…#4208shellyco-code wants to merge 1 commit into
shellyco-code wants to merge 1 commit into
Conversation
…sh.py Signed-off-by: shellyco-code <shellychahar57@gmail.com>
sayanchowdhury
left a comment
Member
There was a problem hiding this comment.
Thanks for the contribution @shellyco-code
Currently there is too much of duplication of the code. How about having a method like _parse_json_dict(resp, context) where the context can have all the info to build the error message.
Comment on lines
+424
to
+425
| product_durable_id = product_durable_id.split("/")[-1] | ||
| plan_durable_id = plan_durable_id.split("/")[-1] |
Member
There was a problem hiding this comment.
Can we leave updating the index?
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.
This PR fixes potential
IndexErrorandJSONDecodeErrorruntime exceptions inci-automation/release/azure_marketplace_publish.py. When fetching product or plan durable IDs from Microsoft Partner Center (get_product_durable_idandget_plan_durable_id), empty API responses or unexpected payloads caused fixed-index string splits (split("/")[1]/split("/")[2]) to throw anIndexError.To prevent crashes during marketplace image publishing, string path splits were updated to
.split("/")[-1]alongside early null-checks (if not product_durable_id:/if not plan_durable_id:) to safely skip invalid offers. Additionally, try/except error handling was wrapped aroundresp.json()acrossget_product_durable_id,get_plan_durable_id,get_image_versions, andgenerate_partner_center_tokento validate dictionary structures before accessing response fields, andget_active_plansnow falls back to returning[]ifchannel-info.txtcannot be fetched.Fixes flatcar/Flatcar#2316.
How to use
Reviewers can inspect
ci-automation/release/azure_marketplace_publish.pyor execute the publishing script in test mode (-t/--test-mode) with Partner Center credentials to verify that missing or empty API responses for offers or plans log an error and skip cleanly without raising unhandledIndexErrorexceptions.Testing done
Output:
Exit code 0 (no syntax errors)Executed unit tests covering valid API payloads, empty
{"value": []}arrays, non-JSON HTTP responses, and variable-length ID path formats:Output:
changelog/directory (user-facing change, bug fix, security fix, update)/bootand/usrsize, packages, list files for any missing binaries, kernel modules, config files, kernel modules, etc.Signed-off-by: shellyco-code shellychahar57@gmail.com