gofiber/fiber · error · ErrTagInvalid
logger: tag name and function are required
Error message
logger: tag name and function are required
What it means
Returned by logger.RegisterTag (tags.go:57, 72) when either the tag name is an empty string or the renderer function (LogFunc) is nil. Both are required for a tag to be usable in format templates. MustRegisterTag panics with the same error. Since registered tags are global and shared across logger instances, an invalid registration would break template compilation for every logger that references the tag.
Source
Thrown at middleware/logger/tags.go:57
TagRespHeader = "respHeader:"
TagLocals = "locals:"
TagQuery = "query:"
TagForm = "form:"
TagCookie = "cookie:"
TagBlack = "black"
TagRed = "red"
TagGreen = "green"
TagYellow = "yellow"
TagBlue = "blue"
TagMagenta = "magenta"
TagCyan = "cyan"
TagWhite = "white"
TagReset = "reset"
)
// ErrTagInvalid is returned by RegisterTag and panicked from MustRegisterTag
// when the supplied tag name or renderer is empty.
var ErrTagInvalid = errors.New("logger: tag name and function are required")
var registeredTags = struct {
m map[string]LogFunc
sync.RWMutex
}{
m: make(map[string]LogFunc),
}
// RegisterTag registers a global logger middleware tag.
// Registered tags are available to logger middleware instances created after
// registration and can be overridden per instance with Config.CustomTags.
// Re-registering a tag replaces the existing tag function.
func RegisterTag(tag string, fn LogFunc) error {
if tag == "" || fn == nil {
return ErrTagInvalid
}
registeredTags.Lock()View on GitHub (pinned to 9a4c7e57fe)
Solutions
- Validate that both the tag name and function are non-empty/non-nil before calling RegisterTag.
- If registering from config, skip or log a warning when either value is missing instead of calling RegisterTag.
Example fix
// before
logger.RegisterTag(tagName, tagFn) // tagName or tagFn may be empty
// after
if tagName != "" && tagFn != nil {
logger.RegisterTag(tagName, tagFn)
} Defensive patterns
Strategy: validation
Validate before calling
// Guard registration against empty inputs
if tagName != "" && tagFn != nil {
if err := logger.RegisterTag(tagName, tagFn); err != nil {
log.Printf("failed to register tag %q: %v", tagName, err)
}
} Prevention
- Always check both name and function are non-empty/non-nil before RegisterTag.
- When loading tags from config, validate and skip incomplete entries.
- Unit test tag registration paths with empty/nil inputs.
When it happens
Trigger: Calling logger.RegisterTag("", fn) or logger.RegisterTag("mytag", nil); passing an empty name or nil function from dynamic code (e.g. reading tag definitions from config); a conditional that leaves fn nil.
Common situations: Programmatic tag registration where the name comes from external config that might be empty; refactoring that accidentally passes nil for the function; conditional registration logic that doesn't guard against empty inputs.
Related errors
- logger: unknown template tag
- proxy: upstream host is empty or invalid
- log: context tag name and function are required
- remote address cannot be empty
- decode SHA256 password: invalid length
AI-assisted analysis of gofiber/fiber@9a4c7e57fe (2026-08-04).
Data as JSON: /data/errors/c560762fbe6ba70a.json.
Report an issue: GitHub.