
kratos-ebz
Go error wrapper for Kratos framework that solves nil interface problems.
CHINESE README
δΈζθ―΄ζ
Main Features
π― Safe Error Wrapping: Avoids Go's (*T)(nil) != nil problem by not implementing error interface
π Type Conversion: Safe conversion between generic errors and Ebz instances with correct nil handling
π Comprehensive API: NewEbz, New, As, Is, FromError, From functions providing complete error handling
Installation
go get github.com/yylego/kratos-ebz/ebzkratos
Usage
Basic Error Wrapping
package main
import (
"github.com/go-kratos/kratos/v3/errors"
"github.com/yylego/kratos-ebz/ebzkratos"
)
func main() {
// Create Kratos error
erk := errors.BadRequest("INVALID_PARAM", "invalid param")
// Wrap with Ebz - safe from nil interface issues
ebz := ebzkratos.New(erk)
// Safe nil checking - no (*T)(nil) != nil problems
if ebz != nil {
// Process error content in safe mode
println("Error:", ebz.Erk.Message)
}
}
Type Conversion
func processError(err error) {
// Convert generic error to Ebz
if ebz, ok := ebzkratos.As(err); ok {
// Handle as Kratos error through Ebz wrapper
println("Kratos error:", ebz.Erk.Reason)
}
// Alternative conversion
ebz := ebzkratos.From(err)
if ebz != nil {
println("Converted:", ebz.Erk.Message)
}
}
Error Comparison
func compareErrors(ebz1, ebz2 *ebzkratos.Ebz) {
// Check errors equivalence with nil handling
if ebzkratos.Is(ebz1, ebz2) {
println("Errors are same type")
}
}
Production Assertions
import "github.com/yylego/kratos-ebz/ebzkratos/must/ebzmust"
func criticalOperation() {
result, ebz := someOperation()
// Assert no error - panic if ebz is not nil
ebzmust.Done(ebz)
// Continue with result in safe mode
processResult(result)
}
Core Constraint
STRUCTURAL INVARIANT: ebz != nil β ebz.Erk must be non-nil
This constraint is enforced via must.Full validation in constructors, ensuring:
- No ambiguous intermediate states
- Simplified error handling logic
- Fail-fast error detection
- Elimination of nil interface complications
API Reference
Creation Functions
NewEbz(erk *errors.Error) *Ebz - Creates error wrapper instance with validation
New(erk *errors.Error) *Ebz - Concise creation alias
Conversion Functions
As(err error) (*Ebz, bool) - Type conversion from generic error to Ebz
FromError(err error) *Ebz - Transforms generic error into safe Ebz instance
From(err error) *Ebz - Concise alias of FromError
Comparison Functions
Is(ebz1, ebz2 *Ebz) bool - Checks if two Ebz values are equivalent
Assert Functions
ebzmust.Done(ebz *Ebz) - Checks no-error convention with panic when violated
ebzmust.Must(ebz *Ebz) - Demands perfect execution with fail-fast termination
π License
MIT License - see LICENSE.
Contributions are welcome! Report bugs, suggest features, and contribute code:
- π Mistake reports? Open an issue on GitHub with reproduction steps
- π‘ Fresh ideas? Create an issue to discuss
- π Documentation confusing? Report it so we can improve
- π Need new features? Share the use cases to help us understand requirements
- β‘ Performance issue? Help us optimize through reporting slow operations
- π§ Configuration problem? Ask questions about complex setups
- π’ Follow project progress? Watch the repo to get new releases and features
- π Success stories? Share how this package improved the workflow
- π¬ Feedback? We welcome suggestions and comments
π§ Development
New code contributions, follow this process:
- Fork: Fork the repo on GitHub (using the webpage UI).
- Clone: Clone the forked project (
git clone https://github.com/yourname/repo-name.git).
- Navigate: Navigate to the cloned project (
cd repo-name)
- Branch: Create a feature branch (
git checkout -b feature/xxx).
- Code: Implement the changes with comprehensive tests
- Testing: (Golang project) Ensure tests pass (
go test ./...) and follow Go code style conventions
- Documentation: Update documentation to support client-facing changes
- Stage: Stage changes (
git add .)
- Commit: Commit changes (
git commit -m "Add feature xxx") ensuring backward compatible code
- Push: Push to the branch (
git push origin feature/xxx).
- PR: Open a merge request on GitHub (on the GitHub webpage) with detailed description.
Please ensure tests pass and include relevant documentation updates.
π Support
Welcome to contribute to this project via submitting merge requests and reporting issues.
Project Support:
- β Give GitHub stars if this project helps you
- π€ Share with teammates and (golang) programming friends
- π Write tech blogs about development tools and workflows - we provide content writing support
- π Join the ecosystem - committed to supporting open source and the (golang) development scene
Have Fun Coding with this package! πππ
GitHub Stars
