Skip to content

Commit

Permalink
Unify error messages
Browse files Browse the repository at this point in the history
Use "cannot" instead of "can't"
  • Loading branch information
jrauh01 committed Jan 20, 2025
1 parent f5e8867 commit 5c35ebc
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 27 deletions.
12 changes: 6 additions & 6 deletions cmd/icinga-kubernetes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func main() {
" a kubeconfig file with cluster access configured")
}

klog.Fatal(errors.Wrap(err, "can't configure Kubernetes client"))
klog.Fatal(errors.Wrap(err, "cannot configure Kubernetes client"))
}

clientset, err := kubernetes.NewForConfig(kconfig)
Expand All @@ -98,7 +98,7 @@ func main() {
var cfg daemon.Config
err = config.FromYAMLFile(configLocation, &cfg)
if err != nil {
klog.Fatal(errors.Wrap(err, "can't create configuration"))
klog.Fatal(errors.Wrap(err, "cannot create configuration"))
}

dbLog := log.WithName("database")
Expand Down Expand Up @@ -196,7 +196,7 @@ func main() {

logs, err := logging.NewLoggingFromConfig("Icinga Kubernetes", cfg.Logging)
if err != nil {
klog.Fatal(errors.Wrap(err, "can't configure logging"))
klog.Fatal(errors.Wrap(err, "cannot configure logging"))
}

db, err := database.NewDbFromConfig(&cfg.Database, logs.GetChildLogger("database"), database.RetryConnectorCallbacks{})
Expand All @@ -219,11 +219,11 @@ func main() {

stmt, _ := kdb.BuildUpsertStmt(clusterInstance)
if _, err := kdb.NamedExecContext(ctx, stmt, clusterInstance); err != nil {
klog.Error(errors.Wrap(err, "can't update cluster"))
klog.Error(errors.Wrap(err, "cannot update cluster"))
}

if _, err := kdb.ExecContext(ctx, "DELETE FROM kubernetes_instance WHERE cluster_uuid = ?", clusterInstance.Uuid); err != nil {
klog.Fatal(errors.Wrap(err, "can't delete instance"))
klog.Fatal(errors.Wrap(err, "cannot delete instance"))
}
// ,omitempty
var kubernetesVersion string
Expand Down Expand Up @@ -253,7 +253,7 @@ func main() {
stmt, _ := kdb.BuildUpsertStmt(instance)

if _, err := kdb.NamedExecContext(ctx, stmt, instance); err != nil {
klog.Error(errors.Wrap(err, "can't update instance"))
klog.Error(errors.Wrap(err, "cannot update instance"))
}
}, periodic.Immediate()).Stop()

Expand Down
2 changes: 1 addition & 1 deletion internal/channel_multiplexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ChannelMultiplexer[T any] interface {
AddOut(chan T)

// Run starts multiplexing of all input channels to all output channels.
// Once run is called, can't be modified and will panic.
// Once run is called, cannot be modified and will panic.
Run(context.Context) error
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/database/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (db *Database) CleanupOlderThan(
Timeout: retry.DefaultTimeout,
OnRetryableError: func(_ time.Duration, _ uint64, err, lastErr error) {
if lastErr == nil || err.Error() != lastErr.Error() {
db.log.Info("Can't execute query. Retrying", "error", err)
db.log.Info("Cannot execute query. Retrying", "error", err)
}
},
OnSuccess: func(elapsed time.Duration, attempt uint64, lastErr error) {
Expand Down
18 changes: 9 additions & 9 deletions pkg/database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewFromConfig(c *database.Config, log logr.Logger) (*Database, error) {
"connect_timeout": {"60"},
"binary_parameters": {"yes"},

// Host and port can alternatively be specified in the query string. lib/pq can't parse the connection URI
// Host and port can alternatively be specified in the query string. lib/pq cannot parse the connection URI
// if a Unix domain socket path is specified in the host part of the URI, therefore always use the query
// string. See also https://github.com/lib/pq/issues/796
"host": {c.Host},
Expand All @@ -103,7 +103,7 @@ func NewFromConfig(c *database.Config, log logr.Logger) (*Database, error) {

db, err := sqlx.Open("icinga-"+c.Type, dsn)
if err != nil {
return nil, errors.Wrap(err, "can't open database")
return nil, errors.Wrap(err, "cannot open database")
}

db.SetMaxIdleConns(c.Options.MaxConnections / 3)
Expand Down Expand Up @@ -236,7 +236,7 @@ func (db *Database) BulkExec(

for b := range bulk {
if err := sem.Acquire(ctx, n); err != nil {
return errors.Wrap(err, "can't acquire semaphore")
return errors.Wrap(err, "cannot acquire semaphore")
}

g.Go(func(b []interface{}) func() error {
Expand All @@ -248,7 +248,7 @@ func (db *Database) BulkExec(
func(context.Context) error {
stmt, args, err := sqlx.In(query, b)
if err != nil {
return errors.Wrapf(err, "can't build placeholders for %q", query)
return errors.Wrapf(err, "cannot build placeholders for %q", query)
}

stmt = db.Rebind(stmt)
Expand Down Expand Up @@ -284,7 +284,7 @@ func (db *Database) BulkExec(
func (db *Database) Connect() bool {
db.log.Info("Connecting to database")
if err := db.Ping(); err != nil {
db.log.Error(errors.WithStack(err), "Can't connect to database")
db.log.Error(errors.WithStack(err), "cannot connect to database")

return false
}
Expand Down Expand Up @@ -322,7 +322,7 @@ func (db *Database) NamedBulkExec(
}

if err := sem.Acquire(ctx, 1); err != nil {
return errors.Wrap(err, "can't acquire semaphore")
return errors.Wrap(err, "cannot acquire semaphore")
}

g.Go(func(b []interface{}) func() error {
Expand Down Expand Up @@ -498,7 +498,7 @@ func (db *Database) UpsertStreamed(
) error {
first, forward, err := com.CopyFirst(ctx, entities)
if first == nil {
return errors.Wrap(err, "can't copy first entity")
return errors.Wrap(err, "cannot copy first entity")
}

sem := db.GetSemaphoreForTable(TableName(first))
Expand Down Expand Up @@ -616,11 +616,11 @@ func (db *Database) YieldAll(ctx context.Context, factoryFunc func() (interface{
for rows.Next() {
e, err := factoryFunc()
if err != nil {
return errors.Wrap(err, "can't create entity")
return errors.Wrap(err, "cannot create entity")
}

if err = rows.StructScan(e); err != nil {
return errors.Wrapf(err, "can't store query result into a %T: %s", e, query)
return errors.Wrapf(err, "cannot store query result into a %T: %s", e, query)
}

select {
Expand Down
4 changes: 2 additions & 2 deletions pkg/database/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c RetryConnector) Connect(ctx context.Context) (driver.Conn, error) {
Timeout: timeout,
OnRetryableError: func(_ time.Duration, _ uint64, err, lastErr error) {
if lastErr == nil || err.Error() != lastErr.Error() {
c.driver.Logger.Info("Can't connect to database. Retrying", "error", err)
c.driver.Logger.Info("Cannot connect to database. Retrying", "error", err)
}
},
OnSuccess: func(elapsed time.Duration, attempt uint64, _ error) {
Expand All @@ -51,7 +51,7 @@ func (c RetryConnector) Connect(ctx context.Context) (driver.Conn, error) {
}
},
},
), "can't connect to database")
), "cannot connect to database")
return conn, err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/database/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

// CantPerformQuery wraps the given error with the specified query that cannot be executed.
func CantPerformQuery(err error, q string) error {
return errors.Wrapf(err, "can't perform %q", q)
return errors.Wrapf(err, "cannot perform %q", q)
}

func IsUnixAddr(host string) bool {
Expand Down
4 changes: 2 additions & 2 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ func (pms *PromMetricSync) run(
Timeout: retry.DefaultTimeout,
OnRetryableError: func(_ time.Duration, _ uint64, err, lastErr error) {
if lastErr == nil || err.Error() != lastErr.Error() {
pms.logger.Warnw("Can't execute prometheus query. Retrying", zap.Error(err))
pms.logger.Warnw("Cannot execute prometheus query. Retrying", zap.Error(err))
}
},
OnSuccess: func(elapsed time.Duration, attempt uint64, lastErr error) {
Expand Down Expand Up @@ -512,7 +512,7 @@ func (pms *PromMetricSync) Pods(ctx context.Context, informer kcache.SharedIndex
obj, exists, err := informer.GetStore().GetByKey(
kcache.NewObjectName(string(res.Metric["namespace"]), string(res.Metric["pod"])).String())
if err != nil {
//return errors.Wrap(err, "can't get pod from store")
//return errors.Wrap(err, "cannot get pod from store")
return nil
}
if !exists {
Expand Down
6 changes: 3 additions & 3 deletions pkg/schema/v1/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,20 +412,20 @@ func GetContainerState(container kcorev1.Container, status kcorev1.ContainerStat
if status.LastTerminationState.Terminated != nil &&
status.LastTerminationState.Terminated.Reason == ErrImagePullBackOff {
return Critical, fmt.Sprintf(
"Container %s can't start. %s.",
"Container %s cannot start. %s.",
container.Name,
ContainerStateReasonAndMassage{
status.LastTerminationState.Terminated.Reason,
removeTrailingWhitespaceAndFullStop(status.LastTerminationState.Terminated.Message),
})
}

return Warning, fmt.Sprintf("Container %s is waiting to start as its image can't be pulled: %s.",
return Warning, fmt.Sprintf("Container %s is waiting to start as its image cannot be pulled: %s.",
container.Name, status.State.Waiting.Message)
}

return Critical, fmt.Sprintf(
"Container %s can't start. %s.",
"Container %s cannot start. %s.",
container.Name,
ContainerStateReasonAndMassage{
status.State.Waiting.Reason,
Expand Down
2 changes: 1 addition & 1 deletion pkg/schema/v1/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func (p *Pod) getIcingaState(pod *kcorev1.Pod) (IcingaState, string) {

if podConditions[kcorev1.PodScheduled].Status == kcorev1.ConditionFalse {
return Critical, fmt.Sprintf(
"Pod %s/%s can't be scheduled: %s: %s.",
"Pod %s/%s cannot be scheduled: %s: %s.",
pod.Namespace,
pod.Name,
podConditions[kcorev1.PodScheduled].Reason,
Expand Down
2 changes: 1 addition & 1 deletion pkg/sync/v1/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (e *EventHandler) OnDelete(obj interface{}) {
func (e *EventHandler) enqueue(_type EventType, obj interface{}, keyFunc cache.KeyFunc) {
key, err := keyFunc(obj)
if err != nil {
e.log.Error(err, "Can't make key")
e.log.Error(err, "cannot make key")

return
}
Expand Down

0 comments on commit 5c35ebc

Please sign in to comment.