Skip to content

Add helper make_kind#51

Merged
jackalcooper merged 2 commits into
mainfrom
make-kind
Oct 20, 2025
Merged

Add helper make_kind#51
jackalcooper merged 2 commits into
mainfrom
make-kind

Conversation

@jackalcooper
Copy link
Copy Markdown
Contributor

@jackalcooper jackalcooper commented Oct 20, 2025

Summary by CodeRabbit

  • New Features

    • Added new resource creation method providing enhanced error handling and improved resource management capabilities.
  • Chores

    • Version bumped to 0.10.8-dev.
    • Build configuration formatting updates.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Oct 20, 2025

Walkthrough

The pull request updates the project version from "0.10.7-dev" to "0.10.8-dev", adds a new public method make_kind to wrap resource creation with kind and module context returning a tuple, and applies minor whitespace formatting to build.zig.

Changes

Cohort / File(s) Summary
Version Bump
mix.exs
Project version incremented from "0.10.7-dev" to "0.10.8-dev"
New Resource Creation Method
src/kinda.zig
Added public method make_kind on ResourceKind.resource that allocates a 3-element tuple containing the "kind" atom, module name, and result of resource.make(), with memory allocation and resource creation error handling
Formatting
build.zig
Minor whitespace adjustment around opening brace in conditional statement; no semantic or behavioral changes

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • Bump version 0.9.2-dev #28: Version bump in mix.exs file (same type of change to project version declaration)
  • 0.10.3-dev #44: Version bump targeting different version in mix.exs (parallel versioning change)
  • Upgrade to Zig 0.14 #41: Modifications to ResourceKind-related code in src/kinda.zig (affects same struct being extended here)

Poem

🐰✨ A version hops forward with gentle care,
New make_kind wraps resources fair,
Tuples bloom with context so bright,
Whitespace dances—formatting just right!
Small changes, big joy—we're building with flair! 🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Add helper make_kind" directly and clearly describes the main change in the pull request: the addition of a new public method make_kind to the ResourceKind.resource struct in src/kinda.zig. The title is concise, specific, and avoids vague terminology. While the PR also includes a version bump and a minor formatting change, the title correctly identifies the primary and most significant change. A teammate scanning the commit history would immediately understand that this PR introduces a new helper method for creating kind-aware resources.
✨ 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 make-kind

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.

Copy link
Copy Markdown

@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)
src/kinda.zig (1)

47-55: Consider extracting shared tuple-creation logic.

The implementation is correct with proper memory management and error handling. However, this code duplicates the tuple-creation pattern from wrap_ret_call (lines 306-316). Both functions allocate a 3-element slice and populate it with the same structure: {"kind", module_name, resource}.

Consider extracting the common logic into a private helper function to improve maintainability:

fn make_kind_tuple(env: beam.env, comptime mod_name: []const u8, resource_term: beam.term) !beam.term {
    var tuple_slice: []beam.term = beam.allocator.alloc(beam.term, 3) catch return beam.Error.@"Fail to allocate memory for tuple slice";
    defer beam.allocator.free(tuple_slice);
    tuple_slice[0] = beam.make_atom(env, "kind");
    tuple_slice[1] = beam.make_atom(env, mod_name);
    tuple_slice[2] = resource_term;
    return beam.make_tuple(env, tuple_slice);
}

Then refactor both functions:

 pub fn make_kind(env: beam.env, value: T) !beam.term {
-    var tuple_slice: []beam.term = beam.allocator.alloc(beam.term, 3) catch return beam.Error.@"Fail to allocate memory for tuple slice";
-    defer beam.allocator.free(tuple_slice);
-    tuple_slice[0] = beam.make_atom(env, "kind");
-    tuple_slice[1] = beam.make_atom(env, module_name);
     const ret = resource.make(env, value) catch return beam.Error.@"Fail to make resource for return type";
-    tuple_slice[2] = ret;
-    return beam.make_tuple(env, tuple_slice);
+    return make_kind_tuple(env, module_name, ret);
 }

And similarly for wrap_ret_call at line 313.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3227cf3 and 6be4a89.

📒 Files selected for processing (3)
  • build.zig (1 hunks)
  • mix.exs (1 hunks)
  • src/kinda.zig (1 hunks)
⏰ 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: otp25.0-ex1.18.0 / ubuntu-22.04
  • GitHub Check: otp24.2-ex1.16.2 / ubuntu-22.04
  • GitHub Check: otp25.0-ex1.13.0 / ubuntu-22.04
🔇 Additional comments (2)
mix.exs (1)

7-7: LGTM!

The version bump is appropriate for adding the new make_kind helper function.

build.zig (1)

9-9: LGTM!

Minor formatting adjustment with no semantic impact.

@jackalcooper jackalcooper merged commit 3b35d77 into main Oct 20, 2025
5 checks passed
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.

1 participant