diff mbox series

[bug#50982] scripts: home/system: Don’t throw an error if no generations exist.

Message ID 8c1286034c3a48353d13515f04883dbede289e0c.1633208618.git.public@yoctocell.xyz
State Accepted
Headers show
Series [bug#50982] scripts: home/system: Don’t throw an error if no generations exist. | expand

Checks

Context Check Description
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Xinglu Chen Oct. 2, 2021, 9:05 p.m. UTC
Previously, When running ‘guix home describe’ or ‘guix system describe’ prior
to having any generations, a backtrace would produced.  Since not having any
existing generations is not an error, a warning would be enough.

  $ guix system describe
  guix system: warning: no system generation, nothing to describe

* guix/scripts/home.scm (process-command): Produce a warning instead of an
error if no generations exist.
* guix/scripts/system.scm (process-command): Likewise.

Fixes: <https://issues.guix.gnu.org/50978>
Reported-by: Maxime Devos <maximedevos@telenet.be>
---
 guix/scripts/home.scm   | 2 +-
 guix/scripts/system.scm | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)


base-commit: f1a3c11407b52004e523ec5de20d326c5661681f

Comments

M Oct. 3, 2021, 8:53 a.m. UTC | #1
Xinglu Chen schreef op za 02-10-2021 om 23:05 [+0200]:
> Previously, When running ‘guix home describe’ or ‘guix system describe’ prior
> to having any generations, a backtrace would produced.  Since not having any
> existing generations is not an error, a warning would be enough.
> 
>   $ guix system describe
>   guix system: warning: no system generation, nothing to describe

Printing a warning instead of an error to avoid a backrace isn't necessary.
E.g., "guix show i-do-not-exists" prints an error
‘guix show: error: i-do-not-exist: package not found’.

I suggest using (leave (G_ "bla bla")) instead of (error (G_ "bla bla"))
for these kind of errors, it appears to work '%find-package' in (gnu packages).

I don't know if the output of "guix system describe" and "guix home describe"
should be an error or warning here ...

Greetings,
Maxime.
Ludovic Courtès Oct. 19, 2021, 1:59 p.m. UTC | #2
Hi Xinglu,

Did you have a chance to look into this?

TIA!

Ludo’.

Maxime Devos <maximedevos@telenet.be> skribis:

> Xinglu Chen schreef op za 02-10-2021 om 23:05 [+0200]:
>> Previously, When running ‘guix home describe’ or ‘guix system describe’ prior
>> to having any generations, a backtrace would produced.  Since not having any
>> existing generations is not an error, a warning would be enough.
>> 
>>   $ guix system describe
>>   guix system: warning: no system generation, nothing to describe
>
> Printing a warning instead of an error to avoid a backrace isn't necessary.
> E.g., "guix show i-do-not-exists" prints an error
> ‘guix show: error: i-do-not-exist: package not found’.
>
> I suggest using (leave (G_ "bla bla")) instead of (error (G_ "bla bla"))
> for these kind of errors, it appears to work '%find-package' in (gnu packages).
>
> I don't know if the output of "guix system describe" and "guix home describe"
> should be an error or warning here ...
>
> Greetings,
> Maxime.
Xinglu Chen Oct. 30, 2021, 11:18 a.m. UTC | #3
Hi,

On Sun, Oct 03 2021, Maxime Devos wrote:

> Xinglu Chen schreef op za 02-10-2021 om 23:05 [+0200]:
>> Previously, When running ‘guix home describe’ or ‘guix system describe’ prior
>> to having any generations, a backtrace would produced.  Since not having any
>> existing generations is not an error, a warning would be enough.
>> 
>>   $ guix system describe
>>   guix system: warning: no system generation, nothing to describe
>
> Printing a warning instead of an error to avoid a backrace isn't necessary.
> E.g., "guix show i-do-not-exists" prints an error
> ‘guix show: error: i-do-not-exist: package not found’.
>
> I suggest using (leave (G_ "bla bla")) instead of (error (G_ "bla bla"))
> for these kind of errors, it appears to work '%find-package' in (gnu packages).
>
> I don't know if the output of "guix system describe" and "guix home describe"
> should be an error or warning here ...

Hmm, since I don’t think that not having any generations is an error, I
would say it makes more sense to use ‘warning’ instead of ‘leave’.
‘leave’ would signal that something isn’t correct, which makes sense if
one runs ‘guix show doesnt-exist’, but not having any generations
doesn’t really mean that something is wrong.

WDYT?
Ludovic Courtès Oct. 30, 2021, 2:24 p.m. UTC | #4
Hi,

Xinglu Chen <public@yoctocell.xyz> skribis:

> On Sun, Oct 03 2021, Maxime Devos wrote:
>
>> Xinglu Chen schreef op za 02-10-2021 om 23:05 [+0200]:
>>> Previously, When running ‘guix home describe’ or ‘guix system describe’ prior
>>> to having any generations, a backtrace would produced.  Since not having any
>>> existing generations is not an error, a warning would be enough.
>>> 
>>>   $ guix system describe
>>>   guix system: warning: no system generation, nothing to describe
>>
>> Printing a warning instead of an error to avoid a backrace isn't necessary.
>> E.g., "guix show i-do-not-exists" prints an error
>> ‘guix show: error: i-do-not-exist: package not found’.
>>
>> I suggest using (leave (G_ "bla bla")) instead of (error (G_ "bla bla"))
>> for these kind of errors, it appears to work '%find-package' in (gnu packages).
>>
>> I don't know if the output of "guix system describe" and "guix home describe"
>> should be an error or warning here ...
>
> Hmm, since I don’t think that not having any generations is an error, I
> would say it makes more sense to use ‘warning’ instead of ‘leave’.
> ‘leave’ would signal that something isn’t correct, which makes sense if
> one runs ‘guix show doesnt-exist’, but not having any generations
> doesn’t really mean that something is wrong.

Yeah, I guess ‘warning’ is fine.

Maxime’s point is that we should always use procedures from (guix
diagnostics) for error/warning/info reports.

Thanks,
Ludo’.
Ludovic Courtès Jan. 6, 2022, 10:28 a.m. UTC | #5
Maxime Devos <maximedevos@telenet.be> skribis:

> Xinglu Chen schreef op za 02-10-2021 om 23:05 [+0200]:
>> Previously, When running ‘guix home describe’ or ‘guix system describe’ prior
>> to having any generations, a backtrace would produced.  Since not having any
>> existing generations is not an error, a warning would be enough.
>> 
>>   $ guix system describe
>>   guix system: warning: no system generation, nothing to describe
>
> Printing a warning instead of an error to avoid a backrace isn't necessary.
> E.g., "guix show i-do-not-exists" prints an error
> ‘guix show: error: i-do-not-exist: package not found’.
>
> I suggest using (leave (G_ "bla bla")) instead of (error (G_ "bla bla"))
> for these kind of errors, it appears to work '%find-package' in (gnu packages).

I’ve done that now, thanks!

Ludo’.
diff mbox series

Patch

diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm
index 75df6d707d..70860564eb 100644
--- a/guix/scripts/home.scm
+++ b/guix/scripts/home.scm
@@ -260,7 +260,7 @@  (define-syntax-rule (with-store* store exp ...)
     ((describe)
      (match (generation-number %guix-home)
        (0
-        (error (G_ "no home environment generation, nothing to describe~%")))
+        (warning (G_ "no home environment generation, nothing to describe~%")))
        (generation
         (display-home-environment-generation generation))))
     ((list-generations)
diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm
index 65eb98e4b2..d77d3ea289 100644
--- a/guix/scripts/system.scm
+++ b/guix/scripts/system.scm
@@ -1307,7 +1307,7 @@  (define-syntax-rule (with-store* store exp ...)
     ((describe)
      (match (generation-number %system-profile)
        (0
-        (error (G_ "no system generation, nothing to describe~%")))
+        (warning (G_ "no system generation, nothing to describe~%")))
        (generation
         (display-system-generation generation))))
     ((search)