cockroachdb / cockroachdb/errors
Support for obtaining a stack trace without requiring github.com/pkg/errors
- Ngôn ngữ chính
- Go
- Star
- 2.5k
- Fork
- 74
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
I made [a spiritual successor of `github.com/pkg/errors`](https://gitlab.com/tozd/go/errors) some time ago and in it I want to know if an error already contains a stack trace. The goal is that if a large codebase uses different packages for errors, they should work together and not hide existing recorded information, like a stack trace.
One of the issues with `github.com/pkg/errors` is that its `stackTracer` interface uses a custom type only exported by `github.com/pkg/errors`. And it seems this package relays heavily on that and reuses it and even re-exports it.
I would suggest that instead, the following interface is implemented:
```
type stackTracer interface {
StackTrace() []uintptr
}
```
Then, it is easy to obtain a stack trace, use it, format it, and one does not have to depend on a library which created the error.
If you do want to keep using `github.com/pkg/errors` and re-exporting it and keeping its interface (to prevent a breaking change), I have seen also the following interface being used in [this package](https://github.com/go-errors/errors):
```
type goErrorsStackTracer interface {
Callers() []uintptr
}
```
But given that `github.com/pkg/errors` is deprecated, then it is probably reasonable to drop its direct use (this package seems to use it for stack formatting as well) and just change the function to `StackTrace() []uintptr`.
(As I mentioned in #70, you can also use my package as drop-in maintained replacement for `github.com/pkg/errors` which provides same stack frame formatting features, but does not lock you in into custom types just to access a stack trace.)
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Hướng nghiên cứu
Bắt đầu bằng cách xác định việc sử dụng hiện tại của github.com/pkg/errors trong package và cách truy cập stack trace. So sánh hành vi hiện có với interface StackTrace() []uintptr được đề xuất và interface Callers() []uintptr thay thế. Được xem là hoàn tất khi các lỗi từ các package khác nhau có thể hiển thị hoặc bảo toàn stack trace mà không yêu cầu github.com/pkg/errors, đồng thời các kỳ vọng về khả năng tương thích đã được giải quyết.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- go
- Lĩnh vực
- backend
- Loại issue
- Tính năng
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100