Repository navigation
fix: return errors instead of panicking on malformed layers - #808
Open
NopeCharon wants to merge 1 commit into
Open
NopeCharon wants to merge 1 commit into
NopeCharon wants to merge 1 commit into
Conversation
parseLayers() validated the directives of each layer with unchecked
type assertions on the raw YAML: the layer body and the 'from' value
were asserted to be yaml.MapSlice and every directive key was asserted
to be a string. A stacker file such as
foo:
from: docker://ubuntu:latest
or a layer with an empty body or a non-string key therefore crashed
stacker with "interface conversion" panics instead of reporting what
was wrong with the file.
Similarly, an empty string entry in 'imports' (which can result from a
substitution with an empty default, e.g. "- ${{EXTRA:}}") made
Layer.absolutify() slice the path with a negative index and panic.
Check every assertion and return a descriptive error naming the layer,
and reject empty import paths when parsing the import entry, the same
way an import map without a 'path' is already rejected.
Add unit tests covering each malformed input.
Fixes project-stacker#807
Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>
NopeCharon
requested review from
hallyn,
mikemccracken,
raharper,
rchamarthy,
rchincha,
smoser and
tych0
as code owners
October 24, 2026 19:45
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #808 +/- ##
===========================================
- Coverage 55.06% 13.28% -41.79%
===========================================
Files 55 55
Lines 5911 5932 +21
===========================================
- Hits 3255 788 -2467
- Misses 2085 5021 +2936
+ Partials 571 123 -448 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What type of PR is this?
bug
Which issue does this PR fix:
Fixes #807
What does this PR do / Why do we need it:
parseLayers()checks the directives of each layer using unchecked type assertions on the raw YAML. Because of that, some malformed stacker files crash stacker with a Go panic instead of producing an error. The most common case is writingfromas a string:An empty layer body (
foo:), a layer that is a scalar (foo: bar), and non-string directive keys also panic. Separately, an empty string entry inimports(for example from- ${{EXTRA:}}) panicked inLayer.absolutify()withslice bounds out of range [-1:].This PR:
parseLayers()and returns a descriptive error that names the layer, e.g.stackerfile: layer 'foo': 'from' must be a map with a 'type' and a 'url' or 'tag', found: "docker://ubuntu:latest"getImportFromInterface(). An import map without apathis already rejected there.If an issue # is not available please add repro steps and logs showing the issue:
See #807.
Testing done on this change:
Added
TestMalformedLayers(one case for each malformed input) and an empty-string case inTestGetImportFromInterface. Without the fix, both tests fail with the panics described in the issue:With the fix,
go test ./pkg/types/passes (on linux/arm64, using the Makefile's go-test build tags):Automation added to e2e:
No. The parsing is covered by Go unit tests in
pkg/types.Will this break upgrades or downgrades?
No. Stacker files that parsed before still parse the same way. Only inputs that used to panic now return an error.
Does this PR introduce any user-facing change?:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.