99 "github.com/github/gh-cli/api"
1010 "github.com/github/gh-cli/context"
1111 "github.com/github/gh-cli/git"
12+ "github.com/pkg/errors"
1213 "github.com/spf13/cobra"
1314)
1415
@@ -31,12 +32,12 @@ func prCreate(cmd *cobra.Command, _ []string) error {
3132
3233 head , err := ctx .Branch ()
3334 if err != nil {
34- return fmt . Errorf ( "could not determine current branch: %s" , err )
35+ return errors . Wrap ( err , "could not determine current branch" )
3536 }
3637
3738 remote , err := guessRemote (ctx )
3839 if err != nil {
39- return err
40+ return errors . Wrap ( err , "could not determine suitable remote" )
4041 }
4142
4243 if err = git .Push (remote , fmt .Sprintf ("HEAD:%s" , head )); err != nil {
@@ -45,11 +46,11 @@ func prCreate(cmd *cobra.Command, _ []string) error {
4546
4647 title , err := cmd .Flags ().GetString ("title" )
4748 if err != nil {
48- return err
49+ return errors . Wrap ( err , "could not parse title" )
4950 }
5051 body , err := cmd .Flags ().GetString ("body" )
5152 if err != nil {
52- return err
53+ return errors . Wrap ( err , "could not parse body" )
5354 }
5455
5556 interactive := title == "" || body == ""
@@ -92,7 +93,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
9293
9394 err := survey .Ask (qs , & inProgress )
9495 if err != nil {
95- return fmt . Errorf ( "could not prompt: %s" , err )
96+ return errors . Wrap ( err , "could not prompt" )
9697 }
9798 confirmAnswers := struct {
9899 Confirmation string
@@ -113,7 +114,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
113114
114115 err = survey .Ask (confirmQs , & confirmAnswers )
115116 if err != nil {
116- return fmt . Errorf ( "could not prompt: %s" , err )
117+ return errors . Wrap ( err , "could not prompt" )
117118 }
118119
119120 switch confirmAnswers .Confirmation {
@@ -136,7 +137,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
136137 }
137138 base , err := cmd .Flags ().GetString ("base" )
138139 if err != nil {
139- return err
140+ return errors . Wrap ( err , "could not parse base" )
140141 }
141142 if base == "" {
142143 // TODO: use default branch for the repo
@@ -145,17 +146,17 @@ func prCreate(cmd *cobra.Command, _ []string) error {
145146
146147 client , err := apiClientForContext (ctx )
147148 if err != nil {
148- return fmt . Errorf ( "could not initialize api client: %s" , err )
149+ return errors . Wrap ( err , "could not initialize api client" )
149150 }
150151
151152 repo , err := ctx .BaseRepo ()
152153 if err != nil {
153- return fmt . Errorf ( "could not determine GitHub repo: %s" , err )
154+ return errors . Wrap ( err , "could not determine GitHub repo" )
154155 }
155156
156157 isDraft , err := cmd .Flags ().GetBool ("draft" )
157158 if err != nil {
158- return err
159+ return errors . Wrap ( err , "could not parse draft" )
159160 }
160161
161162 params := map [string ]interface {}{
@@ -168,7 +169,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
168169
169170 pr , err := api .CreatePullRequest (client , repo , params )
170171 if err != nil {
171- return fmt . Errorf ( "failed to create PR: %s" , err )
172+ return errors . Wrap ( err , "failed to create PR" )
172173 }
173174
174175 fmt .Fprintln (cmd .OutOrStdout (), pr .URL )
@@ -178,14 +179,14 @@ func prCreate(cmd *cobra.Command, _ []string) error {
178179func guessRemote (ctx context.Context ) (string , error ) {
179180 remotes , err := ctx .Remotes ()
180181 if err != nil {
181- return "" , fmt . Errorf ( "could not determine suitable remote: %s" , err )
182+ return "" , errors . Wrap ( err , "could not determine suitable remote" )
182183 }
183184
184185 // TODO: consolidate logic with fsContext.BaseRepo
185186 // TODO: check if the GH repo that the remote points to is writeable
186187 remote , err := remotes .FindByName ("upstream" , "github" , "origin" , "*" )
187188 if err != nil {
188- return "" , fmt . Errorf ( "could not determine suitable remote: %s" , err )
189+ return "" , errors . Wrap ( err , "could not determine suitable remote" )
189190 }
190191
191192 return remote .Name , nil
0 commit comments