@@ -312,7 +312,6 @@ func (dbclient *CouchDatabase) CreateDatabaseIfNotExist() error {
312
312
313
313
return err
314
314
}
315
-
316
315
defer closeResponseBody (resp )
317
316
318
317
logger .Infof ("Created state database %s" , dbclient .DBName )
@@ -343,7 +342,10 @@ func (dbclient *CouchDatabase) GetDatabaseInfo() (*DBInfo, *DBReturn, error) {
343
342
defer closeResponseBody (resp )
344
343
345
344
dbResponse := & DBInfo {}
346
- json .NewDecoder (resp .Body ).Decode (& dbResponse )
345
+ decodeErr := json .NewDecoder (resp .Body ).Decode (& dbResponse )
346
+ if decodeErr != nil {
347
+ return nil , nil , decodeErr
348
+ }
347
349
348
350
// trace the database info response
349
351
if logger .IsEnabledFor (logging .DEBUG ) {
@@ -382,9 +384,9 @@ func (couchInstance *CouchInstance) VerifyCouchConfig() (*ConnectionInfo, *DBRet
382
384
defer closeResponseBody (resp )
383
385
384
386
dbResponse := & ConnectionInfo {}
385
- errJSON := json .NewDecoder (resp .Body ).Decode (& dbResponse )
386
- if errJSON != nil {
387
- return nil , nil , fmt . Errorf ( "Unable to connect to CouchDB, check the hostname and port: %s" , errJSON . Error ())
387
+ decodeErr := json .NewDecoder (resp .Body ).Decode (& dbResponse )
388
+ if decodeErr != nil {
389
+ return nil , nil , decodeErr
388
390
}
389
391
390
392
// trace the database info response
@@ -429,7 +431,10 @@ func (dbclient *CouchDatabase) DropDatabase() (*DBOperationResponse, error) {
429
431
defer closeResponseBody (resp )
430
432
431
433
dbResponse := & DBOperationResponse {}
432
- json .NewDecoder (resp .Body ).Decode (& dbResponse )
434
+ decodeErr := json .NewDecoder (resp .Body ).Decode (& dbResponse )
435
+ if decodeErr != nil {
436
+ return nil , decodeErr
437
+ }
433
438
434
439
if dbResponse .Ok == true {
435
440
logger .Debugf ("Dropped database %s " , dbclient .DBName )
@@ -470,7 +475,10 @@ func (dbclient *CouchDatabase) EnsureFullCommit() (*DBOperationResponse, error)
470
475
defer closeResponseBody (resp )
471
476
472
477
dbResponse := & DBOperationResponse {}
473
- json .NewDecoder (resp .Body ).Decode (& dbResponse )
478
+ decodeErr := json .NewDecoder (resp .Body ).Decode (& dbResponse )
479
+ if decodeErr != nil {
480
+ return nil , decodeErr
481
+ }
474
482
475
483
if dbResponse .Ok == true {
476
484
logger .Debugf ("_ensure_full_commit database %s " , dbclient .DBName )
@@ -626,7 +634,10 @@ func createAttachmentPart(couchDoc *CouchDoc, defaultBoundary string) (bytes.Buf
626
634
//unmarshal the data into the generic map
627
635
decoder := json .NewDecoder (bytes .NewBuffer (couchDoc .JSONValue ))
628
636
decoder .UseNumber ()
629
- decoder .Decode (& genericMap )
637
+ decodeErr := decoder .Decode (& genericMap )
638
+ if decodeErr != nil {
639
+ return * writeBuffer , "" , decodeErr
640
+ }
630
641
631
642
//add all key/values to the attachmentJSONMap
632
643
for jsonKey , jsonValue := range genericMap {
@@ -635,7 +646,11 @@ func createAttachmentPart(couchDoc *CouchDoc, defaultBoundary string) (bytes.Buf
635
646
636
647
}
637
648
638
- filesForUpload , _ := json .Marshal (attachmentJSONMap )
649
+ filesForUpload , err := json .Marshal (attachmentJSONMap )
650
+ if err != nil {
651
+ return * writeBuffer , "" , err
652
+ }
653
+
639
654
logger .Debugf (string (filesForUpload ))
640
655
641
656
//create the header for the JSON
@@ -1336,7 +1351,10 @@ func (dbclient *CouchDatabase) BatchUpdateDocuments(documents []*CouchDoc) ([]*B
1336
1351
var document = make (map [string ]interface {})
1337
1352
1338
1353
//unmarshal the JSON component of the CouchDoc into the document
1339
- json .Unmarshal (jsonDocument .JSONValue , & document )
1354
+ err = json .Unmarshal (jsonDocument .JSONValue , & document )
1355
+ if err != nil {
1356
+ return nil , err
1357
+ }
1340
1358
1341
1359
//iterate through any attachments
1342
1360
if len (jsonDocument .Attachments ) > 0 {
@@ -1365,7 +1383,6 @@ func (dbclient *CouchDatabase) BatchUpdateDocuments(documents []*CouchDoc) ([]*B
1365
1383
documentMap ["docs" ] = jsonDocumentMap
1366
1384
1367
1385
bulkDocsJSON , err := json .Marshal (documentMap )
1368
-
1369
1386
if err != nil {
1370
1387
return nil , err
1371
1388
}
@@ -1557,7 +1574,10 @@ func (couchInstance *CouchInstance) handleRequest(method, connectURL string, dat
1557
1574
errorBytes := []byte (jsonError )
1558
1575
1559
1576
//Unmarshal the response
1560
- json .Unmarshal (errorBytes , & couchDBReturn )
1577
+ err = json .Unmarshal (errorBytes , & couchDBReturn )
1578
+ if err != nil {
1579
+ return nil , nil , err
1580
+ }
1561
1581
1562
1582
//Log the 500 error with the retry count and continue
1563
1583
logger .Warningf ("Retrying couchdb request in %s. Attempt:%v Couch DB Error:%s, Status Code:%v Reason:%v" ,
@@ -1604,7 +1624,10 @@ func (couchInstance *CouchInstance) handleRequest(method, connectURL string, dat
1604
1624
errorBytes := []byte (jsonError )
1605
1625
1606
1626
//marshal the response
1607
- json .Unmarshal (errorBytes , & couchDBReturn )
1627
+ err = json .Unmarshal (errorBytes , & couchDBReturn )
1628
+ if err != nil {
1629
+ return nil , nil , err
1630
+ }
1608
1631
1609
1632
logger .Debugf ("Couch DB Error:%s, Status Code:%v, Reason:%s" ,
1610
1633
couchDBReturn .Error , resp .StatusCode , couchDBReturn .Reason )
0 commit comments