list: gracefully fail in case of invalid registry (#158)

If the given domain is not a valid registry and try to get the
repository list, it fails in unmarshalling and show the JSON syntax
error.

This will catch the error and show a better error message.

Fixes: #157
This commit is contained in:
Mansour Rahimi 2018-10-29 16:27:22 +01:00 committed by Jess Frazelle
parent 23cd8e4025
commit d6e3a0aa00

View file

@ -2,6 +2,7 @@ package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"os"
@ -36,6 +37,9 @@ func (cmd *listCommand) Run(ctx context.Context, args []string) error {
// Get the repositories via catalog.
repos, err := r.Catalog("")
if err != nil {
if _, ok := err.(*json.SyntaxError); ok {
return fmt.Errorf("Domain %s is not a valid registry", r.Domain)
}
return err
}
sort.Strings(repos)