[parted-devel] [PATCH] parted: make the warning message more informative
Jim Meyering
jim at meyering.net
Wed Oct 12 18:28:10 UTC 2011
Petr Uzel wrote:
> Following parted message is not quite useful:
>
> Error: You requested a partition from 2.00MiB to 3.00MiB.
> The closest location we can manage is 2.00MiB to 3.00MiB.
>
> Improve the message by including exact geometry (in sectors):
>
> Error: You requested a partition from 2.00MiB to 3.00MiB (sectors 2048 - 3072).
> The closest location we can manage is 2.00MiB to 3.00MiB (sectors 2049 - 3072).
>
> * parted/parted.c (do_mkpart): Include exact partition geometry in
> the warning message.
> ---
> parted/parted.c | 10 +++++++---
> 1 files changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/parted/parted.c b/parted/parted.c
> index bc14322..2af3cbd 100644
> --- a/parted/parted.c
> +++ b/parted/parted.c
> @@ -651,10 +651,14 @@ do_mkpart (PedDevice** dev)
> (opt_script_mode
> ? PED_EXCEPTION_CANCEL
> : PED_EXCEPTION_YES_NO),
> - _("You requested a partition from %s to %s.\n"
> + _("You requested a partition from %s to %s "
> + "(sectors %llu - %llu).\n"
> "The closest location we can manage is "
> - "%s to %s.%s"),
> - start_usr, end_usr, start_sol, end_sol,
> + "%s to %s (sectors %llu - %llu).%s"),
> + start_usr, end_usr,
> + start, end,
> + start_sol, end_sol,
> + part->geom.start, part->geom.end,
> (opt_script_mode ? ""
> : _("\nIs this still acceptable to you?"))))
> {
Thanks.
I liked this, but preferred to use ".." to indicate the range, rather than "-":
> Error: You requested a partition from 2.00MiB to 3.00MiB (sectors 2048..3072).
> The closest location we can manage is 2.00MiB to 3.00MiB (sectors 2049..3072).
Also, I had to adapt one of the tests to accept the now-modified output.
Here's your slightly modified patch, followed by
the test changes I made (also including a file name change
s/errS/err.expected/, for clarity). They're separate now, just
to show you the differences. I'm about to fold the test changes
into your change-set.
>From 7c3f2feb3085f55807fe2b9d59002098812506f7 Mon Sep 17 00:00:00 2001
From: Petr Uzel <petr.uzel at suse.cz>
Date: Mon, 10 Oct 2011 15:53:09 +0200
Subject: [PATCH 1/2] parted: make the warning message more informative
Following parted message is not quite useful:
Error: You requested a partition from 2.00MiB to 3.00MiB.
The closest location we can manage is 2.00MiB to 3.00MiB.
Improve the message by including exact geometry (in sectors):
Error: You requested a partition from 2.00MiB to 3.00MiB (sectors 2048..3072).
The closest location we can manage is 2.00MiB to 3.00MiB (sectors 2049..3072).
* parted/parted.c (do_mkpart): Include exact partition geometry in
the warning message.
---
parted/parted.c | 10 +++++++---
1 files changed, 7 insertions(+), 3 deletions(-)
diff --git a/parted/parted.c b/parted/parted.c
index bc14322..b381768 100644
--- a/parted/parted.c
+++ b/parted/parted.c
@@ -651,10 +651,14 @@ do_mkpart (PedDevice** dev)
(opt_script_mode
? PED_EXCEPTION_CANCEL
: PED_EXCEPTION_YES_NO),
- _("You requested a partition from %s to %s.\n"
+ _("You requested a partition from %s to %s "
+ "(sectors %llu..%llu).\n"
"The closest location we can manage is "
- "%s to %s.%s"),
- start_usr, end_usr, start_sol, end_sol,
+ "%s to %s (sectors %llu..%llu).%s"),
+ start_usr, end_usr,
+ start, end,
+ start_sol, end_sol,
+ part->geom.start, part->geom.end,
(opt_script_mode ? ""
: _("\nIs this still acceptable to you?"))))
{
--
1.7.7.143.g13ba4
>From c6d82805d352967b733ccd5192fbec886b407c62 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Wed, 12 Oct 2011 19:56:28 +0200
Subject: [PATCH 2/2] * tests/t-lib-helpers.sh (normalize_part_diag_): Adapt
to
handle the new form of the diagnostic.
---
tests/t-lib-helpers.sh | 6 +++---
tests/t7000-scripting.sh | 12 ++++++------
2 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/tests/t-lib-helpers.sh b/tests/t-lib-helpers.sh
index d56a111..bb41139 100644
--- a/tests/t-lib-helpers.sh
+++ b/tests/t-lib-helpers.sh
@@ -337,8 +337,8 @@ mdadm_create_linear_device_()
# Often, when parted cannot use the specified size or start/endpoints
# of a partition, it outputs a warning or error like this:
#
-# Error: You requested a partition from 512B to 50.7kB.
-# The closest location we can manage is 17.4kB to 33.8kB.
+# Error: You requested a partition from 512B to 50.7kB (...).
+# The closest location we can manage is 17.4kB to 33.8kB (...).
#
# But those numbers depend on sector size, so
# replace the specific values with place-holders,
@@ -346,7 +346,7 @@ mdadm_create_linear_device_()
normalize_part_diag_()
{
local file=$1
- sed 's/ [0-9.k]*B to [0-9.k]*B\.$/ X to Y./' $file > $file.t \
+ sed 's/ [0-9.k]*B to [0-9.k]*B (sectors .*$/ X to Y./' $file > $file.t \
&& mv $file.t $file && return 0
return 1
}
diff --git a/tests/t7000-scripting.sh b/tests/t7000-scripting.sh
index 4473cb6..20b7d9f 100755
--- a/tests/t7000-scripting.sh
+++ b/tests/t7000-scripting.sh
@@ -29,15 +29,15 @@ grep '^#define HAVE_LIBREADLINE 1' $CONFIG_HEADER > /dev/null \
|| skip_ "configured without readline support"
# The failure messages.
-cat << EOF > errS || fail=1
-Error: You requested a partition from 512B to 50.7kB.
-The closest location we can manage is 17.4kB to 33.8kB.
+cat << EOF > err.expected || fail=1
+Error: You requested a partition from 512B to 50.7kB (sectors 0..0).
+The closest location we can manage is 17.4kB to 33.8kB (sectors 0..0).
EOF
-normalize_part_diag_ errS || fail=1
+normalize_part_diag_ err.expected || fail=1
{ emit_superuser_warning
- sed s/Error/Warning/ errS
+ sed s/Error/Warning/ err.expected
printf 'Is this still acceptable to you?\nYes/No?'; } >> errI || fail=1
for mkpart in mkpart; do
@@ -52,7 +52,7 @@ for mkpart in mkpart; do
# Compare the real error and the expected one
normalize_part_diag_ out || fail=1
- compare out errS || fail=1
+ compare out err.expected || fail=1
# Test mkpart interactive mode.
# Create the test file
--
1.7.7.143.g13ba4
More information about the parted-devel
mailing list