mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #41327 from thaJeztah/improve_build_errors
Builder: print relative path if COPY/ADD source path was not found
This commit is contained in:
commit
0db8310ec1
2 changed files with 7 additions and 6 deletions
|
@ -242,6 +242,8 @@ func (o *copier) calcCopyInfo(origPath string, allowWildcards bool) ([]copyInfo,
|
|||
// Deal with the single file case
|
||||
copyInfo, err := copyInfoForFile(o.source, origPath)
|
||||
switch {
|
||||
case imageSource == nil && errors.Is(err, os.ErrNotExist):
|
||||
return nil, errors.Wrapf(err, "file not found in build context or excluded by .dockerignore")
|
||||
case err != nil:
|
||||
return nil, err
|
||||
case copyInfo.hash != "":
|
||||
|
@ -315,6 +317,10 @@ func (o *copier) copyWithWildcards(origPath string) ([]copyInfo, error) {
|
|||
func copyInfoForFile(source builder.Source, path string) (copyInfo, error) {
|
||||
fi, err := remotecontext.StatAt(source, path)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
// return the relative path in the error, which is more user-friendly than the full path to the tmp-dir
|
||||
return copyInfo{}, errors.WithStack(&os.PathError{Op: "stat", Path: path, Err: os.ErrNotExist})
|
||||
}
|
||||
return copyInfo{}, err
|
||||
}
|
||||
|
||||
|
|
|
@ -2189,18 +2189,13 @@ func (s *DockerSuite) TestBuildEntrypointRunCleanup(c *testing.T) {
|
|||
|
||||
func (s *DockerSuite) TestBuildAddFileNotFound(c *testing.T) {
|
||||
name := "testbuildaddnotfound"
|
||||
expected := "foo: no such file or directory"
|
||||
|
||||
if testEnv.OSType == "windows" {
|
||||
expected = "foo: The system cannot find the file specified"
|
||||
}
|
||||
|
||||
buildImage(name, build.WithBuildContext(c,
|
||||
build.WithFile("Dockerfile", `FROM `+minimalBaseImage()+`
|
||||
ADD foo /usr/local/bar`),
|
||||
build.WithFile("bar", "hello"))).Assert(c, icmd.Expected{
|
||||
ExitCode: 1,
|
||||
Err: expected,
|
||||
Err: "stat foo: file does not exist",
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue