From c6731fe6b35bdc6a79b468d22fa23824127c3db1 Mon Sep 17 00:00:00 2001 From: ivanauth Date: Tue, 16 Jun 2026 11:59:24 -0400 Subject: [PATCH] chore: remove statically-analyzable dead code (#1719) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove four genuinely-unused symbols flagged by `deadcode`, all under internal/ (no external-API impact) and unused by tests: - common.CancelationContextHandler (cancelation.go, deleted) - common.ConnectWithInstrumentation (superseded by ...AndTimeout) - logging.Log() - shared.NewMaxDepthExceededError (a duplicate; the used one lives in internal/dispatch) Scope is intentionally conservative. NOT removed, despite being flagged: - DebugAnalyzeBeforeStatistics — test-only, but required: the datastore StatsTest relies on it to force ANALYZE (the PG harness runs autovacuum=off, so EstimatedRelationshipCount is 0 without it). - pkg/ exported symbols — removing these needs a deprecation cycle. - AsValidationError — a deadcode false positive; used by pkg/schemautil. --- .../datastore/postgres/common/cancelation.go | 18 ------------------ internal/datastore/postgres/common/pgx.go | 10 ---------- internal/logging/logger.go | 2 -- internal/services/shared/errors.go | 15 --------------- 4 files changed, 45 deletions(-) delete mode 100644 internal/datastore/postgres/common/cancelation.go diff --git a/internal/datastore/postgres/common/cancelation.go b/internal/datastore/postgres/common/cancelation.go deleted file mode 100644 index c1c910c8b1..0000000000 --- a/internal/datastore/postgres/common/cancelation.go +++ /dev/null @@ -1,18 +0,0 @@ -package common - -import ( - "time" - - "github.com/jackc/pgx/v5/pgconn" - "github.com/jackc/pgx/v5/pgconn/ctxwatch" -) - -// CancelationContextHandler returns a context watcher handler for canceling requests -// when a context is canceled, rather than closing connections. -func CancelationContextHandler(pgConn *pgconn.PgConn) ctxwatch.Handler { - return &pgconn.CancelRequestContextWatcherHandler{ - Conn: pgConn, - CancelRequestDelay: 50 * time.Millisecond, // Cancel immediately. - DeadlineDelay: 1 * time.Second, // If not acknowledged, close the connection after a second. - } -} diff --git a/internal/datastore/postgres/common/pgx.go b/internal/datastore/postgres/common/pgx.go index ec9fbefa75..931f5b2a96 100644 --- a/internal/datastore/postgres/common/pgx.go +++ b/internal/datastore/postgres/common/pgx.go @@ -57,16 +57,6 @@ func ParseConfigWithInstrumentation(url string) (*pgx.ConnConfig, error) { return connConfig, nil } -// ConnectWithInstrumentation returns a pgx.Conn that has been instrumented for observability -func ConnectWithInstrumentation(ctx context.Context, url string) (*pgx.Conn, error) { - connConfig, err := ParseConfigWithInstrumentation(url) - if err != nil { - return nil, err - } - - return pgx.ConnectConfig(ctx, connConfig) -} - // ConnectWithInstrumentationAndTimeout returns a pgx.Conn that has been instrumented for observability func ConnectWithInstrumentationAndTimeout(ctx context.Context, url string, connectTimeout time.Duration) (*pgx.Conn, error) { connConfig, err := ParseConfigWithInstrumentation(url) diff --git a/internal/logging/logger.go b/internal/logging/logger.go index 1e9de0a773..1315c0eac7 100644 --- a/internal/logging/logger.go +++ b/internal/logging/logger.go @@ -35,6 +35,4 @@ func Fatal() *zerolog.Event { return Logger.Fatal() } func WithLevel(level zerolog.Level) *zerolog.Event { return Logger.WithLevel(level) } -func Log() *zerolog.Event { return Logger.Log() } - func Ctx(ctx context.Context) *zerolog.Logger { return zerolog.Ctx(ctx) } diff --git a/internal/services/shared/errors.go b/internal/services/shared/errors.go index 9eb241798a..e094a68e0b 100644 --- a/internal/services/shared/errors.go +++ b/internal/services/shared/errors.go @@ -95,21 +95,6 @@ func (err MaxDepthExceededError) GRPCStatus() *status.Status { ) } -// NewMaxDepthExceededError creates a new MaxDepthExceededError. -func NewMaxDepthExceededError(allowedMaximumDepth uint32, isCheckRequest bool) error { - if isCheckRequest { - return MaxDepthExceededError{ - spiceerrors.NewWithAdditionalDetailsError(fmt.Errorf("the check request has exceeded the allowable maximum depth of %d: this usually indicates a recursive or too deep data dependency. Try running zed with --explain to see the dependency. See "+sharederrors.MaxDepthErrorLink, allowedMaximumDepth)), - allowedMaximumDepth, - } - } - - return MaxDepthExceededError{ - spiceerrors.NewWithAdditionalDetailsError(fmt.Errorf("the request has exceeded the allowable maximum depth of %d: this usually indicates a recursive or too deep data dependency. See %s", allowedMaximumDepth, sharederrors.MaxDepthErrorLink)), - allowedMaximumDepth, - } -} - func AsValidationError(err error) *SchemaWriteDataValidationError { var validationErr SchemaWriteDataValidationError if errors.As(err, &validationErr) {