charmbracelet / charmbracelet/log

Error logging with Oops: \t not printed correctly

Open
#144 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
3.4k
Forks
103
PR merge metrics
No merged PRs in 30d

Description

**Describe the bug**
I am trying to use the oops library to do "pretty error logging", basically. The wrapped error (`oops.Wrap(err)`) is displayed abnormally because certain sequences (`\t` and `\r`) are not printed as expected.

**Setup**
Please complete the following information along with version numbers, if applicable.
- OS Windows
- Shell Powershell
- Terminal Emulator Windows Terminal
- Terminal Multiplexer None

*Note: you might encounter rendering issues if your locale does not use
`UTF-8` encoding. Please check your locale (`locale` on POSIX systems) to
see what encoding is being used by your system.*

**To Reproduce**
Steps to reproduce the behavior:
1. Throw an error
2. Use `oops.Wrap(err)`
3. Print the wrapped error

**Source Code**
```go
grafana := MakeGrafanaClient(
config.Grafana.Url,
config.Grafana.Username,
config.Grafana.Password,
)
orgs, err := grafana.GetOrgs()
if err != nil {
err := oops.Wrap(err)
logger.Fatal(err.Error(), "error", err)
}
for _, org := range orgs {
logger.Infof("Org(%d : %s)", org.ID, org.Name)
}
```

(There is another issue where my config isn't parsed correctly - but that's a different issue.)

**Expected behavior**
I expected to get my source fragment to be printed properly.

**Screenshots**
![image](https://github.com/user-attachments/assets/67245ebb-34da-45b6-a473-950409ba0e7c)

**Additional context**
oops: https://github.com/samber/oops
Viper (config loader): https://github.com/spf13/viper
Logger initialization:
```go
// global
var logger = log.NewWithOptions(os.Stdout, log.Options{
Prefix: "cli",
ReportCaller: true,
ReportTimestamp: true,
})
var v = viper.NewWithOptions(viper.WithLogger(slog.New(logger)))
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue from the shown logger initialization and the oops.Wrap(err) call on Windows PowerShell. Inspect how logger.Fatal renders the wrapped error and its source fragment, focusing on the reported \t and \r sequences. Done means the wrapped error's source fragment is displayed as expected in Windows Terminal.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
observability
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.