Improve readability of errors#2372
Conversation
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 <[email protected]>
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 <[email protected]>
|
@kolyshkin @AkihiroSuda PTAL I'm also wondering if we could replace these custom error-types with (e.g.) github.com/pkg/errors, and use |
+1 to this suggestion @thaJeztah |
|
Yeah, these custom error types were written back before |
|
I started a scratch document to see if anything relies on them specifically (original implementation of the "rich" errors was in docker-archive/libcontainer#185, but looks like it was never really used beyond the initial changes). A quick search on github also didn't reveal active use of them, so looks like it should be able to replace them |
libcontainer: don't double-quote errors
genericError.Error() was formatting the underlying error using
%q; as aresult, quotes in underlying errors were escaped multiple times, which
caused the output to become hard to read, for example (wrapped for readability):
With this patch applied:
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):
With this patch applied: