You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: text/0000-project-error-handling.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ This RFC establishes a new project group, under the libs team, to drive efforts
11
11
# Motivation
12
12
[motivation]: #motivation
13
13
14
-
The error handling project group aims to reduce confusion on how to structure error handling for users in the rust community. This will be accomplished by creating learning resources and pushing effort to upstream widely used crates into std. As a secondary goal this project group will also try to resolve some known issues with the Error trait and reporting errors in panics/termination.
14
+
The error handling project group aims to reduce confusion on how to structure error handling for users in the Rust community. This will be accomplished by creating learning resources and pushing effort to upstream widely used crates into the standard library. As a secondary goal, this project group will also try to resolve some known issues with the `Error` trait and reporting errors in panics/termination.
15
15
16
16
# Charter
17
17
[charter]: #charter
@@ -22,9 +22,9 @@ The error handling project group aims to reduce confusion on how to structure er
22
22
23
23
- Recoverable error: An error that can reasonably be expected to be encountered e.g. a missing file.
24
24
- Unrecoverable error: An error that cannot reasonably be expected to happen and which indicates a bug e.g. indexing out of bounds.
25
-
- Error Type: A type that represents a recoverable error. Error types can optionally implement the error trait so that it can be reported to the user or be converted into a trait object.
26
-
- Reporting Type: A type that can store all recoverable errors an application may need to propogate and print them as error reports.
27
-
- Reporting types can represent the recoverable errors either via concrete types, likely paramaterized, or trait objects.
25
+
- Error Type: A type that represents a recoverable error. Error types can optionally implement the `Error` trait so that it can be reported to the user or be converted into a trait object.
26
+
- Reporting Type: A type that can store all recoverable errors an application may need to propagate and print them as error reports.
27
+
- Reporting types can represent the recoverable errors either via concrete types, likely parameterized, or trait objects.
28
28
- Reporting types often bundle context with errors when they are constructed, e.g. `Backtrace`.
29
29
- Reporting types often provide helper functions for creating ad hoc errors whose only purpose is to be reported e.g. `anyhow::format_err!` or `eyre::WrapErr`.
30
30
@@ -34,42 +34,42 @@ Here is a tenative starting point, subject to change:
34
34
35
35
- Use `Result` and `Error` types for recoverable errors.
36
36
- Use `panic` for unrecoverable errors.
37
-
-Impl`Error` for error types that may need to be reported to a human or be composed with other errors.
37
+
-Implement`Error` for error types that may need to be reported to a human or be composed with other errors.
38
38
- Use enums for types representing multiple failure cases that may need to be handled.
39
-
- For libraries, oftentimes you want to support both reporting and handling so you impl`Error` on a possibly non-exhaustive enum.
39
+
- For libraries, oftentimes you want to support both reporting and handling so you implement`Error` on a possibly non-exhaustive enum.
40
40
- Error kind pattern for associating context with every enum variant without including the member in every enum variant.
41
41
- Convert to a reporting type when the error is no longer expected to be handled beyond reporting e.g. `anyhow::Error` or `eyre::Report` or when trait object + downcast error handling is preferable.
42
42
- Recommend `Box`ing concrete error types when stack size is an issue rather than `Box`ing and converting to `dyn Error`s.
43
-
- What is the consensus on handling `dyn Error`s? Should it be encouraged or discouraged? Should we look into making `Box<dyn Error...>`impl Error?
43
+
- What is the consensus on handling `dyn Error`s? Should it be encouraged or discouraged? Should we look into making `Box<dyn Error...>`implement `Error`?
44
44
45
45
46
46
### Communicate current best practices
47
47
48
-
- Document the concensus.
48
+
- Document the consensus.
49
49
- Communicate plan for future changes to error handling, and the libraries that future changes are being based off of.
50
50
- Produce learning resources related to current best practices.
51
51
- New chapters in the book?
52
52
53
-
### Evaluate options for error reporting type aka better `Box<dyn Error>`
53
+
### Evaluate options for error reporting type a.k.a. better `Box<dyn Error>`
54
54
55
55
- Survey the current libraries in the ecosystem:
56
56
-`anyhow`
57
57
-`eyre`
58
58
- Evaluate value of features including:
59
59
- Single word width on stack
60
60
- Error wrapping with display types and with special downcast support.
61
-
-report hook + configurable `dyn ReportHandler` type for custom report formats and content, similar to panic handler but for errors.
61
+
-Report hook and configurable `dyn ReportHandler` type for custom report formats and content, similar to panic handler but for errors.
62
62
- libcore compatibility.
63
63
64
64
### Consolidate ecosystem by merging best practice crates into std
65
65
66
66
- Provide a derive macro for `Error` in std.
67
-
- Stabilize the `Backtrace` type but possibly not `fn backtrace` on the Error trait.
67
+
- Stabilize the `Backtrace` type but possibly not `fn backtrace` on the `Error` trait.
68
68
- Provide necessary API on `Backtrace` to support crates like `color-backtrace`.
69
-
- Move error to core.
69
+
- Move `Error` to core.
70
70
- Depends on generic member access.
71
71
- Requires resolving downcast dependency on `Box` and blocking the stabilization of `fn backtrace`.
72
-
- Potentially stabilize an error Reporting type based on `anyhow` and `eyre` now that they're close to having identical feature sets.
72
+
- Potentially stabilize an error reporting type based on `anyhow` and `eyre` now that they're close to having identical feature sets.
73
73
74
74
### Add missing features
75
75
@@ -84,7 +84,7 @@ Here is a tenative starting point, subject to change:
84
84
85
85
## Membership Requirements
86
86
87
-
- Group membership is open, any interested party can participate in discussions, repeat contributors will be added appropriate teams.
87
+
- Group membership is open, any interested party can participate in discussions, repeat contributors will be added to appropriate teams.
0 commit comments