slackhq / nebula

A scalable overlay networking tool with a focus on performance, simplicity and security

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

πŸ› BUG: ContextualError wrapped errors ironically drop error context

brad-defined opened this issue Β· comments

What version of nebula are you using?

1.8.2

What operating system are you using?

any

Describe the Bug

A program that wraps Nebula and calls nebula.Main() may receive an error return value missing essential context.

The error value returned is of type util.ContextualError.

ContextualErrors consist of different parts:

type ContextualError struct {
	RealError error
	Fields    map[string]interface{}
	Context   string
}

These are the underlying error (RealError), an error context (which is just an additional message string), and a dictionary of variables.

ContextualError defines Error() to only return the wrapped error, omitting the Context and Fields.

func (ce *ContextualError) Error() string {
	if ce.RealError == nil {
		return ce.Context
	}
	return ce.RealError.Error()
}

This means that when programs that invoke nebula.Main() get an error in return and logs it in a typical fashion, only the wrapped error is made available, while the extra context is hidden. This results in opaque error messages like "no such file or directory", as opposed to the more helpful full contextual error message "Failed to get a tun/tap device: no such file or directory".

Logs from affected hosts

No response

Config files from affected hosts

No response