Skip to content

Commit 1591be2

Browse files
committed
fix #232: use %w to wrap error
1 parent a8accd0 commit 1591be2

File tree

4 files changed

+41
-35
lines changed

4 files changed

+41
-35
lines changed

CHANGELOG.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
# Change Log
22

3+
## v2.7.1
4+
5+
- `[FIX]` [#232](https://github.com/huandu/facebook/issues/232) Fix incorrect error wrapping. Thanks, [@AnatolyRugalev](https://github.com/AnatolyRugalev).
6+
37
## v2.7.0
48

5-
- `[NEW]` [#211](https://github.com/huandu/facebook/pull/211) Make session on app configurable. Thank [Spazzy757](https://github.com/Spazzy757) for your PR.
9+
- `[NEW]` [#211](https://github.com/huandu/facebook/pull/211) Make session on app configurable. Thank [@Spazzy757](https://github.com/Spazzy757) for your PR.
610

711
## v2.6.0
812

app.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,21 @@ func (app *App) ParseSignedRequest(signedRequest string) (res Result, err error)
6767
sig, e1 := base64.RawURLEncoding.DecodeString(strs[0])
6868

6969
if e1 != nil {
70-
err = fmt.Errorf("facebook: fail to decode signed request sig with error %v", e1)
70+
err = fmt.Errorf("facebook: fail to decode signed request sig with error %w", e1)
7171
return
7272
}
7373

7474
payload, e2 := base64.RawURLEncoding.DecodeString(strs[1])
7575

7676
if e2 != nil {
77-
err = fmt.Errorf("facebook: fail to decode signed request payload with error is %v", e2)
77+
err = fmt.Errorf("facebook: fail to decode signed request payload with error is %w", e2)
7878
return
7979
}
8080

8181
err = json.Unmarshal(payload, &res)
8282

8383
if err != nil {
84-
err = fmt.Errorf("facebook: signed request payload is not a valid json string with error %v", err)
84+
err = fmt.Errorf("facebook: signed request payload is not a valid json string with error %w", err)
8585
return
8686
}
8787

@@ -142,7 +142,7 @@ func (app *App) ParseCodeInfo(code, machineID string) (token string, expires int
142142
})
143143

144144
if err != nil {
145-
err = fmt.Errorf("facebook: fail to parse facebook response with error %v", err)
145+
err = fmt.Errorf("facebook: fail to parse facebook response with error %w", err)
146146
return
147147
}
148148

@@ -190,7 +190,7 @@ func (app *App) ExchangeToken(accessToken string) (token string, expires int, er
190190
})
191191

192192
if err != nil {
193-
err = fmt.Errorf("fail to parse facebook response with error %v", err)
193+
err = fmt.Errorf("fail to parse facebook response with error %w", err)
194194
return
195195
}
196196

@@ -230,7 +230,7 @@ func (app *App) GetCode(accessToken string) (code string, err error) {
230230
})
231231

232232
if err != nil {
233-
err = fmt.Errorf("facebook: fail to get code from facebook with error %v", err)
233+
err = fmt.Errorf("facebook: fail to get code from facebook with error %w", err)
234234
return
235235
}
236236

result.go

+26-24
Original file line numberDiff line numberDiff line change
@@ -328,19 +328,19 @@ func getValueField(value reflect.Value, fields []string) reflect.Value {
328328
//
329329
// Examples:
330330
//
331-
// type Foo struct {
332-
// // "id" must exist in response. note the leading comma.
333-
// Id string `facebook:",required"`
331+
// type Foo struct {
332+
// // "id" must exist in response. note the leading comma.
333+
// Id string `facebook:",required"`
334334
//
335-
// // use "name" as field name in response.
336-
// TheName string `facebook:"name"`
335+
// // use "name" as field name in response.
336+
// TheName string `facebook:"name"`
337337
//
338-
// // the "json" key also works as expected.
339-
// Key string `json:"my_key"`
338+
// // the "json" key also works as expected.
339+
// Key string `json:"my_key"`
340340
//
341-
// // if both "facebook" and "json" key are set, the "facebook" key is used.
342-
// Value string `facebook:"value" json:"shadowed"`
343-
// }
341+
// // if both "facebook" and "json" key are set, the "facebook" key is used.
342+
// Value string `facebook:"value" json:"shadowed"`
343+
// }
344344
//
345345
// To change default behavior, set a struct tag `facebook:",required"` to fields
346346
// should not be missing.
@@ -388,12 +388,13 @@ func (res Result) DecodeField(field string, v interface{}) error {
388388
// Err returns an error if Result is a Graph API error.
389389
//
390390
// The returned error can be converted to Error by type assertion.
391-
// err := res.Err()
392-
// if err != nil {
393-
// if e, ok := err.(*Error); ok {
394-
// // read more details in e.Message, e.Code and e.Type
395-
// }
396-
// }
391+
//
392+
// err := res.Err()
393+
// if err != nil {
394+
// if e, ok := err.(*Error); ok {
395+
// // read more details in e.Message, e.Code and e.Type
396+
// }
397+
// }
397398
//
398399
// For more information about Graph API Errors, see
399400
// https://developers.facebook.com/docs/reference/api/errors/
@@ -420,13 +421,14 @@ func (res Result) Err() error {
420421
//
421422
// Facebook uses following JSON structure to response paging information.
422423
// If "data" doesn't present in Result, Paging will return error.
423-
// {
424-
// "data": [...],
425-
// "paging": {
426-
// "previous": "https://graph.facebook.com/...",
427-
// "next": "https://graph.facebook.com/..."
428-
// }
429-
// }
424+
//
425+
// {
426+
// "data": [...],
427+
// "paging": {
428+
// "previous": "https://graph.facebook.com/...",
429+
// "next": "https://graph.facebook.com/..."
430+
// }
431+
// }
430432
func (res Result) Paging(session *Session) (*PagingResult, error) {
431433
return newPagingResult(session, res)
432434
}
@@ -614,7 +616,7 @@ func decodeField(val reflect.Value, field reflect.Value, fullName string) error
614616
data, err := json.Marshal(val.Interface())
615617

616618
if err != nil {
617-
return fmt.Errorf("facebook: fail to marshal value for field '%v' with error %v", fullName, err)
619+
return fmt.Errorf("facebook: fail to marshal value for field '%v' with error %w", fullName, err)
618620
}
619621

620622
return unmarshaler.UnmarshalJSON(data)

session.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ func (session *Session) sendPostRequest(uri string, params Params, res interface
476476
mime, err := params.Encode(buf)
477477

478478
if err != nil {
479-
return nil, fmt.Errorf("facebook: cannot encode POST params; %v", err)
479+
return nil, fmt.Errorf("facebook: cannot encode POST params; %w", err)
480480
}
481481

482482
request, err := http.NewRequest("POST", uri, buf)
@@ -502,7 +502,7 @@ func (session *Session) sendOauthRequest(uri string, params Params) (Result, err
502502
mime, err := params.Encode(buf)
503503

504504
if err != nil {
505-
return nil, fmt.Errorf("facebook: cannot encode POST params; %v", err)
505+
return nil, fmt.Errorf("facebook: cannot encode POST params; %w", err)
506506
}
507507

508508
request, err := http.NewRequest("POST", urlStr, buf)
@@ -562,7 +562,7 @@ func (session *Session) sendRequest(request *http.Request) (response *http.Respo
562562
}
563563

564564
if err != nil {
565-
err = fmt.Errorf("facebook: cannot reach facebook server; %v", err)
565+
err = fmt.Errorf("facebook: cannot reach facebook server; %w", err)
566566
return
567567
}
568568

@@ -571,7 +571,7 @@ func (session *Session) sendRequest(request *http.Request) (response *http.Respo
571571
response.Body.Close()
572572

573573
if err != nil {
574-
err = fmt.Errorf("facebook: cannot read facebook response; %v", err)
574+
err = fmt.Errorf("facebook: cannot read facebook response; %w", err)
575575
}
576576

577577
data = buf.Bytes()

0 commit comments

Comments
 (0)