From 69f7c1c1375d7f76279445a74167043f42e77f41 Mon Sep 17 00:00:00 2001 From: Matt Toohey Date: Mon, 15 Apr 2024 09:09:09 +1000 Subject: [PATCH] chore: clean up string interpolation --- backend/controller/dal/dal.go | 42 +++++++++++------------ backend/controller/dal/notify.go | 6 ++-- backend/controller/sql/migrate.go | 6 ++-- backend/protos/xyz/block/ftl/v1/mixins.go | 2 +- backend/runner/runner.go | 28 +++++++-------- cmd/ftl/cmd_schema_generate.go | 2 +- cmd/ftl/cmd_schema_get.go | 2 +- common/plugin/serve.go | 2 +- common/plugin/spawn.go | 6 ++-- go-runtime/compile/parser.go | 2 +- internal/observability/client.go | 6 ++-- internal/rpc/context.go | 6 ++-- 12 files changed, 55 insertions(+), 55 deletions(-) diff --git a/backend/controller/dal/dal.go b/backend/controller/dal/dal.go index f97f455aaa..7d611de642 100644 --- a/backend/controller/dal/dal.go +++ b/backend/controller/dal/dal.go @@ -231,7 +231,7 @@ func WithReservation(ctx context.Context, reservation Reservation, fn func() err func New(ctx context.Context, pool *pgxpool.Pool) (*DAL, error) { conn, err := pool.Acquire(ctx) if err != nil { - return nil, fmt.Errorf("%s: %w", "failed to acquire PG PubSub connection", err) + return nil, fmt.Errorf("failed to acquire PG PubSub connection: %w", err) } dal := &DAL{ db: sql.NewDB(pool), @@ -269,23 +269,23 @@ func (d *DAL) GetStatus( ) (Status, error) { controllers, err := d.GetControllers(ctx, allControllers) if err != nil { - return Status{}, fmt.Errorf("%s: %w", "could not get control planes", translatePGError(err)) + return Status{}, fmt.Errorf("could not get control planes: %w", translatePGError(err)) } runners, err := d.db.GetActiveRunners(ctx, allRunners) if err != nil { - return Status{}, fmt.Errorf("%s: %w", "could not get active runners", translatePGError(err)) + return Status{}, fmt.Errorf("could not get active runners: %w", translatePGError(err)) } deployments, err := d.db.GetActiveDeployments(ctx) if err != nil { - return Status{}, fmt.Errorf("%s: %w", "could not get active deployments", translatePGError(err)) + return Status{}, fmt.Errorf("could not get active deployments: %w", translatePGError(err)) } ingressRoutes, err := d.db.GetAllIngressRoutes(ctx, allIngressRoutes) if err != nil { - return Status{}, fmt.Errorf("%s: %w", "could not get ingress routes", translatePGError(err)) + return Status{}, fmt.Errorf("could not get ingress routes: %w", translatePGError(err)) } routes, err := d.db.GetRoutingTable(ctx, nil) if err != nil { - return Status{}, fmt.Errorf("%s: %w", "could not get routing table", translatePGError(err)) + return Status{}, fmt.Errorf("could not get routing table: %w", translatePGError(err)) } statusDeployments, err := slices.MapErr(deployments, func(in sql.GetActiveDeploymentsRow) (Deployment, error) { labels := model.Labels{} @@ -417,7 +417,7 @@ func (d *DAL) CreateDeployment(ctx context.Context, language string, moduleSchem // Start the transaction tx, err := d.db.Begin(ctx) if err != nil { - return model.DeploymentKey{}, fmt.Errorf("%s: %w", "could not start transaction", err) + return model.DeploymentKey{}, fmt.Errorf("could not start transaction: %w", err) } defer tx.CommitOrRollback(ctx, &err) @@ -436,13 +436,13 @@ func (d *DAL) CreateDeployment(ctx context.Context, language string, moduleSchem schemaBytes, err := proto.Marshal(moduleSchema.ToProto()) if err != nil { - return model.DeploymentKey{}, fmt.Errorf("%s: %w", "failed to marshal schema", err) + return model.DeploymentKey{}, fmt.Errorf("failed to marshal schema: %w", err) } // TODO(aat): "schema" containing language? _, err = tx.UpsertModule(ctx, language, moduleSchema.Name) if err != nil { - return model.DeploymentKey{}, fmt.Errorf("%s: %w", "failed to upsert module", translatePGError(err)) + return model.DeploymentKey{}, fmt.Errorf("failed to upsert module: %w", translatePGError(err)) } deploymentKey := model.NewDeploymentKey(moduleSchema.Name) @@ -450,13 +450,13 @@ func (d *DAL) CreateDeployment(ctx context.Context, language string, moduleSchem // Create the deployment err = tx.CreateDeployment(ctx, moduleSchema.Name, schemaBytes, deploymentKey) if err != nil { - return model.DeploymentKey{}, fmt.Errorf("%s: %w", "failed to create deployment", translatePGError(err)) + return model.DeploymentKey{}, fmt.Errorf("failed to create deployment: %w", translatePGError(err)) } uploadedDigests := slices.Map(artefacts, func(in DeploymentArtefact) []byte { return in.Digest[:] }) artefactDigests, err := tx.GetArtefactDigests(ctx, uploadedDigests) if err != nil { - return model.DeploymentKey{}, fmt.Errorf("%s: %w", "failed to get artefact digests", err) + return model.DeploymentKey{}, fmt.Errorf("failed to get artefact digests: %w", err) } if len(artefactDigests) != len(artefacts) { missingDigests := strings.Join(slices.Map(artefacts, func(in DeploymentArtefact) string { return in.Digest.String() }), ", ") @@ -473,7 +473,7 @@ func (d *DAL) CreateDeployment(ctx context.Context, language string, moduleSchem Path: artefact.Path, }) if err != nil { - return model.DeploymentKey{}, fmt.Errorf("%s: %w", "failed to associate artefact with deployment", translatePGError(err)) + return model.DeploymentKey{}, fmt.Errorf("failed to associate artefact with deployment: %w", translatePGError(err)) } } @@ -486,7 +486,7 @@ func (d *DAL) CreateDeployment(ctx context.Context, language string, moduleSchem Verb: ingressRoute.Verb, }) if err != nil { - return model.DeploymentKey{}, fmt.Errorf("%s: %w", "failed to create ingress route", translatePGError(err)) + return model.DeploymentKey{}, fmt.Errorf("failed to create ingress route: %w", translatePGError(err)) } } @@ -525,7 +525,7 @@ func (d *DAL) GetDeployment(ctx context.Context, key model.DeploymentKey) (*mode func (d *DAL) UpsertRunner(ctx context.Context, runner Runner) error { attrBytes, err := json.Marshal(runner.Labels) if err != nil { - return fmt.Errorf("%s: %w", "failed to JSON encode runner labels", err) + return fmt.Errorf("failed to JSON encode runner labels: %w", err) } deploymentID, err := d.db.UpsertRunner(ctx, sql.UpsertRunnerParams{ Key: runner.Key, @@ -573,7 +573,7 @@ func (d *DAL) DeregisterRunner(ctx context.Context, key model.RunnerKey) error { func (d *DAL) ReserveRunnerForDeployment(ctx context.Context, deployment model.DeploymentKey, reservationTimeout time.Duration, labels model.Labels) (Reservation, error) { jsonLabels, err := json.Marshal(labels) if err != nil { - return nil, fmt.Errorf("%s: %w", "failed to JSON encode labels", err) + return nil, fmt.Errorf("failed to JSON encode labels: %w", err) } ctx, cancel := context.WithTimeout(ctx, reservationTimeout) tx, err := d.db.Begin(ctx) @@ -687,7 +687,7 @@ func (d *DAL) ReplaceDeployment(ctx context.Context, newDeploymentKey model.Depl return translatePGError(err) } if count == 1 { - return fmt.Errorf("%s: %w", "deployment already exists", ErrConflict) + return fmt.Errorf("deployment already exists: %w", ErrConflict) } replacedDeploymentKey = optional.Some(oldDeployment.Key) } else if !isNotFound(err) { @@ -780,7 +780,7 @@ func (d *DAL) GetDeploymentsWithMinReplicas(ctx context.Context) ([]Deployment, func (d *DAL) GetActiveDeploymentSchemas(ctx context.Context) ([]*schema.Module, error) { rows, err := d.db.GetActiveDeploymentSchemas(ctx) if err != nil { - return nil, fmt.Errorf("%s: %w", "could not get active deployments", translatePGError(err)) + return nil, fmt.Errorf("could not get active deployments: %w", translatePGError(err)) } return slices.MapErr(rows, func(in sql.GetActiveDeploymentSchemasRow) (*schema.Module, error) { return in.Schema, nil }) } @@ -844,7 +844,7 @@ func (d *DAL) GetProcessList(ctx context.Context) ([]Process, error) { func (d *DAL) GetIdleRunners(ctx context.Context, limit int, labels model.Labels) ([]Runner, error) { jsonb, err := json.Marshal(labels) if err != nil { - return nil, fmt.Errorf("%s: %w", "could not marshal labels", err) + return nil, fmt.Errorf("could not marshal labels: %w", err) } runners, err := d.db.GetIdleRunners(ctx, jsonb, int64(limit)) if isNotFound(err) { @@ -856,7 +856,7 @@ func (d *DAL) GetIdleRunners(ctx context.Context, limit int, labels model.Labels rowLabels := model.Labels{} err := json.Unmarshal(row.Labels, &rowLabels) if err != nil { - return Runner{}, fmt.Errorf("%s: %w", "could not unmarshal labels", err) + return Runner{}, fmt.Errorf("could not unmarshal labels: %w", err) } return Runner{ @@ -878,7 +878,7 @@ func (d *DAL) GetRoutingTable(ctx context.Context, modules []string) (map[string return nil, translatePGError(err) } if len(routes) == 0 { - return nil, fmt.Errorf("%s: %w", "no routes found", ErrNotFound) + return nil, fmt.Errorf("no routes found: %w", ErrNotFound) } out := make(map[string][]Route, len(routes)) for _, route := range routes { @@ -1133,7 +1133,7 @@ func (*DAL) checkForExistingDeployments(ctx context.Context, tx *sql.Tx, moduleS int64(len(artefacts)), ) if err != nil { - return model.DeploymentKey{}, fmt.Errorf("%s: %w", "couldn't check for existing deployment", err) + return model.DeploymentKey{}, fmt.Errorf("couldn't check for existing deployment: %w", err) } if len(existing) > 0 { return existing[0].DeploymentKey, nil diff --git a/backend/controller/dal/notify.go b/backend/controller/dal/notify.go index 980b41cb47..0bf5d1279a 100644 --- a/backend/controller/dal/notify.go +++ b/backend/controller/dal/notify.go @@ -142,20 +142,20 @@ func decodeNotification[K any, T NotificationPayload, KP interface { var deletedKey K var deletedKeyP KP = &deletedKey if err := deletedKeyP.UnmarshalText([]byte(notification.Old)); err != nil { - return Notification[T, K, KP]{}, fmt.Errorf("%s: %w", "failed to unmarshal notification key", err) + return Notification[T, K, KP]{}, fmt.Errorf("failed to unmarshal notification key: %w", err) } deleted = optional.Some(deletedKey) } else { var newKey K var newKeyP KP = &newKey if err := newKeyP.UnmarshalText([]byte(notification.New)); err != nil { - return Notification[T, K, KP]{}, fmt.Errorf("%s: %w", "failed to unmarshal notification key", err) + return Notification[T, K, KP]{}, fmt.Errorf("failed to unmarshal notification key: %w", err) } var msg T var err error msg, deleted, err = translate(newKey) if err != nil { - return Notification[T, K, KP]{}, fmt.Errorf("%s: %w", "failed to translate database notification", err) + return Notification[T, K, KP]{}, fmt.Errorf("failed to translate database notification: %w", err) } if !deleted.Ok() { diff --git a/backend/controller/sql/migrate.go b/backend/controller/sql/migrate.go index 27ee8b106a..3c91b81b34 100644 --- a/backend/controller/sql/migrate.go +++ b/backend/controller/sql/migrate.go @@ -21,11 +21,11 @@ var migrationSchema embed.FS func Migrate(ctx context.Context, dsn string) error { u, err := url.Parse(dsn) if err != nil { - return fmt.Errorf("%s: %w", "invalid DSN", err) + return fmt.Errorf("invalid DSN: %w", err) } conn, err := sql.Open("pgx", dsn) if err != nil { - return fmt.Errorf("%s: %w", "failed to connect to database", err) + return fmt.Errorf("failed to connect to database: %w", err) } defer conn.Close() @@ -35,7 +35,7 @@ func Migrate(ctx context.Context, dsn string) error { db.MigrationsDir = []string{"schema"} err = db.CreateAndMigrate() if err != nil { - return fmt.Errorf("%s: %w", "failed to create and migrate database", err) + return fmt.Errorf("failed to create and migrate database: %w", err) } return nil } diff --git a/backend/protos/xyz/block/ftl/v1/mixins.go b/backend/protos/xyz/block/ftl/v1/mixins.go index 9062f559e1..4937bff064 100644 --- a/backend/protos/xyz/block/ftl/v1/mixins.go +++ b/backend/protos/xyz/block/ftl/v1/mixins.go @@ -66,7 +66,7 @@ func (r *RegisterRunnerRequest) DeploymentAsOptional() (optional.Option[model.De } key, err := model.ParseDeploymentKey(*r.Deployment) if err != nil { - return optional.None[model.DeploymentKey](), fmt.Errorf("%s: %w", "invalid deployment key", err) + return optional.None[model.DeploymentKey](), fmt.Errorf("invalid deployment key: %w", err) } return optional.Some(key), nil } diff --git a/backend/runner/runner.go b/backend/runner/runner.go index 5d42b4d052..2ef55cc424 100644 --- a/backend/runner/runner.go +++ b/backend/runner/runner.go @@ -55,7 +55,7 @@ func Start(ctx context.Context, config Config) error { } hostname, err := os.Hostname() if err != nil { - return fmt.Errorf("%s: %w", "failed to get hostname", err) + return fmt.Errorf("failed to get hostname: %w", err) } pid := os.Getpid() @@ -67,7 +67,7 @@ func Start(ctx context.Context, config Config) error { logger.Debugf("Deployment directory: %s", config.DeploymentDir) err = os.MkdirAll(config.DeploymentDir, 0700) if err != nil { - return fmt.Errorf("%s: %w", "failed to create deployment directory", err) + return fmt.Errorf("failed to create deployment directory: %w", err) } logger.Debugf("Using FTL endpoint: %s", config.ControllerEndpoint) logger.Debugf("Listening on %s", config.Bind) @@ -86,7 +86,7 @@ func Start(ctx context.Context, config Config) error { "languages": slices.Map(config.Language, func(t string) any { return t }), }) if err != nil { - return fmt.Errorf("%s: %w", "failed to marshal labels", err) + return fmt.Errorf("failed to marshal labels: %w", err) } svc := &Service{ @@ -154,12 +154,12 @@ func (s *Service) Ping(ctx context.Context, req *connect.Request[ftlv1.PingReque func (s *Service) Deploy(ctx context.Context, req *connect.Request[ftlv1.DeployRequest]) (response *connect.Response[ftlv1.DeployResponse], err error) { if err, ok := s.registrationFailure.Load().Get(); ok { - return nil, connect.NewError(connect.CodeUnavailable, fmt.Errorf("%s: %w", "failed to register runner", err)) + return nil, connect.NewError(connect.CodeUnavailable, fmt.Errorf("failed to register runner: %w", err)) } key, err := model.ParseDeploymentKey(req.Msg.DeploymentKey) if err != nil { - return nil, connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("%s: %w", "invalid deployment key", err)) + return nil, connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("invalid deployment key: %w", err)) } deploymentLogger := s.getDeploymentLogger(ctx, key) @@ -191,23 +191,23 @@ func (s *Service) Deploy(ctx context.Context, req *connect.Request[ftlv1.DeployR } module, err := schema.ModuleFromProto(gdResp.Msg.Schema) if err != nil { - return nil, fmt.Errorf("%s: %w", "invalid module", err) + return nil, fmt.Errorf("invalid module: %w", err) } deploymentDir := filepath.Join(s.config.DeploymentDir, module.Name, key.String()) if s.config.TemplateDir != "" { err = copy.Copy(s.config.TemplateDir, deploymentDir) if err != nil { - return nil, fmt.Errorf("%s: %w", "failed to copy template directory", err) + return nil, fmt.Errorf("failed to copy template directory: %w", err) } } else { err = os.MkdirAll(deploymentDir, 0700) if err != nil { - return nil, fmt.Errorf("%s: %w", "failed to create deployment directory", err) + return nil, fmt.Errorf("failed to create deployment directory: %w", err) } } err = download.Artefacts(ctx, s.controllerClient, key, deploymentDir) if err != nil { - return nil, fmt.Errorf("%s: %w", "failed to download artefacts", err) + return nil, fmt.Errorf("failed to download artefacts: %w", err) } verbCtx := log.ContextWithLogger(ctx, deploymentLogger.Attrs(map[string]string{"module": module.Name})) @@ -225,7 +225,7 @@ func (s *Service) Deploy(ctx context.Context, req *connect.Request[ftlv1.DeployR ), ) if err != nil { - return nil, fmt.Errorf("%s: %w", "failed to spawn plugin", err) + return nil, fmt.Errorf("failed to spawn plugin: %w", err) } dep := s.makeDeployment(cmdCtx, key, deployment) @@ -244,7 +244,7 @@ func (s *Service) Terminate(ctx context.Context, c *connect.Request[ftlv1.Termin } deploymentKey, err := model.ParseDeploymentKey(c.Msg.DeploymentKey) if err != nil { - return nil, connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("%s: %w", "invalid deployment key", err)) + return nil, connect.NewError(connect.CodeInvalidArgument, fmt.Errorf("invalid deployment key: %w", err)) } if !depl.key.Equal(deploymentKey) { return nil, connect.NewError(connect.CodeInvalidArgument, errors.New("deployment key mismatch")) @@ -253,7 +253,7 @@ func (s *Service) Terminate(ctx context.Context, c *connect.Request[ftlv1.Termin // Soft kill. err = depl.plugin.Cmd.Kill(syscall.SIGTERM) if err != nil { - return nil, fmt.Errorf("%s: %w", "failed to kill plugin", err) + return nil, fmt.Errorf("failed to kill plugin: %w", err) } // Hard kill after 10 seconds. select { @@ -262,7 +262,7 @@ func (s *Service) Terminate(ctx context.Context, c *connect.Request[ftlv1.Termin err := depl.plugin.Cmd.Kill(syscall.SIGKILL) if err != nil { // Should we os.Exit(1) here? - return nil, fmt.Errorf("%s: %w", "failed to kill plugin", err) + return nil, fmt.Errorf("failed to kill plugin: %w", err) } } s.deployment.Store(optional.None[*deployment]()) @@ -320,7 +320,7 @@ func (s *Service) registrationLoop(ctx context.Context, send func(request *ftlv1 }) if err != nil { s.registrationFailure.Store(optional.Some(err)) - return fmt.Errorf("%s: %w", "failed to register with Controller", err) + return fmt.Errorf("failed to register with Controller: %w", err) } s.registrationFailure.Store(optional.None[error]()) diff --git a/cmd/ftl/cmd_schema_generate.go b/cmd/ftl/cmd_schema_generate.go index 378eeb50ef..eb28832592 100644 --- a/cmd/ftl/cmd_schema_generate.go +++ b/cmd/ftl/cmd_schema_generate.go @@ -91,7 +91,7 @@ func (s *schemaGenerateCmd) hotReload(ctx context.Context, client ftlv1connect.C case ftlv1.DeploymentChangeType_DEPLOYMENT_ADDED, ftlv1.DeploymentChangeType_DEPLOYMENT_CHANGED: module, err := schema.ModuleFromProto(msg.Schema) if err != nil { - return fmt.Errorf("%s: %w", "invalid module schema", err) + return fmt.Errorf("invalid module schema: %w", err) } modules[module.Name] = module diff --git a/cmd/ftl/cmd_schema_get.go b/cmd/ftl/cmd_schema_get.go index 94398ed513..3723d1f8b3 100644 --- a/cmd/ftl/cmd_schema_get.go +++ b/cmd/ftl/cmd_schema_get.go @@ -38,7 +38,7 @@ func (g *getSchemaCmd) Run(ctx context.Context, client ftlv1connect.ControllerSe module, err := schema.ModuleFromProto(msg.Schema) if len(g.Modules) == 0 || remainingNames[msg.Schema.Name] { if err != nil { - return fmt.Errorf("%s: %w", "invalid module schema", err) + return fmt.Errorf("invalid module schema: %w", err) } fmt.Println(module) delete(remainingNames, msg.Schema.Name) diff --git a/common/plugin/serve.go b/common/plugin/serve.go index afebc4e94e..c1a09c00ea 100644 --- a/common/plugin/serve.go +++ b/common/plugin/serve.go @@ -170,7 +170,7 @@ func Start[Impl any, Iface any, Config any]( func allocatePort() (*net.TCPAddr, error) { l, err := net.ListenTCP("tcp", &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1)}) if err != nil { - return nil, fmt.Errorf("%s: %w", "failed to allocate port", err) + return nil, fmt.Errorf("failed to allocate port: %w", err) } _ = l.Close() return l.Addr().(*net.TCPAddr), nil //nolint:forcetypeassert diff --git a/common/plugin/spawn.go b/common/plugin/spawn.go index abd5d243c8..08fb4e95e9 100644 --- a/common/plugin/spawn.go +++ b/common/plugin/spawn.go @@ -181,14 +181,14 @@ func Spawn[Client PingableClient]( select { case <-dialCtx.Done(): - return nil, nil, fmt.Errorf("%s: %w", "plugin timed out while starting", dialCtx.Err()) + return nil, nil, fmt.Errorf("plugin timed out while starting: %w", dialCtx.Err()) case <-cmdCtx.Done(): - return nil, nil, fmt.Errorf("%s: %w", "plugin process died", cmdCtx.Err()) + return nil, nil, fmt.Errorf("plugin process died: %w", cmdCtx.Err()) case err := <-pingErr: if err != nil { - return nil, nil, fmt.Errorf("%s: %w", "plugin failed to respond to ping", err) + return nil, nil, fmt.Errorf("plugin failed to respond to ping: %w", err) } } diff --git a/go-runtime/compile/parser.go b/go-runtime/compile/parser.go index 95c348b0b5..2feed44796 100644 --- a/go-runtime/compile/parser.go +++ b/go-runtime/compile/parser.go @@ -96,7 +96,7 @@ func parseDirectives(fset *token.FileSet, docs *ast.CommentGroup) ([]directive, } else { err = fmt.Errorf("%s: %w", pos, err) } - return nil, fmt.Errorf("%s: %w", "invalid directive", err) + return nil, fmt.Errorf("invalid directive: %w", err) } directives = append(directives, directive.Directive) } diff --git a/internal/observability/client.go b/internal/observability/client.go index bb6174c5ba..ffd779be5c 100644 --- a/internal/observability/client.go +++ b/internal/observability/client.go @@ -53,12 +53,12 @@ func Init(ctx context.Context, serviceName, serviceVersion string, config Config semconv.ServiceVersion(serviceVersion), )) if err != nil { - return fmt.Errorf("%s: %w", "failed to create OTEL resource", err) + return fmt.Errorf("failed to create OTEL resource: %w", err) } otelMetricExporter, err := otlpmetricgrpc.New(ctx) if err != nil { - return fmt.Errorf("%s: %w", "failed to create OTEL metric exporter", err) + return fmt.Errorf("failed to create OTEL metric exporter: %w", err) } meterProvider := metric.NewMeterProvider(metric.WithReader(metric.NewPeriodicReader(otelMetricExporter)), metric.WithResource(res)) @@ -66,7 +66,7 @@ func Init(ctx context.Context, serviceName, serviceVersion string, config Config otelTraceExporter, err := otlptracegrpc.New(ctx) if err != nil { - return fmt.Errorf("%s: %w", "failed to create OTEL trace exporter", err) + return fmt.Errorf("failed to create OTEL trace exporter: %w", err) } traceProvider := trace.NewTracerProvider(trace.WithBatcher(otelTraceExporter), trace.WithResource(res)) otel.SetTracerProvider(traceProvider) diff --git a/internal/rpc/context.go b/internal/rpc/context.go index 821a71aff5..aaa38ded9a 100644 --- a/internal/rpc/context.go +++ b/internal/rpc/context.go @@ -57,7 +57,7 @@ func IsDirectRouted(ctx context.Context) bool { return ctx.Value(ftlDirectRoutingKey{}) != nil } -// RequestKeyFromContext returns the request Key from the context, if any. +// RequestKeyFromContext returns the request key from the context, if any. // // TODO: Return an Option here instead of a bool. func RequestKeyFromContext(ctx context.Context) (optional.Option[model.RequestKey], error) { @@ -68,12 +68,12 @@ func RequestKeyFromContext(ctx context.Context) (optional.Option[model.RequestKe } key, err := model.ParseRequestKey(keyStr) if err != nil { - return optional.None[model.RequestKey](), fmt.Errorf("%s: %w", "invalid request Key", err) + return optional.None[model.RequestKey](), fmt.Errorf("invalid request key: %w", err) } return optional.Some(key), nil } -// WithRequestName adds the request Key to the context. +// WithRequestName adds the request key to the context. func WithRequestName(ctx context.Context, key model.RequestKey) context.Context { return context.WithValue(ctx, requestIDKey{}, key.String()) }