kratos-ebz

module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 28, 2026 License: MIT

README ΒΆ

GitHub Workflow Status (branch) GoDoc Coverage Status Supported Go Versions GitHub Release Go Report Card

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.


πŸ’¬ Contact & Feedback

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:

  1. Fork: Fork the repo on GitHub (using the webpage UI).
  2. Clone: Clone the forked project (git clone https://github.com/yourname/repo-name.git).
  3. Navigate: Navigate to the cloned project (cd repo-name)
  4. Branch: Create a feature branch (git checkout -b feature/xxx).
  5. Code: Implement the changes with comprehensive tests
  6. Testing: (Golang project) Ensure tests pass (go test ./...) and follow Go code style conventions
  7. Documentation: Update documentation to support client-facing changes
  8. Stage: Stage changes (git add .)
  9. Commit: Commit changes (git commit -m "Add feature xxx") ensuring backward compatible code
  10. Push: Push to the branch (git push origin feature/xxx).
  11. 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

Stargazers

Directories ΒΆ

Path Synopsis
Package ebzkratos provides safe Kratos error wrapping without implementing error interface Addresses Go's nil interface challenge where (*T)(nil) != nil causes confusion CORE CONSTRAINT: ebz != nil β‡’ ebz.Erk must be non-nil (enforced via must.Full)
Package ebzkratos provides safe Kratos error wrapping without implementing error interface Addresses Go's nil interface challenge where (*T)(nil) != nil causes confusion CORE CONSTRAINT: ebz != nil β‡’ ebz.Erk must be non-nil (enforced via must.Full)
must/ebzmust
Package ebzmust provides assertion functions with panic and logging Used to enforce no-error convention in production code
Package ebzmust provides assertion functions with panic and logging Used to enforce no-error convention in production code

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL