Repository navigation
fix(transform): don't panic on flow-style compose files in publish rewrites - #14387
TDnorthgarden wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Thanks for the fix — the panic is real (I reproduced it on main with the one-line flow document from the description), and the PR also turns a second, silent failure into a clean error: on main, env_file: [a.env, b.env] with index 1 produces env_file: [a.env, NEW (closing bracket swallowed), which is now rejected. I checked the branch locally. Rejecting flow style outright is a good call for such a rarely used syntax; a few small points, all reproduced.
1. Error does not say which file is at fault (publish.go)
publish.go:200 and :236 return the error from processFile unwrapped. Extended files are processed too (:236), so the message service "web": env_file is in flow style… doesn't tell the user which file to fix. Wrapping with the file name at those two call sites would help (small, could be a follow-up).
2. Test coverage
TestReplaceFlowStyle covers the two one-line documents only. Two cheap cases would exercise the remaining new branches:
- flow sequence
env_file: [a.env, b.env](this was silently corrupting onmain); - out-of-range
i(the new bounds check is not exercised).
3. Nits
replace: theline > 1guard leavesposat 0 for line 1, andpos += columnthen points one byte too far (columns are 1-based):replace([]byte("abc old.env"), 1, 5, "X")returnsabc oX. It is unreachable through the public functions now (any node on line 1 is flow style and rejected), so this is dead code today;column-1would make it correct if it ever becomes reachable.- The
isFlowStyledoc says a line holding "the value (and an optional trailing comment)" is safe, butreplaceoverwrites to the end of the line, so the comment is dropped (env_file: old.env # keep→env_file: NEW). Either adjust the comment or leave it; this is pre-existing and not a blocker.
d7cafdc to
c282227
Compare
Thanks for the thorough review, and for reproducing both the panic and the silent bracket-swallowing case on main.
|
…writes
replace() locates the value's line by scanning for the newline that
precedes it: line 1 has no preceding newline, so the scan ran to the
end of the stream and the column offset then sliced out of range. A
flow-style document ({services: {test: {extends: {file: x}}}}) puts
every node on line 1, and compose publish feeds the user's original
file bytes into this path (processFile), so the panic was reachable
from the CLI.
Refuse flow-style nodes explicitly instead: the rewrite runs from the
value's start to the end of its line, which would swallow the closing
braces and commas following the value in flow style and corrupt the
stream. Also guard the env_file entry index against out-of-range
values.
The processFile errors in createLayers and processExtends are wrapped
with the compose file name, so a rejection in any of the project's
files — the extended ones included — tells the user which file to fix.
Signed-off-by: Aucoto <tdnorthgarden@gmail.com>
c282227 to
df3f26d
Compare
Problem
replace()inpkg/compose/transformlocates a value's line by scanningfor the newline that precedes it. Line 1 has no preceding newline, so for a
flow-style document — where every node sits on line 1 — the scan runs to
the end of the stream, and the column offset then slices out of range:
compose publishfeeds the user's original file bytes into this path(
processFilereads the file as-is before rewriting local paths to opaquedigests), so the panic is reachable from the CLI. Flow style is valid YAML
and the compose loader accepts it.
Fix
stream) and return an error instead of panicking when the computed
position is out of range.
start to the end of its line, which would swallow the closing braces and
commas that follow the value in flow style and corrupt the stream.
env_fileentry index against out-of-range values.