Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: suggest using errors.New instead of fmt.Errorf with no parameters #5557

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions exp/services/market-tracker/price.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
Expand Down Expand Up @@ -117,7 +118,7 @@ func parseStellarExpertPriceHistory(body string) ([]xlmPrice, error) {
// with the most recent timestamp and price first. We split that array to get strings of only "timestamp,price".
// We then split each of those strings and define a struct containing the timestamp and price.
if len(body) < 5 {
return []xlmPrice{}, fmt.Errorf("got ill-formed response body from stellar expert")
return []xlmPrice{}, errors.New("got ill-formed response body from stellar expert")
}

body = body[2 : len(body)-2]
Expand All @@ -127,7 +128,7 @@ func parseStellarExpertPriceHistory(body string) ([]xlmPrice, error) {
for _, timePriceStr := range timePriceStrs {
timePrice := strings.Split(timePriceStr, ",")
if len(timePrice) != 2 {
return []xlmPrice{}, fmt.Errorf("got ill-formed time/price from stellar expert")
return []xlmPrice{}, errors.New("got ill-formed time/price from stellar expert")
}

ts, err := strconv.ParseInt(timePrice[0], 10, 64)
Expand Down Expand Up @@ -157,12 +158,12 @@ func parseStellarExpertLatestPrice(body string) (float64, error) {
// We format and return the most recent price.
lists := strings.Split(body, ",")
if len(lists) < 2 {
return 0.0, fmt.Errorf("mis-formed response from stellar expert")
return 0.0, errors.New("mis-formed response from stellar expert")
}

rawPriceStr := lists[1]
if len(rawPriceStr) < 2 {
return 0.0, fmt.Errorf("mis-formed price from stellar expert")
return 0.0, errors.New("mis-formed price from stellar expert")
}

priceStr := rawPriceStr[:len(rawPriceStr)-1]
Expand Down Expand Up @@ -227,7 +228,7 @@ func getAssetUSDPrice(body, currency string) (float64, error) {
rates := make(map[string]interface{})
var ok bool
if rates, ok = m["rates"].(map[string]interface{}); !ok {
return 0.0, fmt.Errorf("could not get rates from api response")
return 0.0, errors.New("could not get rates from api response")
}

var rate float64
Expand Down
9 changes: 5 additions & 4 deletions exp/services/market-tracker/volume.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"fmt"
"sort"
"strconv"
Expand Down Expand Up @@ -205,7 +206,7 @@ func getAggRecords(taps []hProtocol.TradeAggregationsPage) (records []hProtocol.

func constructVolumeHistory(tas []hProtocol.TradeAggregation, xlmPrices []xlmPrice, assetPrice float64, start, end time.Time, res int) ([]volumeHist, error) {
if len(xlmPrices) < 2 {
return []volumeHist{}, fmt.Errorf("mis-formed xlm price history from stellar expert")
return []volumeHist{}, errors.New("mis-formed xlm price history from stellar expert")
}

volumeHistory := []volumeHist{}
Expand Down Expand Up @@ -414,18 +415,18 @@ func calcWeightedPrice(timestamp int64, startIndex int, prices []xlmPrice) (floa
// TODO: Use resolution to weight prices.
if startIndex < 0 {
if timestamp < prices[0].timestamp {
return 0.0, fmt.Errorf("update price index before calculating price")
return 0.0, errors.New("update price index before calculating price")
}
return prices[0].price, nil
} else if startIndex >= len(prices)-1 {
if timestamp > prices[len(prices)-1].timestamp {
return 0.0, fmt.Errorf("update price index before calculating price")
return 0.0, errors.New("update price index before calculating price")
}
return prices[len(prices)-1].price, nil
}

if timestamp > prices[startIndex].timestamp || timestamp < prices[startIndex+1].timestamp {
return 0.0, fmt.Errorf("update price index before calculating price")
return 0.0, errors.New("update price index before calculating price")
}

avgPrice := (prices[startIndex].price + prices[startIndex+1].price) / 2
Expand Down
4 changes: 2 additions & 2 deletions utils/apiclient/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ func (c *APIClient) CallAPI(reqParams RequestParams) (interface{}, error) {
}

if reqParams.Endpoint == "" {
return nil, fmt.Errorf("Please set endpoint to query")
return nil, errors.New("Please set endpoint to query")
}

url := c.GetURL(reqParams.Endpoint, reqParams.QueryParams)
reqBody, err := CreateRequestBody(reqParams.RequestType, url)
if err != nil {
return nil, fmt.Errorf("http request creation failed")
return nil, errors.New("http request creation failed")
}

SetAuthHeaders(reqBody, c.AuthType, c.AuthHeaders)
Expand Down