@@ -10,7 +10,6 @@ import (
1010 "strings"
1111
1212 "github.com/pelletier/go-toml/v2"
13- "github.com/pkg/errors"
1413)
1514
1615// ConfigPath is the default path to the configuration file
@@ -154,7 +153,7 @@ func (conf *Config) LoadConfig(configFile string) error {
154153
155154 if conf .ClientSendInterval < 1 || conf .AggrInterval < 1 || conf .AggrPerSecond < 1 ||
156155 conf .MetricsPerSecond < 1 || conf .ConnectTimeout < 1 {
157- return errors . New ("ClientSendInterval, AggrInterval, AggrPerSecond, ClientSendInterval, " +
156+ return fmt . Errorf ("ClientSendInterval, AggrInterval, AggrPerSecond, ClientSendInterval, " +
158157 "MetricsPerSecond, ConnectTimeout must be greater than 0" )
159158 }
160159
@@ -182,17 +181,17 @@ func (conf *Config) prepareEnvironment() error {
182181 // Create directory with default permissions first
183182 err = os .MkdirAll (conf .MetricDir , os .ModePerm )
184183 if err != nil {
185- return errors . Wrap ( err , "Failed to create MetricDir: " + conf .MetricDir )
184+ return fmt . Errorf ( "failed to create MetricDir %s: %w" , conf .MetricDir , err )
186185 }
187186 // Then explicitly set the desired permissions to avoid issues with umask
188187 err = os .Chmod (conf .MetricDir , 0777 | os .ModeSticky )
189188 if err != nil {
190- return errors . Wrap ( err , "Failed to chmod MetricDir after creation: " + conf .MetricDir )
189+ return fmt . Errorf ( "failed to chmod MetricDir after creation %s: %w" , conf .MetricDir , err )
191190 }
192191 } else {
193192 err = os .Chmod (conf .MetricDir , 0777 | os .ModeSticky )
194193 if err != nil {
195- return errors . Wrap ( err , "Failed to chmod MetricDir: " + conf .MetricDir )
194+ return fmt . Errorf ( "failed to chmod MetricDir %s: %w" , conf .MetricDir , err )
196195 }
197196 }
198197
@@ -204,21 +203,21 @@ func (conf *Config) prepareEnvironment() error {
204203 if conf .UseACL {
205204 err := setACL (conf .MetricDir )
206205 if err != nil {
207- return errors . Wrap ( err , "Can not set ACLs for dir " + conf .MetricDir )
206+ return fmt . Errorf ( "can not set ACLs for dir %s: %w" , conf .MetricDir , err )
208207 }
209208 }
210209
211210 if _ , err := os .Stat (filepath .Dir (conf .Log )); conf .Log != "-" || os .IsNotExist (err ) {
212211 if err = os .MkdirAll (filepath .Dir (conf .Log ), os .ModePerm ); err != nil {
213- return errors . Wrap ( err , "Can not create logfile's dir " + filepath .Dir (conf .Log ))
212+ return fmt . Errorf ( "can not create logfile's dir %s: %w" , filepath .Dir (conf .Log ), err )
214213 }
215214 }
216215
217216 // Check if servers in CarbonAddrs are resolvable
218217 for _ , carbonAddr := range conf .CarbonAddrs {
219218 _ , err := net .ResolveTCPAddr ("tcp" , carbonAddr )
220219 if err != nil {
221- return errors . New ( "Could not resolve an address from CarbonAddrs: " + err . Error () )
220+ return fmt . Errorf ( "could not resolve an address from CarbonAddrs: %w" , err )
222221 }
223222 }
224223
@@ -239,7 +238,7 @@ func (conf *Config) GenerateLocalConfig() (*LocalConfig, error) {
239238
240239 err := conf .prepareEnvironment ()
241240 if err != nil {
242- return nil , errors . Wrap ( err , "Can not prepare environment" )
241+ return nil , fmt . Errorf ( "can not prepare environment: %w" , err )
243242 }
244243
245244 /*
@@ -265,7 +264,7 @@ func (conf *Config) GenerateLocalConfig() (*LocalConfig, error) {
265264 } else {
266265 f , err = os .OpenFile (conf .Log , os .O_RDWR | os .O_CREATE | os .O_APPEND , 0660 )
267266 if err != nil {
268- log .Println ("Can not open file" , conf .Log , err . Error () )
267+ log .Println ("Can not open file" , conf .Log , err )
269268 os .Exit (1 )
270269 }
271270 }
@@ -275,9 +274,9 @@ func (conf *Config) GenerateLocalConfig() (*LocalConfig, error) {
275274 if hostname == "" {
276275 hostname , err = os .Hostname ()
277276 if err != nil {
278- return nil , errors . New ( "Can not resolve the hostname: " + err . Error () )
277+ return nil , fmt . Errorf ( "can not resolve the hostname: %w" , err )
279278 }
280- hostname = strings .Replace (hostname , "." , "_" , - 1 )
279+ hostname = strings .ReplaceAll (hostname , "." , "_" )
281280 }
282281
283282 // There are 4 metrics per backend in client and 3 in server stats
0 commit comments