{"action":"closed","issue":{"url":"https://api.github.com/repos/square/go-jose/issues/50","labels_url":"https://api.github.com/repos/square/go-jose/issues/50/labels{/name}","comments_url":"https://api.github.com/repos/square/go-jose/issues/50/comments","events_url":"https://api.github.com/repos/square/go-jose/issues/50/events","html_url":"https://github.com/square/go-jose/issues/50","id":109718303,"number":50,"title":"Nitpick: Make errors explicit about which fields are missing","user":{"login":"lestrrat","id":49281,"avatar_url":"https://avatars.githubusercontent.com/u/49281?v=3","gravatar_id":"","url":"https://api.github.com/users/lestrrat","html_url":"https://github.com/lestrrat","followers_url":"https://api.github.com/users/lestrrat/followers","following_url":"https://api.github.com/users/lestrrat/following{/other_user}","gists_url":"https://api.github.com/users/lestrrat/gists{/gist_id}","starred_url":"https://api.github.com/users/lestrrat/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lestrrat/subscriptions","organizations_url":"https://api.github.com/users/lestrrat/orgs","repos_url":"https://api.github.com/users/lestrrat/repos","events_url":"https://api.github.com/users/lestrrat/events{/privacy}","received_events_url":"https://api.github.com/users/lestrrat/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/square/go-jose/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-10-05T01:42:04Z","updated_at":"2015-10-15T21:22:03Z","closed_at":"2015-10-15T21:22:03Z","body":"While investigating a malformed jwks file, I found it necessary to know which field go-jose thought was missing from the JSON file. This is not such a important thing except for a specific instance like mine, so I thought I'd just file this run by this change as an issue first instead of PR.\r\n\r\n```\r\ndiff --git a/jwk.go b/jwk.go\r\nindex 8512be3..73b99b3 100644\r\n--- a/jwk.go\r\n+++ b/jwk.go\r\n@@ -187,9 +187,28 @@ func fromEcPublicKey(pub *ecdsa.PublicKey) (*rawJsonWebKey, error) {\r\n        return key, nil\r\n }\r\n \r\n+var (\r\n+       errInvalidRSAPrivateKeyMissingN = fmt.Errorf(\"square/go-jose: invalid RSA private key, missing values (%s)\", \"N\")\r\n+       errInvalidRSAPrivateKeyMissingE = fmt.Errorf(\"square/go-jose: invalid RSA private key, missing values (%s)\", \"E\")\r\n+       errInvalidRSAPrivateKeyMissingD = fmt.Errorf(\"square/go-jose: invalid RSA private key, missing values (%s)\", \"D\")\r\n+       errInvalidRSAPrivateKeyMissingP = fmt.Errorf(\"square/go-jose: invalid RSA private key, missing values (%s)\", \"P\")\r\n+       errInvalidRSAPrivateKeyMissingQ = fmt.Errorf(\"square/go-jose: invalid RSA private key, missing values (%s)\", \"Q\")\r\n+)\r\n+\r\n func (key rawJsonWebKey) rsaPrivateKey() (*rsa.PrivateKey, error) {\r\n-       if key.N == nil || key.E == nil || key.D == nil || key.P == nil || key.Q == nil {\r\n-               return nil, fmt.Errorf(\"square/go-jose: invalid RSA private key, missing values\")\r\n+       // lestrrat: these assersions are unpacked so that error messages are\r\n+       // reported better\r\n+       switch {\r\n+       case key.N == nil:\r\n+               return nil, errInvalidRSAPrivateKeyMissingN\r\n+       case key.E == nil:\r\n+               return nil, errInvalidRSAPrivateKeyMissingE\r\n+       case key.D == nil:\r\n+               return nil, errInvalidRSAPrivateKeyMissingD\r\n...skipping...\r\n \r\n+var (\r\n+       errInvalidRSAPrivateKeyMissingN = fmt.Errorf(\"square/go-jose: invalid RSA private key, missing values (%s)\", \"N\")\r\n+       errInvalidRSAPrivateKeyMissingE = fmt.Errorf(\"square/go-jose: invalid RSA private key, missing values (%s)\", \"E\")\r\n+       errInvalidRSAPrivateKeyMissingD = fmt.Errorf(\"square/go-jose: invalid RSA private key, missing values (%s)\", \"D\")\r\n+       errInvalidRSAPrivateKeyMissingP = fmt.Errorf(\"square/go-jose: invalid RSA private key, missing values (%s)\", \"P\")\r\n+       errInvalidRSAPrivateKeyMissingQ = fmt.Errorf(\"square/go-jose: invalid RSA private key, missing values (%s)\", \"Q\")\r\n+)\r\n+\r\n func (key rawJsonWebKey) rsaPrivateKey() (*rsa.PrivateKey, error) {\r\n-       if key.N == nil || key.E == nil || key.D == nil || key.P == nil || key.Q == nil {\r\n-               return nil, fmt.Errorf(\"square/go-jose: invalid RSA private key, missing values\")\r\n+       // lestrrat: these assersions are unpacked so that error messages are\r\n+       // reported better\r\n+       switch {\r\n+       case key.N == nil:\r\n+               return nil, errInvalidRSAPrivateKeyMissingN\r\n+       case key.E == nil:\r\n+               return nil, errInvalidRSAPrivateKeyMissingE\r\n+       case key.D == nil:\r\n+               return nil, errInvalidRSAPrivateKeyMissingD\r\n+       case key.P == nil:\r\n+               return nil, errInvalidRSAPrivateKeyMissingP\r\n+       case key.Q == nil:\r\n+               return nil, errInvalidRSAPrivateKeyMissingQ\r\n        }\r\n \r\n        rv := &rsa.PrivateKey{\r\n```"}}