Use errors.AsType instead of errors.As - #2281
Conversation
📊 API Diff Results
|
📊 API Diff Results
|
📊 API Diff Results
|
There was a problem hiding this comment.
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.Ascall sites witherrors.AsType[T]in runtime code paths and tests. - Updated
LimitErrordocumentation to demonstrate the new typedAsTypepattern. - 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.
| limitErr, ok := errors.AsType[LimitError](err) | ||
| require.True(t, ok) | ||
| _ = limitErr | ||
| _, ok = errors.AsType[LimitError](fmt.Errorf("wrapped: %w", err)) | ||
| require.True(t, ok) |
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.
There was a problem hiding this comment.
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
_ = limitErronly 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) |
| func (s staticRelayer) AssertEqual(_ context.Context, t *testing.T, relayer looptypes.Relayer) { | ||
| s.assertEqual(t, relayer, true) | ||
| } |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
pkg/settings/limits/errors_test.go:38
- The test stores
limitErrbut doesn't use it (only_ = limitErrto satisfy the compiler). Since the test only asserts type-identification behavior, you can drop the unused variable and use the blank identifier to keep the intent clear.
limitErr, ok := errors.AsType[LimitError](err)
require.True(t, ok)
_ = limitErr
_, ok = errors.AsType[LimitError](fmt.Errorf("wrapped: %w", err))
require.True(t, ok)
Converts call sites to use the Go 1.26+ typed errors.AsType helper.
errors.As(err, &target)witherrors.AsType[T](err).errorAshelper inpkg/services/orgresolver/fallback.gobecause itsgrpcStatusinterface is not an error type and therefore cannot be used witherrors.AsType.