Skip to content

Commit

Permalink
Don't print usage message for non-usage errors
Browse files Browse the repository at this point in the history
If an error occurs that was not related to usage of the
command, then the usage message should not be displayed
rather just the error that occured is shown.

However, if the problem was the usage of the command then
usage message should be printed.

Also, resolves the issue where an error message was being
sent to client twice during revocation.

https://jira.hyperledger.org/browse/FAB-2835
https://jira.hyperledger.org/browse/FAB-2839

Change-Id: I75696ce396eb4d7be09afcff631aa4195527936d
Signed-off-by: Saad Karim <[email protected]>
  • Loading branch information
Saad Karim committed Mar 29, 2017
1 parent e724a89 commit a64ea74
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 7 deletions.
3 changes: 3 additions & 0 deletions cmd/fabric-ca-client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ var rootCmd = &cobra.Command{
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
util.CmdRunBegin()

cmd.SilenceUsage = true
cmd.SilenceErrors = true

return nil
},
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/fabric-ca-client/revoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var revokeCmd = &cobra.Command{
return nil
}

err := runRevoke()
err := runRevoke(cmd)
if err != nil {
return err
}
Expand All @@ -70,7 +70,7 @@ func init() {
}

// The client revoke main logic
func runRevoke() error {
func runRevoke(cmd *cobra.Command) error {
log.Debug("Revoke Entered")

var err error
Expand All @@ -91,10 +91,12 @@ func runRevoke() error {

if enrollmentID == "" {
if serial == "" || aki == "" {
cmd.Usage()
return errInput
}
} else {
if serial != "" || aki != "" {
cmd.Usage()
return errInput
}
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/fabric-ca-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ var (
if err != nil {
return err
}
cmd.SilenceUsage = true
cmd.SilenceErrors = true
util.CmdRunBegin()
return nil
},
Expand Down
2 changes: 1 addition & 1 deletion lib/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ func (s *Server) getUserAffiliation(username string) (string, error) {
return "", err
}
aff := user.Affiliation
log.Debugf("getUserAttrValue user=%s, aff=%s, value=%s", username, aff)
log.Debugf("getUserAffiliation user=%s, aff=%s", username, aff)
return aff, nil
}

Expand Down
10 changes: 6 additions & 4 deletions lib/serverrevoke.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ func (h *revokeHandler) Handle(w http.ResponseWriter, r *http.Request) error {
if req.Serial != "" && req.AKI != "" {
certificate, err := certDBAccessor.GetCertificateWithID(req.Serial, req.AKI)
if err != nil {
log.Error(notFound(w, err))
return notFound(w, err)
msg := fmt.Sprintf("Failed to retrieve certificate for the provided serial number and AKI: %s", err)
log.Errorf(msg)
return notFound(w, errors.New(msg))
}

userInfo, err2 := registry.GetUserInfo(certificate.ID)
Expand All @@ -108,8 +109,9 @@ func (h *revokeHandler) Handle(w http.ResponseWriter, r *http.Request) error {

err = certDBAccessor.RevokeCertificate(req.Serial, req.AKI, req.Reason)
if err != nil {
log.Error(notFound(w, err))
return notFound(w, err)
msg := fmt.Sprintf("Failed to revoke certificate: %s", err)
log.Error(msg)
return notFound(w, errors.New(msg))
}
} else if req.Name != "" {

Expand Down

0 comments on commit a64ea74

Please sign in to comment.