Refactor error handing and logging
Open
Nobody has claimed this yet.
jira
- Dominant language
- Go
- Stars
- 974
- Forks
- 296
- Avg merge
- 6d 14h
- Merged PRs (30d)
- 9
Description
Bug
Ignition Version
2.0.0+
Summary
Ignition currently doesn't have any guidelines for how to report errors or when/how to log things. The only guiding principle is "if something fails, fail hard".
Some questions to answer:
- When do we wrap errors like:
if err := someFunc(foo); err != nil {
return fmt.Errorf("error someFunc-ing on %s: %v", foo.String(), err)
}
- When do we log? If we have functions
A, B, C, Dwhich all call each other likeA(B(C(D())))do we log at all levels? Is it context dependent? - How do we determine what level to log at? Ignition currently has
Emergency,Alert,Critical,Error,Warning,Notice,Info, andDebug. Do we need that many? This was mostly inherited from https://golang.org/pkg/log/syslog/.
Proposals:
- Always wrap errors unless we have a strong reason not to. Consider using something like https://github.com/hashicorp/errwrap or https://godoc.org/github.com/pkg/errors to ensure a common structure.
- Drop
Emergency,Alert,CriticalandNotice, from the logger interface. I don't see a distinction between the first 3 andErrororNoticeandInfo. That leaves us with justError,Warning,Info, andDebug. - Only use
Errorfor things that are fatal (which are most things, given the fail hard philosophy). UseWarningfor things that seem wrong,Infofor general logging andDebugfor things that would only seem useful to Ignition developers. - Use the
logger.PushPrefixandlogger.PopPrefixmore. - Log actions that are long running (e.g. fetching resources over network), modify the system (i.e. writing a file), are significant events (e.g. subsections of stages starting/ending), or errors at the top level where they are handled (assuming we wrap them so they still have context).
- Debug logging can break these rules and be inserted wherever useful.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no files or tests; start by tracing the logger interface, PushPrefix/PopPrefix, and representative error paths across the Go codebase. Define the error-wrapping, logging-level, and top-level logging rules, then update the affected implementation and verify that the resulting behavior follows them.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli, tooling
- Issue type
- Refactor
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 18/100