Skip to content

Harden Tabby transaction persistence failures#314

Open
nikkkkj wants to merge 1 commit into
BAWES-Universe:mainfrom
nikkkkj:codex/harden-tabby-transaction-persistence
Open

Harden Tabby transaction persistence failures#314
nikkkkj wants to merge 1 commit into
BAWES-Universe:mainfrom
nikkkkj:codex/harden-tabby-transaction-persistence

Conversation

@nikkkkj
Copy link
Copy Markdown

@nikkkkj nikkkkj commented May 17, 2026

Summary\n- remove raw print_r/die handling when Tabby transactions fail to save\n- keep structured Tabby error logging and raise Yii exceptions instead\n- avoid leaking model validation errors to payment callback callers\n\n/claim #59\n\n## Validation\n- git diff --check\n- php -l common/models/Tabby.php could not run because php is not installed in this environment

Summary by CodeRabbit

  • Bug Fixes
    • Improved error handling for transaction operations. The system now properly propagates errors through exceptions instead of halting with debug output, enabling more graceful error handling and better application stability.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 17, 2026

📝 Walkthrough

Walkthrough

The Tabby model replaces debug-output-based error handling with exception throwing in addTransaction() and updateTransaction() methods. When TabbyTransaction::save() fails, both methods now throw yii\base\Exception instead of echoing debug details and terminating execution.

Changes

Transaction Error Handling Refactor

Layer / File(s) Summary
Exception-based error handling for transaction methods
common/models/Tabby.php
addTransaction() and updateTransaction() methods replace debug output and die calls with thrown yii\base\Exception when TabbyTransaction::save() fails. File structure adjusted accordingly.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

A rabbit hops through error paths,
No more debug's messy baths,
Exceptions thrown so clean and bright,
Tabby transactions now get it right,
🐰 throws not dies—what a sight!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly aligns with the main change: replacing raw error output with proper exception handling in Tabby transaction persistence, which is a hardening measure for error handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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: 1

🧹 Nitpick comments (1)
common/models/Tabby.php (1)

90-93: ⚡ Quick win

Consider using a more specific exception type.

While \yii\base\Exception works, Yii2 provides more specific exception types for database operations. Consider using yii\db\Exception or creating a custom exception class for Tabby-specific failures. This improves error handling granularity and makes it easier for callers to distinguish between different failure types.

♻️ Suggested improvement
 if (!$tt->save()) {
     TabbyTransaction::ddlog('error', 'addTransaction', null, $tt->errors);
-    throw new \yii\base\Exception('Unable to persist Tabby transaction.');
+    throw new \yii\db\Exception('Unable to persist Tabby transaction.');
 }
🤖 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 `@common/models/Tabby.php` around lines 90 - 93, The current catch when
$tt->save() fails throws a generic \yii\base\Exception; change this to throw a
more specific exception (either yii\db\Exception or a custom Tabby-specific
exception class like TabbyException) so callers can distinguish DB failures;
update the throw in the failure block where TabbyTransaction::ddlog('error',
'addTransaction', null, $tt->errors) is called to instantiate and throw the
chosen specific exception and, if creating a custom class, add it to the
common\models namespace and use it here.
🤖 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 `@common/models/Tabby.php`:
- Around line 131-134: The log context is incorrect: inside updateTransaction()
the TabbyTransaction::ddlog call uses the string 'addTransaction' which is a
copy-paste error; update the ddlog invocation in updateTransaction() to use the
correct context string (e.g., 'updateTransaction') so logs reflect the right
method, and while here consider throwing a more specific exception class instead
of \yii\base\Exception (for example \RuntimeException or your domain-specific
exception) to keep error handling consistent.

---

Nitpick comments:
In `@common/models/Tabby.php`:
- Around line 90-93: The current catch when $tt->save() fails throws a generic
\yii\base\Exception; change this to throw a more specific exception (either
yii\db\Exception or a custom Tabby-specific exception class like TabbyException)
so callers can distinguish DB failures; update the throw in the failure block
where TabbyTransaction::ddlog('error', 'addTransaction', null, $tt->errors) is
called to instantiate and throw the chosen specific exception and, if creating a
custom class, add it to the common\models namespace and use it here.
🪄 Autofix (Beta)

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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9bc17ebf-00a7-4aa7-a2c5-a60d2bfa18eb

📥 Commits

Reviewing files that changed from the base of the PR and between bc485b0 and 95863b9.

📒 Files selected for processing (1)
  • common/models/Tabby.php

Comment thread common/models/Tabby.php
Comment on lines 131 to 134
if (!$tt->save()) {
TabbyTransaction::ddlog('error', 'addTransaction', null, $tt->errors);
echo "<pre />";
print_r($tt->errors);
die();
throw new \yii\base\Exception('Unable to update Tabby transaction.');
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix copy-paste error in log context.

The ddlog call on line 132 uses 'addTransaction' as the context, but this code is inside the updateTransaction() method. This inconsistency will make log analysis and debugging more difficult.

🐛 Proposed fix
 if (!$tt->save()) {
-    TabbyTransaction::ddlog('error', 'addTransaction', null, $tt->errors);
+    TabbyTransaction::ddlog('error', 'updateTransaction', null, $tt->errors);
     throw new \yii\base\Exception('Unable to update Tabby transaction.');
 }

Additionally, consider using a more specific exception type for consistency:

 if (!$tt->save()) {
     TabbyTransaction::ddlog('error', 'updateTransaction', null, $tt->errors);
-    throw new \yii\base\Exception('Unable to update Tabby transaction.');
+    throw new \yii\db\Exception('Unable to update Tabby transaction.');
 }
📝 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
if (!$tt->save()) {
TabbyTransaction::ddlog('error', 'addTransaction', null, $tt->errors);
echo "<pre />";
print_r($tt->errors);
die();
throw new \yii\base\Exception('Unable to update Tabby transaction.');
}
if (!$tt->save()) {
TabbyTransaction::ddlog('error', 'updateTransaction', null, $tt->errors);
throw new \yii\base\Exception('Unable to update Tabby transaction.');
}
🤖 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 `@common/models/Tabby.php` around lines 131 - 134, The log context is
incorrect: inside updateTransaction() the TabbyTransaction::ddlog call uses the
string 'addTransaction' which is a copy-paste error; update the ddlog invocation
in updateTransaction() to use the correct context string (e.g.,
'updateTransaction') so logs reflect the right method, and while here consider
throwing a more specific exception class instead of \yii\base\Exception (for
example \RuntimeException or your domain-specific exception) to keep error
handling consistent.

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.

2 participants