fix: [#762] handle panic when using transaction#1184
Conversation
There was a problem hiding this comment.
Pull Request Overview
This pull request improves transaction reliability by adding panic handling to prevent partial database writes and ensure proper cleanup when transactions fail unexpectedly.
- Added panic recovery in the
Transactionmethod to catch panics, rollback transactions, and return formatted errors - Enhanced testing with a new test case that verifies panic handling behavior during transactions
- Incremented package version to reflect these reliability improvements
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| support/constant.go | Version bump from v1.15.11 to v1.15.12 |
| database/orm/orm_test.go | Added fmt import and TestTransactionPanic test case |
| database/orm/orm.go | Added errors import and panic recovery logic in Transaction method |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.50.
| Benchmark suite | Current: 0ce89d5 | Previous: 4cd93b0 | Ratio |
|---|---|---|---|
Benchmark_DecryptString |
6606 ns/op 2040 B/op 17 allocs/op |
2170 ns/op 2032 B/op 16 allocs/op |
3.04 |
Benchmark_DecryptString - ns/op |
6606 ns/op |
2170 ns/op |
3.04 |
Benchmark_Debug |
175073 ns/op 47977 B/op 661 allocs/op |
115588 ns/op 29160 B/op 529 allocs/op |
1.51 |
Benchmark_Debug - ns/op |
175073 ns/op |
115588 ns/op |
1.51 |
Benchmark_Debug - B/op |
47977 B/op |
29160 B/op |
1.65 |
Benchmark_Info |
175210 ns/op 48057 B/op 659 allocs/op |
115865 ns/op 29053 B/op 527 allocs/op |
1.51 |
Benchmark_Info - ns/op |
175210 ns/op |
115865 ns/op |
1.51 |
Benchmark_Info - B/op |
48057 B/op |
29053 B/op |
1.65 |
Benchmark_Warning |
190112 ns/op 50022 B/op 691 allocs/op |
120574 ns/op 29875 B/op 537 allocs/op |
1.58 |
Benchmark_Warning - ns/op |
190112 ns/op |
120574 ns/op |
1.58 |
Benchmark_Warning - B/op |
50022 B/op |
29875 B/op |
1.67 |
This comment was automatically generated by workflow using github-action-benchmark.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## v1.15.x #1184 +/- ##
==========================================
Coverage ? 68.68%
==========================================
Files ? 219
Lines ? 18968
Branches ? 0
==========================================
Hits ? 13029
Misses ? 5261
Partials ? 678 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
📑 Description
Closes goravel/goravel#762
This pull request improves the reliability of transaction handling in the ORM package by ensuring that panics within transactions are properly caught and handled, preventing partial data writes and making error reporting more robust. Additionally, a new test is added to verify this behavior, and the package version is incremented.
Transaction reliability improvements:
Transactionmethod inorm.goto catch panics, roll back the transaction, and return a formatted error, ensuring that panics do not leave the database in an inconsistent state.errorspackage inorm.goto support error joining for rollback failures during panic handling.Testing enhancements:
TestTransactionPanicinorm_test.goto verify that panics during a transaction are handled correctly, the transaction is rolled back, and no data is written.fmtpackage inorm_test.goto support formatted error comparisons in tests.Version update:
support/constant.gofromv1.15.11tov1.15.12to reflect these improvements.✅ Checks