Skip to content

Providing an odd number of arguments to a pterm Logger's Args method results in a panic #628

@TylerGillson

Description

@TylerGillson

Program:

package main

import (
	"github.com/pterm/pterm"
)

func main() {
	l := pterm.DefaultLogger
	l.Info("message", l.Args("Hello", ", World!"))
	l.Info("message", l.Args("foo", "bar", "Hello", ", World!"))
	l.Info("message", l.Args(", World!"))
	l.Info("message", l.Args("foo", "bar", ", World!"))
	l.Info("message", l.Args("foo", "bar", "Hello", ", World!", "baz"))
}

Output:

❯ go run ~/Downloads/gotest/main.go
2024-02-01 12:17:38 INFO  message Hello: , World!
2024-02-01 12:17:38 INFO  message foo: bar Hello: , World!
panic: runtime error: index out of range [1] with length 1

goroutine 1 [running]:
github.com/pterm/pterm.Logger.Args({0x0, {0x1010a8608, 0x14000048018}, 0x3, 0x0, 0x0, 0x1, {0x101048ea3, 0x13}, 0x14000072990, ...}, ...)
        /Users/tylergillson/go/pkg/mod/github.com/pterm/pterm@v0.12.76/logger.go:216 +0x1c4
main.main()
        /Users/tylergillson/Downloads/gotest/main.go:11 +0x25c
exit status 2

Perhaps this could be handled more gracefully?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions