[Libguestfs] [PATCH] v2v: do not hide the error, rather report it

Pino Toscano ptoscano at redhat.com
Fri Aug 5 09:53:30 UTC 2016


On Friday, 5 August 2016 11:32:27 CEST Tomáš Golembiovský wrote:
> The Invalid_argument exception is there to catch unexpected situation
> when rpm returns no output. Such situation should be reported rather
> then hidden.
> 
> Signed-off-by: Tomáš Golembiovský <tgolembi at redhat.com>
> ---
>  v2v/linux.ml | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/v2v/linux.ml b/v2v/linux.ml
> index e57dad6..46cb3ba 100644
> --- a/v2v/linux.ml
> +++ b/v2v/linux.ml
> @@ -109,8 +109,8 @@ let rec file_owner (g : G.guestfs) inspect path =
>             raise Not_found
>           else
>             raise exn
> -       | Invalid_argument msg ->
> -         raise Not_found
> +       | Invalid_argument "index out of bounds" ->
> +         error (f_"internal error: file_owner: rpm command returned no output")

At this point, IMHO it would make more sense to split the different
operations in different try/with blocks, to distinguish better the
errors; something like:

  let pkgs =
    try
      pkgs = g#command_lines cmd
    with Guestfs.Error msg as exn ->
      if String.find msg "is not owned" >= 0 then
        raise Not_found
      else
        raise exn in
  if Array.length = 0 then
    error (f_"internal error: file_owner: rpm command returned no output");
  pkgs.(0)

-- 
Pino Toscano
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20160805/f6e50388/attachment.sig>


More information about the Libguestfs mailing list