Replace errors package functions for error handling with multilingual support:
| Go Standard | fmt Equivalent |
|---|---|
errors.New() |
Err(message) |
fmt.Errorf() |
Errf(format, args...) |
fmt.Errorf("%w: %w", cause, sentinel) |
ErrType(cause, sentinel) |
// Multiple error messages and types
err := Err("invalid format", "expected number", 404)
// out: "invalid format expected number 404"
// Formatted errors (like fmt.Errorf)
err := Errf("invalid value: %s at position %d", "abc", 5)
// out: "invalid value: abc at position 5"For multilingual error messages using dictionary terms that can be translated into multiple languages, see the Translation Guide.
// Using dictionary terms for translatable errors
// Note: requires import _ "github.com/tinywasm/fmt/dictionary"
err := Err("format", "invalid")
// → "format invalid" (in English) or translated based on global language setting
// Force specific language
err := Err(ES, "format", "invalid")
// → "formato inválido"ErrType allows wrapping an error with a sentinel for identification while preserving the original error's message and identity.
var ErrNotFound = fmt.Err("not found")
func FindUser(id string) error {
err := db.Query(...) // returns database error
return fmt.ErrType(err, ErrNotFound)
}
// Consuming the error
err := FindUser("123")
if errors.Is(err, ErrNotFound) {
// Identity preserved
}
fmt.Print(err) // "db connection timeout: not found"