Skip to content

Use errors.AsType instead of errors.As#2281

Open
pkcll wants to merge 2 commits into
mainfrom
use-errors-astype
Open

Use errors.AsType instead of errors.As#2281
pkcll wants to merge 2 commits into
mainfrom
use-errors-astype

Conversation

@pkcll

@pkcll pkcll commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Converts call sites to use the Go 1.26+ typed errors.AsType helper.

  • Replaces pointer-variable declarations and errors.As(err, &target) with errors.AsType[T](err).
  • Updates the LimitError doc comment to show the new pattern.
  • Keeps the custom errorAs helper in pkg/services/orgresolver/fallback.go because its grpcStatus interface is not an error type and therefore cannot be used with errors.AsType.

Copilot AI review requested due to automatic review settings July 24, 2026 15:51
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

📊 API Diff Results

No changes detected for module github.com/smartcontractkit/chainlink-common/pkg/chipingress

View full report

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

📊 API Diff Results

No changes detected for module github.com/smartcontractkit/chainlink-common/pkg/monitoring

View full report

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

📊 API Diff Results

No changes detected for module github.com/smartcontractkit/chainlink-common

View full report

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates error type-checking patterns across the codebase to use the Go 1.26+ typed helper errors.AsType[T](err) instead of errors.As(err, &target), and aligns documentation/tests with the new idiom.

Changes:

  • Replaced errors.As call sites with errors.AsType[T] in runtime code paths and tests.
  • Updated LimitError documentation to demonstrate the new typed AsType pattern.
  • Simplified several error-handling blocks by removing now-unnecessary target variable declarations.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/workflows/wasm/host/execution.go Uses errors.AsType to detect and serialize capability errors in async capability calls.
pkg/workflows/host/execution_restrictions_test.go Updates restriction tests to assert typed capability errors via AsType.
pkg/settings/limits/errors.go Updates LimitError doc comment to recommend errors.AsType.
pkg/settings/limits/errors_test.go Converts LimitError assertions to errors.AsType (minor cleanup opportunity noted in review comment).
pkg/monitoring/schema_registry.go Uses errors.AsType to detect schema-registry “not found” errors by typed error matching.
pkg/loop/internal/relayer/pluginprovider/ext/median/test/median.go Uses errors.AsType for extracting *CompareError in test helper server logic.
pkg/loop/internal/core/services/capability/capabilities.go Uses errors.AsType when deciding whether to serialize capability errors over gRPC.
pkg/loop/internal/core/services/capability/capabilities_test.go Updates capability tests to extract caperrors.Error using errors.AsType.
pkg/config/toml.go Uses errors.AsType to format *toml.StrictMissingError as user-friendly errors.
pkg/chipingress/batch/client.go Uses errors.AsType to classify *PublishError for metric-friendly error codes.
pkg/beholder/batch_emitter_service.go Uses errors.AsType to detect publish errors and avoid noisy logs for partial delivery cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/settings/limits/errors_test.go Outdated
Comment on lines +34 to +38
limitErr, ok := errors.AsType[LimitError](err)
require.True(t, ok)
_ = limitErr
_, ok = errors.AsType[LimitError](fmt.Errorf("wrapped: %w", err))
require.True(t, ok)
jmank88
jmank88 previously approved these changes Jul 24, 2026
@pkcll
pkcll marked this pull request as ready for review July 24, 2026 16:24
@pkcll
pkcll requested review from a team as code owners July 24, 2026 16:24
engnke
engnke previously approved these changes Jul 24, 2026
Run the recovery subtests sequentially so the relayer has time to relaunch

between plugin-killing limit hits, instead of racing multiple parallel calls

against a connection that is still closing.
Copilot AI review requested due to automatic review settings July 24, 2026 18:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 13 out of 13 changed files in this pull request and generated 2 comments.

Comments suppressed due to low confidence (1)

pkg/settings/limits/errors_test.go:38

  • The test assigns limitErr and then uses _ = limitErr only to avoid an unused-variable compile error. Since the value isn't asserted on, this can be simplified by discarding it in the AsType assignment.
			limitErr, ok := errors.AsType[LimitError](err)
			require.True(t, ok)
			_ = limitErr
			_, ok = errors.AsType[LimitError](fmt.Errorf("wrapped: %w", err))
			require.True(t, ok)

servicetest.Run(t, relayer)

relayertest.Run(t, relayer)
relayertest.RunSequential(t, relayer)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @pkcll

Comment on lines 424 to +426
func (s staticRelayer) AssertEqual(_ context.Context, t *testing.T, relayer looptypes.Relayer) {
s.assertEqual(t, relayer, true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants