linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] btrfs-progs: dump-tree: print invalid argument and strerror
@ 2018-08-30  9:08 Su Yue
  2018-09-11 14:44 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Su Yue @ 2018-08-30  9:08 UTC (permalink / raw)
  To: linux-btrfs; +Cc: suy.fnst

Before this patch:
$ ls nothingness
ls: cannot access 'nothingness': No such file or directory
$ btrfs inspect-internal dump-tree nothingness
ERROR: not a block device or regular file: nothingness

The confusing error message makes users thinks that nonexistent
file is existed but in wrong type.

This patch let check_arg_type return -errno if realpath failed.
And print strerror if check_arg_type failed and the returned code
is negative. Like:

$ btrfs inspect-internal dump-tree nothingness
ERROR: invalid argument: nothingness: No such file or directory

Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com>
---
 cmds-inspect-dump-tree.c | 7 ++++++-
 utils.c                  | 2 ++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/cmds-inspect-dump-tree.c b/cmds-inspect-dump-tree.c
index c8acd55a0c3a..f70a1c47d145 100644
--- a/cmds-inspect-dump-tree.c
+++ b/cmds-inspect-dump-tree.c
@@ -313,7 +313,12 @@ int cmd_inspect_dump_tree(int argc, char **argv)
 
 	ret = check_arg_type(argv[optind]);
 	if (ret != BTRFS_ARG_BLKDEV && ret != BTRFS_ARG_REG) {
-		error("not a block device or regular file: %s", argv[optind]);
+		if (ret < 0)
+			error("invalid argument: %s: %s", argv[optind],
+			      strerror(-ret));
+		else
+			error("not a block device or regular file: %s",
+			      argv[optind]);
 		goto out;
 	}
 
diff --git a/utils.c b/utils.c
index 1e275c668cd5..80eca77b1b20 100644
--- a/utils.c
+++ b/utils.c
@@ -502,6 +502,8 @@ int check_arg_type(const char *input)
 			return BTRFS_ARG_REG;
 
 		return BTRFS_ARG_UNKNOWN;
+	} else {
+		return -errno;
 	}
 
 	if (strlen(input) == (BTRFS_UUID_UNPARSED_SIZE - 1) &&
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2018-09-11 17:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-30  9:08 [PATCH] btrfs-progs: dump-tree: print invalid argument and strerror Su Yue
2018-09-11 14:44 ` David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).