HilkopterBob/PackageLock

BUG: cannot run without sudo

Closed this issue · 1 comments

If packagelock is ran without sudo, inside a directory that the execution user doesnt have permissions on, we get a very cryptic bug!
Stack Trace:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x793d7b]

goroutine 1 [running]:
go.uber.org/zap.(*Logger).clone(...)
	/home/nick/go/pkg/mod/go.uber.org/zap@v1.27.0/logger.go:318
go.uber.org/zap.(*Logger).Sugar(...)
	/home/nick/go/pkg/mod/go.uber.org/zap@v1.27.0/logger.go:147
packagelock/logger.InitLogger()
	/home/nick/Work/programming/Golang/packagelock/logger/logger.go:48 +0x1db
main.init.0()
	/home/nick/Work/programming/Golang/packagelock/main.go:219 +0x10a

This happens because an unhandled exception in

logger, err := loggerConfig.Build()
if err != nil {
// Handle logger initialization error (no panic)
logger = nil
}

because we store nil inside the logger and later try to run methods on a nil pointer