Skip to content

improve lua error handling - #16

Open
D-Berg wants to merge 1 commit into
stack/tkuvrtxrwllmfrom
stack/nwwpluypooqz
Open

improve lua error handling#16
D-Berg wants to merge 1 commit into
stack/tkuvrtxrwllmfrom
stack/nwwpluypooqz

Conversation

@D-Berg

@D-Berg D-Berg commented Aug 7, 2026

Copy link
Copy Markdown
Owner

All native zig functions are wrapped by a lua helper.
Avoids calling assert in manifests and avoids calling lua_Lerror which
makes defers not work.

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling across build, dependency, installation, and information commands so setup and native-operation failures are reported instead of being silently ignored.
    • Environment-related helper failures now return consistent nil results.
    • Corrected command argument error wording for clearer feedback.
  • Reliability

    • Lua-integrated operations now propagate failures more consistently and clean up temporary context safely.

All native zig functions are wrapped by a lua helper. 
Avoids calling assert in manifests and avoids calling lua_Lerror which
makes defers not work.
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8947bf58-daad-461d-8b17-e5469e36e7fc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/actions/build_package.zig`:
- Line 390: Update the error message in the Lua argument-validation logic to use
the correctly spaced phrase “at least” instead of “atleast,” preserving the rest
of the message unchanged.

In `@src/error_wrapper.lua`:
- Around line 5-9: Update the outer wrapper setup in the returned function
around native so it captures the current global error function in a local before
creating and returning the inner wrapper. Use that captured function in the
failure branch of the inner wrapper instead of resolving global error at call
time, while preserving the existing level argument and return behavior.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 209690a2-cedc-45e1-a824-75407a933356

📥 Commits

Reviewing files that changed from the base of the PR and between 33e4b40 and 188508c.

📒 Files selected for processing (5)
  • src/actions/build_package.zig
  • src/actions/info.zig
  • src/actions/install.zig
  • src/error_wrapper.lua
  • src/lua_helpers.zig

if (n_args < 1) {
lua.pushNil();
_ = lua.pushLString("run requires atleast 1 arg");
_ = lua.pushLString("run requires atleast 1 argument");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Correct the error text.

Change "atleast" to "at least".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/actions/build_package.zig` at line 390, Update the error message in the
Lua argument-validation logic to use the correctly spaced phrase “at least”
instead of “atleast,” preserving the rest of the message unchanged.

Comment thread src/error_wrapper.lua
Comment on lines +5 to +9
return function(native)
return function(...)
local value, failure = native(...)
if failure ~= nil then
error(failure, 2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Capture the Lua error function during wrapper setup.

A manifest can replace global error before a checked native function fails. The wrapper can then return normally after a failed native call. Capture error in a local before returning the wrapper.

Proposed fix
+local lua_error = error
+
 return function(native)
     return function(...)
         local value, failure = native(...)
         if failure ~= nil then
-            error(failure, 2)
+            lua_error(failure, 2)
         end
📝 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
return function(native)
return function(...)
local value, failure = native(...)
if failure ~= nil then
error(failure, 2)
local lua_error = error
return function(native)
return function(...)
local value, failure = native(...)
if failure ~= nil then
lua_error(failure, 2)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/error_wrapper.lua` around lines 5 - 9, Update the outer wrapper setup in
the returned function around native so it captures the current global error
function in a local before creating and returning the inner wrapper. Use that
captured function in the failure branch of the inner wrapper instead of
resolving global error at call time, while preserving the existing level
argument and return behavior.

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