From 2adfd20ac9dcaf2824959e4989983c6a1790a800 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 3 May 2020 02:11:02 +0200 Subject: [PATCH 1/2] libcontainer: don't double-quote errors genericError.Error() was formatting the underlying error using `%q`; as a result, quotes in underlying errors were escaped multiple times, which caused the output to become hard to read, for example (wrapped for readability): ``` container_linux.go:345: starting container process caused "process_linux.go:430: container init caused \"rootfs_linux.go:58: mounting \\\"/foo.txt\\\" to rootfs \\\"/var/lib/docker/overlay2/f49a0ae0ec6646c818dcf05dbcbbdd79fc7c42561f3684fbb1fc5d2b9d3ad192/merged\\\" at \\\"/var/lib/docker/overlay2/f49a0ae0ec6646c818dcf05dbcbbdd79fc7c42561f3684fbb1fc5d2b9d3ad192/merged/usr/share/nginx/html\\\" caused \\\"not a directory\\\"\"": unknown ``` With this patch applied: ``` container_linux.go:348: starting container process caused: process_linux.go:438: container init caused: rootfs_linux.go:58: mounting "/foo.txt" to rootfs "/var/lib/docker/overlay2/de506d67da606b807009e23b548fec60d72359c77eec88785d8c7ecd54a6e4b2/merged" at "/var/lib/docker/overlay2/de506d67da606b807009e23b548fec60d72359c77eec88785d8c7ecd54a6e4b2/merged/usr/share/nginx/html" caused: not a directory: unknown ``` Signed-off-by: Sebastiaan van Stijn --- libcontainer/generic_error.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcontainer/generic_error.go b/libcontainer/generic_error.go index 6e7de2fe..d185ebd8 100644 --- a/libcontainer/generic_error.go +++ b/libcontainer/generic_error.go @@ -80,7 +80,7 @@ func (e *genericError) Error() string { return e.Message } frame := e.Stack.Frames[0] - return fmt.Sprintf("%s:%d: %s caused %q", frame.File, frame.Line, e.Cause, e.Message) + return fmt.Sprintf("%s:%d: %s caused: %s", frame.File, frame.Line, e.Cause, e.Message) } func (e *genericError) Code() ErrorCode { From 64ca54816c38e3847cb4aae7521be426c66d527d Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sun, 3 May 2020 02:59:46 +0200 Subject: [PATCH 2/2] libcontainer: simplify error message The error message was including both the rootfs path, and the full mount path, which also includes the path of the rootfs. This patch removes the rootfs path from the error message, as it was redundant, and made the error message overly verbose Before this patch (errors wrapped for readability): ``` container_linux.go:348: starting container process caused: process_linux.go:438: container init caused: rootfs_linux.go:58: mounting "/foo.txt" to rootfs "/var/lib/docker/overlay2/de506d67da606b807009e23b548fec60d72359c77eec88785d8c7ecd54a6e4b2/merged" at "/var/lib/docker/overlay2/de506d67da606b807009e23b548fec60d72359c77eec88785d8c7ecd54a6e4b2/merged/usr/share/nginx/html" caused: not a directory: unknown ``` With this patch applied: ``` container_linux.go:348: starting container process caused: process_linux.go:438: container init caused: rootfs_linux.go:58: mounting "/foo.txt" to rootfs at "/var/lib/docker/overlay2/de506d67da606b807009e23b548fec60d72359c77eec88785d8c7ecd54a6e4b2/merged/usr/share/nginx/html" caused: not a directory: unknown ``` Signed-off-by: Sebastiaan van Stijn --- libcontainer/rootfs_linux.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcontainer/rootfs_linux.go b/libcontainer/rootfs_linux.go index df2fa03d..62fad7ed 100644 --- a/libcontainer/rootfs_linux.go +++ b/libcontainer/rootfs_linux.go @@ -55,7 +55,7 @@ func prepareRootfs(pipe io.ReadWriter, iConfig *initConfig) (err error) { } } if err := mountToRootfs(m, config.Rootfs, config.MountLabel, hasCgroupns); err != nil { - return newSystemErrorWithCausef(err, "mounting %q to rootfs %q at %q", m.Source, config.Rootfs, m.Destination) + return newSystemErrorWithCausef(err, "mounting %q to rootfs at %q", m.Source, m.Destination) } for _, postcmd := range m.PostmountCmds {