Skip to content

Conversation

@vertex451
Copy link
Contributor

@vertex451 vertex451 commented Dec 26, 2025

📝 Description

Register function that was used in our error registering under the hood uses grpccodes.Unknown code, which is mapped to http.InternalError status code(500). link

So, each error ended up with that code at this line:

My fix replaces Register with RegisterWithGRPCCode that propagates the original error to the http status code.

Testing

Tested at local network with akash binary build using chain-sdk with this branch:

In browser you can see code 404, which mean that the bug is fixed.

Screenshot 2025-12-29 at 16 07 29

Question to resolve

  1. Should I do the same in other modules? For instance, audit, cert, escrow, market, provider, take, types

🔧 Purpose of the Change

  • Bug fix

📌 Related Issues

✅ Checklist

  • I've updated relevant documentation
  • Code follows Akash Network's style guide
  • I've added/updated relevant unit tests
  • Dependencies have been properly updated
  • I agree and adhered to the Contribution Guidelines

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 26, 2025

Walkthrough

Replace many package error initializers with gRPC-aware registrations by switching to sdkerrors.RegisterWithGRPCCode(...) and importing google.golang.org/grpc/codes; add table-driven tests that assert each module error maps to the expected gRPC status code. (≤50 words)

Changes

Cohort / File(s) Summary
Registry updates (error → GRPC-aware)
go/node/deployment/v1/errors.go, go/node/audit/v1/errors.go, go/node/cert/v1/errors.go, go/node/escrow/module/error.go, go/node/market/v1/errors.go, go/node/provider/v1beta4/errors.go, go/node/take/v1/errors.go, go/node/types/attributes/v1/attribute.go, go/node/types/deposit/v1/errors.go
Replaced prior error initializers with sdkerrors.RegisterWithGRPCCode(ModuleName, ..., codes.<CODE>, "..."), added google.golang.org/grpc/codes imports, and assigned explicit gRPC codes (NotFound, InvalidArgument, AlreadyExists, FailedPrecondition, Internal, PermissionDenied). Some messages/identifiers adjusted (e.g., rename errCodeUnknownLeaseForOrder → errCodeUnknownLeaseForBid).
Tests: error → gRPC mapping
go/node/deployment/v1/errors_test.go, go/node/audit/v1/errors_test.go, go/node/cert/v1/errors_test.go, go/node/escrow/module/error_test.go, go/node/market/v1/errors_test.go, go/node/provider/v1beta4/errors_test.go, go/node/take/v1/errors_test.go, go/node/types/attributes/v1/errors_test.go, go/node/types/deposit/v1/errors_test.go
Added table-driven tests that call status.FromError(...) and assert each exported module error converts to the expected gRPC status code using require. Tests cover NotFound, AlreadyExists, InvalidArgument, FailedPrecondition, Internal, PermissionDenied cases.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • troian
  • stalniy

Poem

🐇 I hopped through lines with tiny feet,

I swapped registrations, tidy and neat.
NotFound, Invalid, AlreadyExists in a row,
Tests now whisper which codes they know.
A carrot cheers the CI as we go!

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: replacing sdkerrors.Register with RegisterWithGRPCCode for proper error propagation.
Description check ✅ Passed The PR description covers the problem, solution, testing, and includes a related issue link, but several checklist items remain unchecked and the question about other modules is unresolved.
Linked Issues check ✅ Passed The PR addresses the core requirement from issue #404 by replacing error registration to properly propagate gRPC codes, enabling correct HTTP status mapping (404 instead of 500) for not-found errors.
Out of Scope Changes check ✅ Passed The PR makes comprehensive error registration updates across multiple modules (deployment, audit, cert, escrow, market, provider, take, types), which directly serves the linked issue's objective of fixing HTTP status code propagation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch artem/fix/500-instead-of-404

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dac34e0 and e57a675.

📒 Files selected for processing (5)
  • go/node/audit/v1/errors.go
  • go/node/cert/v1/errors.go
  • go/node/deployment/v1/errors.go
  • go/node/market/v1/errors.go
  • go/node/types/deposit/v1/errors.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • go/node/types/deposit/v1/errors.go
🧰 Additional context used
🧬 Code graph analysis (4)
go/node/audit/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
go/node/cert/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
go/node/market/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
go/node/deployment/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: test
  • GitHub Check: coverage
  • GitHub Check: go
  • GitHub Check: proto
🔇 Additional comments (5)
go/node/audit/v1/errors.go (1)

5-22: LGTM! Correct gRPC code mappings for audit errors.

The error registrations properly map to their semantic gRPC codes: NotFound for missing entities (provider, attribute) and InvalidArgument for malformed input (address). This will ensure these errors return the correct HTTP status codes (404, 400) instead of 500.

go/node/cert/v1/errors.go (1)

7-52: LGTM! Comprehensive gRPC code mappings for certificate errors.

All nine error registrations use appropriate gRPC codes:

  • NotFound for missing certificates
  • InvalidArgument for validation failures (address, serial, value, pubkey, state, key size)
  • AlreadyExists for duplicate certificates
  • FailedPrecondition for revocation state violations

This ensures proper HTTP status code propagation (404, 400, 409, 412) across certificate operations.

go/node/market/v1/errors.go (1)

5-112: LGTM! Comprehensive market error mappings with past issues resolved.

The file correctly maps 31 market-related errors to appropriate gRPC codes:

  • NotFound (9): bid/lease/order/group lookup failures
  • InvalidArgument (11): validation failures (price, deposit, attributes, capabilities)
  • FailedPrecondition (8): state violations (not active, not open, closed, timing issues)
  • AlreadyExists (2): duplicate bids/orders
  • Internal (1): internal errors

Past review issues have been addressed (ErrInvalidBid message, constant naming, group error messages). This comprehensive update will ensure all market errors return correct HTTP status codes.

go/node/deployment/v1/errors.go (2)

4-5: LGTM! Import standardization for deployment errors.

The change from cerrors to sdkerrors and addition of grpc/codes aligns with the PR's objective to enable proper error code propagation across all modules.


36-80: LGTM! Correct gRPC code mappings for deployment errors.

All 23 deployment and group errors are mapped to appropriate gRPC codes:

  • NotFound (3): name/deployment/group not found
  • InvalidArgument (13): validation failures (ID, hash, groups, deposit, params)
  • AlreadyExists (1): duplicate deployments
  • FailedPrecondition (5): state violations (closed, open, paused transitions)
  • Internal (1): internal errors

These mappings will ensure deployment operations return correct HTTP status codes. Note: The team has consciously deferred fixing a pre-existing comment/message inconsistency for ErrInvalidGroupID (lines 59-60) to keep this PR focused on the gRPC code migration.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@vertex451 vertex451 marked this pull request as ready for review December 26, 2025 13:39
@vertex451 vertex451 requested a review from a team as a code owner December 26, 2025 13:39
@vertex451 vertex451 self-assigned this Dec 26, 2025
@vertex451 vertex451 requested a review from troian December 26, 2025 13:40
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4a2663b and 1ac45d3.

📒 Files selected for processing (2)
  • go/node/deployment/v1/errors.go
  • go/node/deployment/v1/errors_test.go
🧰 Additional context used
🧬 Code graph analysis (1)
go/node/deployment/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (17-17)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: coverage
  • GitHub Check: test
  • GitHub Check: go
🔇 Additional comments (5)
go/node/deployment/v1/errors.go (3)

5-5: LGTM! Correct import for gRPC codes.

The addition of the google.golang.org/grpc/codes import is necessary for the new RegisterWithGRPCCode calls and enables proper HTTP status code mapping.


36-42: Excellent fix for the core issue!

The mapping of ErrDeploymentNotFound to codes.NotFound (line 42) directly addresses issue #404 by ensuring that missing deployment queries return HTTP 404 instead of HTTP 500. The gRPC code mappings for related "not found" errors are also correct.


44-81: LGTM! All remaining gRPC code mappings are semantically correct.

The error-to-status-code mappings are appropriate:

  • FailedPrecondition for state-based errors (closed, open, paused deployments/groups)
  • InvalidArgument for all validation failures
  • Internal for internal server errors

This will ensure correct HTTP status codes are returned via grpc-gateway.

go/node/deployment/v1/errors_test.go (2)

1-11: LGTM! Proper test structure and imports.

Using an external test package (v1_test) is good practice for testing public APIs, and the imports are correct for validating gRPC status code mappings.


13-143: Excellent test coverage and implementation!

The test provides complete coverage of all 23 error definitions with correct validation approach:

  • Uses status.FromError to properly extract gRPC status codes
  • Verifies both conversion success and code correctness
  • Table-driven structure with descriptive test case names
  • Covers all gRPC code categories: NotFound (3), AlreadyExists (1), InvalidArgument (13), FailedPrecondition (5), and Internal (1)

This ensures the fix for issue #404 is properly validated and prevents regressions.

…to propagate the proper http code into the response
@vertex451 vertex451 force-pushed the artem/fix/500-instead-of-404 branch from e970797 to dc80e0d Compare December 29, 2025 15:23
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
go/node/deployment/v1/errors_test.go (1)

13-13: Consider adding a package-level doc comment.

A brief comment explaining that this test ensures proper HTTP status codes via grpc-gateway mapping would help future maintainers understand the test's purpose in the context of the HTTP 500 → 404 fix.

🔎 Suggested addition
+// Package v1_test validates gRPC status code mappings for deployment errors.
+// These mappings ensure grpc-gateway returns correct HTTP status codes
+// (e.g., 404 for NotFound instead of 500 for Unknown).
+
 package v1_test
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e970797 and dc80e0d.

📒 Files selected for processing (2)
  • go/node/deployment/v1/errors.go
  • go/node/deployment/v1/errors_test.go
🧰 Additional context used
🧬 Code graph analysis (2)
go/node/deployment/v1/errors_test.go (1)
go/node/deployment/v1/errors.go (23)
  • ErrDeploymentNotFound (42-42)
  • ErrGroupNotFound (62-62)
  • ErrNameDoesNotExist (36-36)
  • ErrDeploymentExists (40-40)
  • ErrInvalidRequest (38-38)
  • ErrInvalidGroups (48-48)
  • ErrInvalidDeploymentID (50-50)
  • ErrEmptyHash (52-52)
  • ErrInvalidHash (54-54)
  • ErrInvalidDeployment (58-58)
  • ErrInvalidGroupID (60-60)
  • ErrInvalidDeposit (74-74)
  • ErrInvalidIDPath (76-76)
  • ErrInvalidParam (78-78)
  • ErrInvalidEscrowID (80-80)
  • ErrOwnerAcctMissing (46-46)
  • ErrGroupSpecInvalid (72-72)
  • ErrDeploymentClosed (44-44)
  • ErrGroupClosed (64-64)
  • ErrGroupOpen (66-66)
  • ErrGroupPaused (68-68)
  • ErrGroupNotOpen (70-70)
  • ErrInternal (56-56)
go/node/deployment/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (17-17)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: test
  • GitHub Check: coverage
  • GitHub Check: go
  • GitHub Check: proto
🔇 Additional comments (2)
go/node/deployment/v1/errors.go (1)

5-5: LGTM! Error-to-HTTP-status mappings are correct.

The addition of explicit gRPC codes to all error registrations directly addresses the PR objective. The NotFound codes (lines 36, 42, 62) will now correctly map to HTTP 404 instead of 500 via grpc-gateway, fixing the reported issue. All other code mappings are semantically appropriate:

  • AlreadyExists → HTTP 409
  • InvalidArgument → HTTP 400
  • FailedPrecondition → HTTP 400
  • Internal → HTTP 500

Also applies to: 36-80

go/node/deployment/v1/errors_test.go (1)

13-143: LGTM! Comprehensive test coverage for gRPC code mappings.

The test validates all 23 error variables against their expected gRPC codes using status.FromError, which confirms the error registrations will produce the correct HTTP status codes via grpc-gateway. Test structure is clean and follows Go's table-driven testing pattern.

…in audit, cert, escrow, market, provider, take and types modules
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
go/node/market/v1/errors.go (1)

111-112: Add documentation comment for ErrInvalidEscrowID.

All other errors in this file have documentation comments. For consistency, add one for the new error.

🔎 Suggested fix
 	// ErrInvalidLeaseClosedReason indicates reason for lease close does not match context
 	ErrInvalidLeaseClosedReason = sdkerrors.RegisterWithGRPCCode(ModuleName, errInvalidLeaseClosedReason, codes.InvalidArgument, "invalid lease closed reason")
-	ErrInvalidEscrowID          = sdkerrors.RegisterWithGRPCCode(ModuleName, errInvalidEscrowID, codes.InvalidArgument, "invalid escrow id")
+	// ErrInvalidEscrowID indicates an invalid escrow ID
+	ErrInvalidEscrowID = sdkerrors.RegisterWithGRPCCode(ModuleName, errInvalidEscrowID, codes.InvalidArgument, "invalid escrow id")
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between dc80e0d and 9abd45d.

📒 Files selected for processing (17)
  • go/node/audit/v1/errors.go
  • go/node/audit/v1/errors_test.go
  • go/node/cert/v1/errors.go
  • go/node/cert/v1/errors_test.go
  • go/node/deployment/v1/errors.go
  • go/node/escrow/module/error.go
  • go/node/escrow/module/error_test.go
  • go/node/market/v1/errors.go
  • go/node/market/v1/errors_test.go
  • go/node/provider/v1beta4/errors.go
  • go/node/provider/v1beta4/errors_test.go
  • go/node/take/v1/errors.go
  • go/node/take/v1/errors_test.go
  • go/node/types/attributes/v1/attribute.go
  • go/node/types/attributes/v1/errors_test.go
  • go/node/types/deposit/v1/errors.go
  • go/node/types/deposit/v1/errors_test.go
🧰 Additional context used
🧬 Code graph analysis (16)
go/node/take/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
go/node/audit/v1/errors_test.go (1)
go/node/audit/v1/errors.go (3)
  • ErrProviderNotFound (16-16)
  • ErrAttributeNotFound (22-22)
  • ErrInvalidAddress (19-19)
go/node/take/v1/errors_test.go (4)
go/node/market/v1/errors_test.go (1)
  • TestErrorGRPCStatusCodes (13-198)
go/node/types/attributes/v1/errors_test.go (1)
  • TestErrorGRPCStatusCodes (13-38)
go/node/types/deposit/v1/errors_test.go (1)
  • TestErrorGRPCStatusCodes (13-38)
go/node/take/v1/errors.go (1)
  • ErrInvalidParam (14-14)
go/node/escrow/module/error_test.go (1)
go/node/escrow/module/error.go (15)
  • ErrAccountExists (29-29)
  • ErrPaymentExists (34-34)
  • ErrInvalidDenomination (33-33)
  • ErrPaymentRateZero (37-37)
  • ErrInvalidPayment (38-38)
  • ErrInvalidSettlement (39-39)
  • ErrInvalidID (40-40)
  • ErrInvalidAccount (41-41)
  • ErrInvalidAccountDepositor (42-42)
  • ErrInvalidDeposit (44-44)
  • ErrInvalidAuthzScope (45-45)
  • ErrAccountClosed (30-30)
  • ErrAccountOverdrawn (32-32)
  • ErrPaymentClosed (35-35)
  • ErrUnauthorizedDepositScope (43-43)
go/node/cert/v1/errors_test.go (3)
go/node/market/v1/errors_test.go (1)
  • TestErrorGRPCStatusCodes (13-198)
go/node/take/v1/errors_test.go (1)
  • TestErrorGRPCStatusCodes (13-33)
go/node/cert/v1/errors.go (9)
  • ErrCertificateNotFound (28-28)
  • ErrCertificateExists (34-34)
  • ErrInvalidAddress (31-31)
  • ErrInvalidSerialNumber (40-40)
  • ErrInvalidCertificateValue (43-43)
  • ErrInvalidPubkeyValue (46-46)
  • ErrInvalidState (49-49)
  • ErrInvalidKeySize (52-52)
  • ErrCertificateAlreadyRevoked (37-37)
go/node/audit/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
go/node/market/v1/errors_test.go (1)
go/node/market/v1/errors.go (34)
  • ErrUnknownBid (59-59)
  • ErrUnknownLease (61-61)
  • ErrUnknownLeaseForBid (63-63)
  • ErrUnknownOrderForBid (65-65)
  • ErrNoLeaseForOrder (73-73)
  • ErrOrderNotFound (75-75)
  • ErrGroupNotFound (77-77)
  • ErrBidNotFound (83-83)
  • ErrLeaseNotFound (87-87)
  • ErrUnknownProvider (107-107)
  • ErrBidExists (89-89)
  • ErrOrderExists (97-97)
  • ErrEmptyProvider (47-47)
  • ErrSameAccount (49-49)
  • ErrBidOverOrder (53-53)
  • ErrAttributeMismatch (55-55)
  • ErrCapabilitiesMismatch (57-57)
  • ErrBidZeroPrice (85-85)
  • ErrBidInvalidPrice (91-91)
  • ErrInvalidDeposit (103-103)
  • ErrInvalidParam (105-105)
  • ErrInvalidBid (109-109)
  • ErrInvalidLeaseClosedReason (111-111)
  • ErrInvalidEscrowID (112-112)
  • ErrLeaseNotActive (67-67)
  • ErrBidNotActive (69-69)
  • ErrBidNotOpen (71-71)
  • ErrGroupNotOpen (79-79)
  • ErrOrderNotOpen (81-81)
  • ErrOrderActive (93-93)
  • ErrOrderClosed (95-95)
  • ErrOrderTooEarly (99-99)
  • ErrOrderDurationExceeded (101-101)
  • ErrInternal (51-51)
go/node/types/deposit/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
go/node/cert/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
go/node/types/deposit/v1/errors_test.go (3)
go/node/take/v1/errors_test.go (1)
  • TestErrorGRPCStatusCodes (13-33)
go/node/types/attributes/v1/errors_test.go (1)
  • TestErrorGRPCStatusCodes (13-38)
go/node/types/deposit/v1/errors.go (2)
  • ErrInvalidDepositor (17-17)
  • ErrInvalidDepositSource (19-19)
go/node/types/attributes/v1/errors_test.go (1)
go/node/types/attributes/v1/attribute.go (2)
  • ErrAttributesDuplicateKeys (30-30)
  • ErrInvalidAttributeKey (31-31)
go/node/provider/v1beta4/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
go/node/escrow/module/error.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
go/node/market/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
go/node/deployment/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
go/node/provider/v1beta4/errors_test.go (1)
go/node/provider/v1beta4/errors.go (8)
  • ErrProviderNotFound (27-27)
  • ErrProviderExists (30-30)
  • ErrInvalidProviderURI (21-21)
  • ErrNotAbsProviderURI (24-24)
  • ErrInvalidAddress (33-33)
  • ErrAttributes (36-36)
  • ErrInvalidInfoWebsite (42-42)
  • ErrIncompatibleAttributes (39-39)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: test
  • GitHub Check: coverage
  • GitHub Check: go
  • GitHub Check: proto
🔇 Additional comments (24)
go/node/audit/v1/errors.go (1)

14-22: LGTM! gRPC code mappings are semantically correct.

The error-to-gRPC-code assignments align well with standard conventions:

  • ErrProviderNotFound and ErrAttributeNotFoundcodes.NotFound
  • ErrInvalidAddresscodes.InvalidArgument

This correctly addresses the HTTP 500 → 404 issue for "not found" semantics.

go/node/provider/v1beta4/errors.go (1)

19-43: LGTM! Comprehensive and semantically correct gRPC code mappings.

The error registrations follow gRPC conventions properly:

  • Validation errors (ErrInvalidProviderURI, ErrNotAbsProviderURI, ErrInvalidAddress, etc.) → codes.InvalidArgument
  • Resource not found (ErrProviderNotFound) → codes.NotFound
  • Duplicate resource (ErrProviderExists) → codes.AlreadyExists
  • State violation (ErrIncompatibleAttributes) → codes.FailedPrecondition

This ensures proper HTTP status code mapping via grpc-gateway.

go/node/deployment/v1/errors.go (2)

41-42: Key fix for issue #404: ErrDeploymentNotFound now maps to HTTP 404.

This is the core change that resolves the bug. With codes.NotFound, the grpc-gateway will correctly translate this to HTTP 404 instead of the previous HTTP 500.


34-81: Comprehensive gRPC code mappings look correct.

All error-to-code mappings follow gRPC semantic conventions:

  • NotFound for missing resources (deployment, group, name)
  • AlreadyExists for duplicate resources
  • FailedPrecondition for state violations (closed, paused, open states)
  • InvalidArgument for validation errors
  • Internal for internal errors

The previous concern about ErrInvalidGroupID (lines 59-60) has been addressed with the corrected comment and message.

go/node/take/v1/errors.go (1)

12-15: LGTM!

The ErrInvalidParam correctly maps to codes.InvalidArgument, which aligns with the semantic meaning of an invalid parameter.

go/node/types/attributes/v1/errors_test.go (1)

13-38: LGTM! Well-structured test for gRPC status code mappings.

The table-driven test pattern with subtests is clean and maintainable. The test correctly validates that:

  1. Errors are convertible to gRPC status via status.FromError
  2. The resulting status codes match expectations

This provides good regression protection for the error-to-HTTP-status mapping behavior.

go/node/take/v1/errors_test.go (1)

13-33: LGTM!

Consistent test structure with other error test files. Validates the ErrInvalidParamcodes.InvalidArgument mapping.

go/node/audit/v1/errors_test.go (1)

13-43: LGTM! Complete test coverage for audit/v1 errors.

All three errors defined in errors.go are covered with correct expected codes. The test structure is consistent with other modules in this PR.

go/node/escrow/module/error_test.go (1)

13-113: LGTM! Comprehensive test coverage for escrow module errors.

Excellent coverage of 16 error types across 5 different gRPC status codes (NotFound, AlreadyExists, InvalidArgument, FailedPrecondition, PermissionDenied). The test cases align with the production error definitions in error.go.

go/node/market/v1/errors_test.go (1)

1-198: Comprehensive test coverage for market error mappings.

The test correctly validates that all market module errors map to their intended gRPC status codes. The table-driven approach is clear and maintains consistency with error definitions in errors.go.

go/node/types/deposit/v1/errors_test.go (1)

1-38: Test coverage validated for deposit errors.

The test correctly verifies that deposit-related errors map to codes.InvalidArgument, aligning with the updated error registrations.

go/node/cert/v1/errors.go (2)

7-7: Import added for gRPC codes.

The addition of google.golang.org/grpc/codes is necessary for the RegisterWithGRPCCode calls.


28-52: gRPC status codes correctly assigned to certificate errors.

The error-to-code mappings are semantically appropriate:

  • NotFound for missing certificates
  • InvalidArgument for validation failures
  • AlreadyExists for duplicates
  • FailedPrecondition for revoked certificates

These changes will ensure certificate errors map to correct HTTP status codes (e.g., 404, 400, 409, 412) via gRPC-gateway.

go/node/provider/v1beta4/errors_test.go (1)

1-68: Provider error mappings validated.

The test ensures provider module errors correctly convert to gRPC status codes, with appropriate mappings for not found, already exists, invalid input, and precondition failures.

go/node/cert/v1/errors_test.go (1)

1-73: Certificate error test coverage is complete.

All certificate module errors are tested with correct gRPC code expectations, ensuring the changes in errors.go are properly validated.

go/node/types/deposit/v1/errors.go (2)

4-5: Imports updated for gRPC-aware error registration.

The addition of sdkerrors alias and grpc/codes enables explicit gRPC status code assignment.


17-19: Deposit errors correctly mapped to InvalidArgument.

Both ErrInvalidDepositor and ErrInvalidDepositSource appropriately map to codes.InvalidArgument, which will translate to HTTP 400 for invalid request parameters.

go/node/types/attributes/v1/attribute.go (2)

13-14: Imports added for gRPC code support.

The sdkerrors alias and grpc/codes import enable explicit gRPC status code registration.


30-31: Attribute validation errors correctly mapped.

Both attribute errors map to codes.InvalidArgument, which is appropriate for validation failures (duplicate keys, invalid key format). These will correctly translate to HTTP 400.

go/node/escrow/module/error.go (2)

4-5: Imports updated for gRPC-aware error handling.

The switch to sdkerrors and addition of grpc/codes enables explicit status code mapping for escrow module errors.


29-45: Escrow error mappings are semantically correct.

All 16 error registrations use appropriate gRPC codes:

  • NotFound for missing accounts/payments (→ HTTP 404)
  • AlreadyExists for duplicates (→ HTTP 409)
  • InvalidArgument for validation failures (→ HTTP 400)
  • FailedPrecondition for state violations (→ HTTP 412)
  • PermissionDenied for authorization failures (→ HTTP 403)

The use of PermissionDenied for ErrUnauthorizedDepositScope is particularly appropriate, as it distinguishes authorization failures from general validation errors.

go/node/market/v1/errors.go (3)

3-6: LGTM!

The import of google.golang.org/grpc/codes is correctly added to support the gRPC code mappings.


41-43: LGTM!

New error codes are correctly appended at the end of the iota sequence, preserving existing error code values for backward compatibility.


45-107: gRPC code mappings are semantically correct.

The mappings appropriately use:

  • codes.NotFound for missing resources (bids, leases, orders, providers)
  • codes.InvalidArgument for validation errors
  • codes.AlreadyExists for duplicate entries
  • codes.FailedPrecondition for state-related errors
  • codes.Internal for internal errors

This correctly addresses the PR objective of returning HTTP 404 for not-found scenarios instead of HTTP 500.

@vertex451 vertex451 changed the title Artem/fix/500 instead of 404 Replace sdkerrors.Register with sdkerrors.RegisterWithGRPCCode for the proper error propagation. Dec 29, 2025
@vertex451 vertex451 changed the title Replace sdkerrors.Register with sdkerrors.RegisterWithGRPCCode for the proper error propagation. fix: replaced sdkerrors.Register with sdkerrors.RegisterWithGRPCCode for the proper error propagation. Dec 29, 2025
@troian
Copy link
Member

troian commented Dec 29, 2025

this is consensus breaking change, will hold on merging for now

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Fix all issues with AI Agents 🤖
In @go/node/market/v1/errors.go:
- Line 77: The ErrGroupNotFound constant incorrectly registers the message
"order not found"; update the registration call for ErrGroupNotFound (using
sdkerrors.RegisterWithGRPCCode, errCodeGroupNotFound, and codes.NotFound) to use
the correct message "group not found" and, if present, update any surrounding
comment to match the "group" semantics so the name, message, and comment are
consistent.
- Line 63: ErrUnknownLeaseForBid is registered with errCodeUnknownLeaseForOrder
which mismatches the variable name and message; either add a new error code
constant named errCodeUnknownLeaseForBid and use it in
sdkerrors.RegisterWithGRPCCode for ErrUnknownLeaseForBid, or if the intent was
"order" rename ErrUnknownLeaseForBid to ErrUnknownLeaseForOrder (and update any
references) so the constant errCodeUnknownLeaseForOrder matches the error
variable and message.
🧹 Nitpick comments (1)
go/node/market/v1/errors.go (1)

112-112: Add comment for consistency with other error declarations.

All other error variables have a preceding comment line, but ErrInvalidEscrowID is declared inline. For consistency and better documentation, add a comment on a separate line.

🔎 Suggested fix
 	// ErrInvalidLeaseClosedReason indicates reason for lease close does not match context
 	ErrInvalidLeaseClosedReason = sdkerrors.RegisterWithGRPCCode(ModuleName, errInvalidLeaseClosedReason, codes.InvalidArgument, "invalid lease closed reason")
-	ErrInvalidEscrowID          = sdkerrors.RegisterWithGRPCCode(ModuleName, errInvalidEscrowID, codes.InvalidArgument, "invalid escrow id")
+	// ErrInvalidEscrowID indicates an invalid escrow identifier
+	ErrInvalidEscrowID = sdkerrors.RegisterWithGRPCCode(ModuleName, errInvalidEscrowID, codes.InvalidArgument, "invalid escrow id")
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9abd45d and 1e64f41.

📒 Files selected for processing (1)
  • go/node/market/v1/errors.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: coverage
  • GitHub Check: test
  • GitHub Check: go
🔇 Additional comments (2)
go/node/market/v1/errors.go (2)

5-5: LGTM! Import necessary for gRPC code constants.

The addition of google.golang.org/grpc/codes is required for the RegisterWithGRPCCode calls throughout the file.


47-112: LGTM! gRPC code mappings are semantically correct.

All error registrations use appropriate gRPC codes that align with gRPC best practices:

  • codes.InvalidArgument for validation and parameter errors
  • codes.NotFound for missing resources
  • codes.FailedPrecondition for state precondition failures
  • codes.AlreadyExists for duplicate resources
  • codes.Internal for internal errors

This ensures proper HTTP status code mapping via grpc-gateway (e.g., NotFound → HTTP 404 instead of HTTP 500).

@vertex451 vertex451 changed the title fix: replaced sdkerrors.Register with sdkerrors.RegisterWithGRPCCode for the proper error propagation. Fix: replaced sdkerrors.Register with sdkerrors.RegisterWithGRPCCode for the proper error propagation. Jan 5, 2026
@vertex451 vertex451 changed the title Fix: replaced sdkerrors.Register with sdkerrors.RegisterWithGRPCCode for the proper error propagation. fix!: replaced sdkerrors.Register with sdkerrors.RegisterWithGRPCCode for the proper error propagation. Jan 5, 2026
@vertex451 vertex451 force-pushed the artem/fix/500-instead-of-404 branch from 6f31ee3 to dac34e0 Compare January 6, 2026 14:49
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI Agents
In @go/node/market/v1/errors.go:
- Around line 78-79: The comment and error message for ErrGroupNotOpen are
inconsistent and reference "order" instead of "group": update the code where
ErrGroupNotOpen is registered (the sdkerrors.RegisterWithGRPCCode call that
defines ErrGroupNotOpen) so the inline comment reads something like
"ErrGroupNotOpen group not open" (or "group not open") and change the error
message string argument from "order not open" to "group not open" to match the
error name; ensure only the comment and the message string are changed, leaving
the registration call and GRPC code (codes.FailedPrecondition) intact.
🧹 Nitpick comments (2)
go/node/market/v1/errors.go (2)

80-81: Inconsistent message prefix in ErrOrderNotOpen.

The error message includes a "bid: " prefix ("bid: order not open") which is inconsistent with other error messages in the file. Most errors don't include such contextual prefixes in their base messages.

🔎 Suggested fix for consistency
-	// ErrOrderNotOpen order not found
-	ErrOrderNotOpen = sdkerrors.RegisterWithGRPCCode(ModuleName, errCodeOrderNotOpen, codes.FailedPrecondition, "bid: order not open")
+	// ErrOrderNotOpen order not open
+	ErrOrderNotOpen = sdkerrors.RegisterWithGRPCCode(ModuleName, errCodeOrderNotOpen, codes.FailedPrecondition, "order not open")

103-103: Inconsistent capitalization in error message.

The message "Deposit invalid" has a capital "D" which is inconsistent with other error messages in the file that use lowercase (e.g., "bid price is invalid", "parameter invalid").

🔎 Suggested fix for consistency
-	ErrInvalidDeposit = sdkerrors.RegisterWithGRPCCode(ModuleName, errInvalidDeposit, codes.InvalidArgument, "Deposit invalid")
+	ErrInvalidDeposit = sdkerrors.RegisterWithGRPCCode(ModuleName, errInvalidDeposit, codes.InvalidArgument, "deposit invalid")
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1e64f41 and dac34e0.

📒 Files selected for processing (1)
  • go/node/market/v1/errors.go
🧰 Additional context used
🧬 Code graph analysis (1)
go/node/market/v1/errors.go (1)
go/node/types/attributes/v1/attribute.go (1)
  • ModuleName (18-18)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: test
  • GitHub Check: coverage
  • GitHub Check: go
  • GitHub Check: proto
🔇 Additional comments (4)
go/node/market/v1/errors.go (4)

5-5: LGTM: gRPC codes import.

The addition of the google.golang.org/grpc/codes import is necessary and correct for the migration to RegisterWithGRPCCode.


16-16: Correctly adds missing constant.

The addition of errCodeUnknownLeaseForBid resolves the previous constant name mismatch where ErrUnknownLeaseForBid was incorrectly using errCodeUnknownLeaseForOrder.


47-77: LGTM: Error registrations with appropriate gRPC codes.

The error registrations correctly use RegisterWithGRPCCode with semantically appropriate gRPC codes:

  • codes.InvalidArgument for validation errors
  • codes.NotFound for missing entities
  • codes.Internal for internal errors
  • codes.FailedPrecondition for state-based errors

The previously flagged issues with ErrInvalidBid, ErrUnknownLeaseForBid, and ErrGroupNotFound have been successfully addressed.


83-112: LGTM: Remaining error registrations.

The remaining error registrations correctly use RegisterWithGRPCCode with appropriate gRPC codes:

  • codes.NotFound for missing entities
  • codes.InvalidArgument for validation errors
  • codes.FailedPrecondition for state-based errors
  • codes.AlreadyExists for duplicate entities

@vertex451 vertex451 force-pushed the artem/fix/500-instead-of-404 branch from dac34e0 to e57a675 Compare January 6, 2026 16:07
@troian troian merged commit 2dd736a into main Jan 6, 2026
7 checks passed
@troian troian deleted the artem/fix/500-instead-of-404 branch January 6, 2026 17:02
cloud-j-luna pushed a commit that referenced this pull request Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: API returns HTTP 500 instead of 404 for non-existent deployment

3 participants