Skip to content

Conversation

@ChrisBQu
Copy link
Collaborator

@ChrisBQu ChrisBQu commented Aug 25, 2025

Relevant issue(s)

Resolves #3965

Description

There were many portions of the c binding code base where a pointer (CGO handle) to a node, transaction, or identity CGO handle was passed in, and assumed valid without any error checking. This would result in a panic and crash if the node were actually invalid. While there is always the chance of the user passing in an invalid handle, it needs to be handled gracefully, which is what now happens. The functions will now return the error as part of the Result object, and return the error message to the user to help indicate what happened.

Tasks

  • I made sure the code is well commented, particularly hard-to-understand areas.
  • I made sure the repository-held documentation is changed accordingly.
  • I made sure the pull request title adheres to the conventional commit style (the subset used in the project can be found in tools/configs/chglog/config.yml).
  • I made sure to discuss its limitations such as threats to validity, vulnerability to mistake and misuse, robustness to invalidation of assumptions, resource requirements, ...

How has this been tested?

Specify the platform(s) on which this was tested:

  • WSL

@ChrisBQu ChrisBQu added this to the DefraDB v0.20 milestone Aug 25, 2025
@ChrisBQu ChrisBQu self-assigned this Aug 25, 2025
@ChrisBQu ChrisBQu added the code quality Related to improving code quality label Aug 25, 2025
@codecov
Copy link

codecov bot commented Aug 25, 2025

Codecov Report

❌ Patch coverage is 29.23729% with 167 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.00%. Comparing base (7344e2f) to head (979f856).
⚠️ Report is 1 commits behind head on develop.

Files with missing lines Patch % Lines
cbindings/p2p.go 33.93% 26 Missing and 11 partials ⚠️
cbindings/cutils.go 40.91% 20 Missing and 6 partials ⚠️
cbindings/collection.go 24.24% 18 Missing and 7 partials ⚠️
cbindings/acp.go 25.00% 16 Missing and 8 partials ⚠️
cbindings/lens.go 12.50% 20 Missing and 1 partial ⚠️
cbindings/index.go 25.00% 6 Missing and 3 partials ⚠️
cbindings/node.go 22.22% 6 Missing and 1 partial ⚠️
cbindings/view.go 33.33% 4 Missing and 2 partials ⚠️
cbindings/block.go 25.00% 2 Missing and 1 partial ⚠️
cbindings/identity.go 25.00% 2 Missing and 1 partial ⚠️
... and 2 more
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3966      +/-   ##
===========================================
- Coverage    74.21%   74.00%   -0.21%     
===========================================
  Files          476      476              
  Lines        43531    43675     +144     
===========================================
+ Hits         32304    32321      +17     
- Misses        9066     9155      +89     
- Partials      2161     2199      +38     
Flag Coverage Δ
all-tests 74.00% <29.24%> (-0.21%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
cbindings/block.go 71.43% <25.00%> (-11.90%) ⬇️
cbindings/identity.go 26.92% <25.00%> (-3.51%) ⬇️
cbindings/query.go 81.25% <40.00%> (-3.75%) ⬇️
cbindings/schema.go 62.50% <25.00%> (-14.42%) ⬇️
cbindings/view.go 52.00% <33.33%> (-7.09%) ⬇️
cbindings/node.go 4.40% <22.22%> (-1.29%) ⬇️
cbindings/index.go 60.71% <25.00%> (-7.71%) ⬇️
cbindings/lens.go 14.71% <12.50%> (-1.57%) ⬇️
cbindings/acp.go 67.12% <25.00%> (-13.20%) ⬇️
cbindings/collection.go 50.66% <24.24%> (-4.37%) ⬇️
... and 2 more

... and 10 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7344e2f...979f856. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ChrisBQu ChrisBQu marked this pull request as ready for review August 25, 2025 17:05
@ChrisBQu ChrisBQu requested a review from a team August 25, 2025 18:17
Copy link
Contributor

@AndrewSisley AndrewSisley left a comment

Choose a reason for hiding this comment

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

LGTM, just a couple of small comments.

question: Was this broken out of a main C binding refactor, or did you discover that this was entirely responsible for the problems found and you chose to go with this instead of a more comprehensive refactor?

errInvalidLensConfig string = "invalid lens configuration: %v"
errMarshallingJSON string = "error marshalling JSON: %v"
errInvalidKeyType string = "invalid key type: %v"
errInvalidStorePointer string = "invalid store pointer: %v"
Copy link
Contributor

Choose a reason for hiding this comment

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

todo: These should really be following the same error pattern that we use everywhere else in our code base.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For everyone's context: Andy and I discussed this issue a bit through direct message. This change will happen, but it will happen through a separate PR/issue.

@ChrisBQu ChrisBQu merged commit 6077f0f into sourcenetwork:develop Aug 26, 2025
85 of 89 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Related to improving code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create safety checks in C bindings

2 participants