fix(ros): gate unusable local templates before the first API call - #198
Open
ruanzhengxin-zhuxing wants to merge 1 commit into
Open
fix(ros): gate unusable local templates before the first API call#198ruanzhengxin-zhuxing wants to merge 1 commit into
ruanzhengxin-zhuxing wants to merge 1 commit into
Conversation
ROS template tools reported an unusable local template as an invalid
`body_file`, a parameter the caller never sent. Callers passing
`template_url` therefore had no way to tell what to fix from the first
failure, and retried the same template input across ros_validate_template,
aliyun_api ValidateTemplate, and ros_preview_template before resorting to
bash to inspect the file.
Two defects produced that message:
- No pre-call readability gate. Permission checks only authorized the path,
so a missing or non-regular template still returned `allow` and failed
later while the wire layer materialized the request body.
- `_read_body_file` converts read failures into
`ApiContractError("invalid_body_file")`, but the local-template branches
caught only `(OSError, UnicodeError)`. The error escaped to the generic
handler and lost its template-source context and structured report.
Classify local templates (missing / not-regular / unreadable / too-large)
before credentials, endpoints, and any request, and report every failure as
a ROS1202 diagnostic carrying `metadata.ros_validation` plus a specific
corrective action. The size ceiling is derived from the wire-layer limit so
the gate and the transport cannot disagree. Applied consistently to the
runtime, legacy, and ros_stack read paths so the dedicated ROS tools and
ros_deploy all fail the same way.
Genuine `body_file` inputs keep reporting `invalid_body_file`, and the
success path is unchanged.
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
ROS template tools reported an unusable local template as an invalid
body_file— a parameter the caller never sent. Callers passingtemplate_urltherefore could not tell what to fix from the first failure, and retried the same template input acrossros_validate_template,aliyun_api ValidateTemplate, andros_preview_templatebefore resorting tobashto inspect the file.Two defects produced that message:
allowand only failed later, while the wire layer materialized the request body._read_body_fileconverts read failures intoApiContractError("invalid_body_file"), but the local-template branches caught only(OSError, UnicodeError). The error escaped to the generic handler and lost both its template-source context and its structured report.Observed before the fix — the most common failure mode returned the least diagnostic information:
allowbody_file is invalidallowbody_file is invalidallowROS1202reportros_validationChange
Classify local templates (missing / not-regular / unreadable / too-large) before credentials, endpoints, and any request, and report every failure as a
ROS1202diagnostic carryingmetadata.ros_validationplus a specific corrective action. The size ceiling is derived from the wire-layer limit so the gate and the transport cannot disagree.Applied consistently to the runtime, legacy, and
ros_stackread paths so the dedicated ROS tools andros_deployall fail the same way.Genuine
body_fileinputs keep reportinginvalid_body_file, and the success path is unchanged.Verification
make test: 13282 passed, 4 skipped. Two failures are pre-existing and unrelated — verified failing identically on the untouched base commitd470b40(a urllib error-class difference and an mtime-granularity ordering assumption).make lint(ruff+ty): clean.make translaterun for themessagesdomain; the 7 new user-facing strings are translated acrosszh es fr de ja pt.body_file, and that no request is assembled (request_builder.inputs == []).