Skip to content

Conversation

@vertex451
Copy link

@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). Minor message formatting or consolidation in some declarations.
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
New table-driven tests per package that call status.FromError(...) and assert the resulting gRPC status code matches the expected code for each exported module error using require.

Sequence Diagram(s)

(omitted)

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • troian
  • stalniy

Poem

🐇 I hopped through code with eager paws,

Gave errors codes and ironed out the laws.
NotFound, Invalid, AlreadyExists too—
Now status replies match what they should do.
A carrot for tests that all turn true!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes changes beyond the stated objective. While the PR title and initial objective focus on the deployment module, the changeset applies the same gRPC code registration pattern to audit, cert, escrow, market, provider, take, and types modules—changes the author questioned whether they should include. Clarify if these additional module changes are intentional and required for issue #404, or if they should be separated into a follow-up PR to maintain focused scope.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description is comprehensive and covers the problem, solution, testing approach, and raises a valid question about scope. It includes proper context about the bug and proof of fix.
Linked Issues check ✅ Passed The PR implements the fix required by issue #404: ensuring HTTP 404 is returned instead of HTTP 500 for non-existent deployments by using RegisterWithGRPCCode to preserve gRPC error codes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title accurately describes the main change: replacing sdkerrors.Register with sdkerrors.RegisterWithGRPCCode throughout the codebase to fix error propagation and HTTP status codes.
✨ 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

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
ErrInvalidDeployment = cerrors.RegisterWithGRPCCode(ModuleName, errInvalidDeployment, codes.InvalidArgument, "Invalid deployment")
// ErrInvalidGroupID is the error when already deployment exists
ErrInvalidGroupID = cerrors.Register(ModuleName, errInvalidGroupID, "Deployment exists")
ErrInvalidGroupID = cerrors.RegisterWithGRPCCode(ModuleName, errInvalidGroupID, codes.InvalidArgument, "Deployment exists")
Copy link
Author

Choose a reason for hiding this comment

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

I am not sure about this error mapping - it can be both codes.InvalidArgument and codes.AlreadyExists.

@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).

ErrUnknownLease = sdkerrors.RegisterWithGRPCCode(ModuleName, errCodeUnknownLease, codes.NotFound, "unknown lease")
// ErrUnknownLeaseForBid is the error when lease is unknown for bid
ErrUnknownLeaseForBid = sdkerrors.Register(ModuleName, errCodeUnknownLeaseForOrder, "unknown lease for bid")
ErrUnknownLeaseForBid = sdkerrors.RegisterWithGRPCCode(ModuleName, errCodeUnknownLeaseForOrder, codes.NotFound, "unknown lease for bid")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check all errCodeUnknownLease constants and their usage patterns
rg -n "errCodeUnknownLease" --type=go -C 3

Repository: akash-network/chain-sdk

Length of output: 1574


🏁 Script executed:

#!/bin/bash
# Check the entire file structure and search for any bid-related lease constants
cat -n go/node/market/v1/errors.go | head -30
# Also check if errCodeUnknownLeaseForBid is mentioned anywhere
rg -n "errCodeUnknownLeaseForBid" --type=go
# And check if errCodeUnknownLeaseForOrder is used elsewhere
rg -n "errCodeUnknownLeaseForOrder" --type=go

Repository: akash-network/chain-sdk

Length of output: 1094


Constant name mismatch: ErrUnknownLeaseForBid uses errCodeUnknownLeaseForOrder.

The error variable refers to "bid" while the constant refers to "order". Either create a new constant errCodeUnknownLeaseForBid to match the variable and message, or review if the wrong constant was used.

🤖 Prompt for AI Agents
In @go/node/market/v1/errors.go around 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.

ErrOrderNotFound = sdkerrors.RegisterWithGRPCCode(ModuleName, errCodeOrderNotFound, codes.NotFound, "invalid order: order not found")
// ErrGroupNotFound order not found
ErrGroupNotFound = sdkerrors.Register(ModuleName, errCodeGroupNotFound, "order not found")
ErrGroupNotFound = sdkerrors.RegisterWithGRPCCode(ModuleName, errCodeGroupNotFound, codes.NotFound, "order not found")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Error message and comment don't match the error name.

ErrGroupNotFound has a comment and message stating "order not found", which is inconsistent with the error name that refers to a "group".

🔎 Suggested fix
-	// ErrGroupNotFound order not found
-	ErrGroupNotFound = sdkerrors.RegisterWithGRPCCode(ModuleName, errCodeGroupNotFound, codes.NotFound, "order not found")
+	// ErrGroupNotFound group not found
+	ErrGroupNotFound = sdkerrors.RegisterWithGRPCCode(ModuleName, errCodeGroupNotFound, codes.NotFound, "group not found")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ErrGroupNotFound = sdkerrors.RegisterWithGRPCCode(ModuleName, errCodeGroupNotFound, codes.NotFound, "order not found")
// ErrGroupNotFound group not found
ErrGroupNotFound = sdkerrors.RegisterWithGRPCCode(ModuleName, errCodeGroupNotFound, codes.NotFound, "group not found")
🤖 Prompt for AI Agents
In @go/node/market/v1/errors.go around 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.

@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
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

4 participants