Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit b4d9860

Browse files
o752dyaahc
o752d
andauthored
error book wip oliver (#18)
* error book wip oliver * Update CHARTER.md Co-authored-by: Jane Lusby <[email protected]> * remove ignored dir oliver Co-authored-by: Jane Lusby <[email protected]>
1 parent 692fc14 commit b4d9860

30 files changed

+186
-66
lines changed

Diff for: CHARTER.md

+70-39
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,62 @@
55

66
### Agree on and define common error handling terminology
77

8-
- Recoverable error: An error that can be reacted and recovered from when encountered e.g. a missing file.
9-
- Unrecoverable error: An error that cannot reasonably be reacted to or recovered from and which indicates a bug e.g. indexing out of bounds.
10-
- 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.
11-
- Reporting Type: A type that can store all recoverable errors an application may need to propagate and print them as error reports.
12-
- Reporting types can represent the recoverable errors either via concrete types, likely parameterized, or trait objects.
13-
- Reporting types often bundle context with errors when they are constructed, e.g. `Backtrace`.
14-
- 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`.
8+
- Recoverable error: An error that can be reacted and recovered from when
9+
encountered e.g. a missing file.
10+
- Unrecoverable error: An error that cannot reasonably be reacted to or
11+
recovered from and which indicates a bug e.g. indexing out of bounds.
12+
- Error Type: A type that represents a recoverable error. Error types can
13+
optionally implement the `Error` trait so that it can be reported to the user
14+
or be converted into a trait object.
15+
- Reporting Type: A type that can store all recoverable errors an application
16+
may need to propagate and print them as error reports.
17+
- Reporting types can represent the recoverable errors either via concrete
18+
types, likely parameterized, or trait objects.
19+
- Reporting types often bundle context with errors when they are
20+
constructed, e.g. `Backtrace`.
21+
- Reporting types often provide helper functions for creating ad hoc errors
22+
whose only purpose is to be reported e.g. `anyhow::format_err!` or
23+
`eyre::WrapErr`.
1524

1625
### Come to a consensus on current best practices
1726

1827
Here is a tentative starting point, subject to change:
1928

2029
- Use `Result` and `Error` types for recoverable errors.
2130
- Use `panic` for unrecoverable errors.
22-
- Implement `Error` for error types that may need to be reported to a human or be composed with other errors.
23-
- Use enums for types representing multiple failure cases that may need to be handled.
24-
- For libraries, oftentimes you want to support both reporting and handling so you implement `Error` on a possibly non-exhaustive enum.
25-
- Error kind pattern for associating context with every enum variant without including the member in every enum variant.
26-
- 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.
27-
- Recommend `Box`ing concrete error types when stack size is an issue rather than `Box`ing and converting to `dyn Error`s.
28-
- 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`?
31+
- Implement `Error` for error types that may need to be reported to a human or
32+
be composed with other errors.
33+
- Use enums for types representing multiple failure cases that may need to be
34+
handled.
35+
- For libraries, oftentimes you want to support both reporting and handling
36+
so you implement `Error` on a possibly non-exhaustive enum.
37+
- Error kind pattern for associating context with every enum variant without
38+
including the member in every enum variant.
39+
- Convert to a reporting type when the error is no longer expected to be handled
40+
beyond reporting e.g. `anyhow::Error` or `eyre::Report` or when trait object +
41+
downcast error handling is preferable.
42+
- Recommend `Box`ing concrete error types when stack size is an issue rather
43+
than `Box`ing and converting to `dyn Error`s.
44+
- What is the consensus on handling `dyn Error`s? Should it be encouraged or
45+
discouraged? Should we look into making `Box<dyn Error...>` implement `Error`?
2946

3047

3148
### Identify pain points in error handling today
3249

33-
- Backtrace capture is expensive, but without it can be difficult to pinpoint the origin of errors
34-
- unwrapping errors without first converting to a reporting type will often discard relevant information
35-
- errors printed from `main` have to assume a prefixed `Error: `, sub-par control of output format when printing during termination.
36-
- The `Error` trait only exposes three forms of context, can only represent singly-linked lists for chains of errors
50+
- Backtrace capture is expensive, but without it can be difficult to pinpoint
51+
the origin of errors
52+
- unwrapping errors without first converting to a reporting type will often
53+
discard relevant information
54+
- errors printed from `main` have to assume a prefixed `Error: `, sub-par
55+
control of output format when printing during termination.
56+
- The `Error` trait only exposes three forms of context, can only represent
57+
singly-linked lists for chains of errors
3758

3859
### Communicate current best practices
3960

4061
- Document the consensus.
41-
- Communicate plan for future changes to error handling, and the libraries that future changes are being based off of.
62+
- Communicate plan for future changes to error handling, and the libraries that
63+
future changes are being based off of.
4264
- Produce learning resources related to current best practices.
4365
- New chapters in the book?
4466

@@ -50,18 +72,23 @@ Here is a tentative starting point, subject to change:
5072
- Evaluate value of features including:
5173
- Single word width on stack
5274
- Error wrapping with display types and with special downcast support.
53-
- Report hook and configurable `dyn ReportHandler` type for custom report formats and content, similar to panic handler but for errors.
75+
- Report hook and configurable `dyn ReportHandler` type for custom report
76+
formats and content, similar to panic handler but for errors.
5477
- `#[no_std]` support
5578

5679
### Consolidate ecosystem by merging best practice crates into std
5780

5881
- Provide a derive macro for `Error` in std.
59-
- Stabilize the `Backtrace` type but possibly not `fn backtrace` on the `Error` trait.
60-
- Provide necessary API on `Backtrace` to support crates like `color-backtrace`.
82+
- Stabilize the `Backtrace` type but possibly not `fn backtrace` on the `Error`
83+
trait.
84+
- Provide necessary API on `Backtrace` to support crates like
85+
`color-backtrace`.
6186
- Move `Error` to core.
6287
- Depends on generic member access.
63-
- Requires resolving downcast dependency on `Box` and blocking the stabilization of `fn backtrace`.
64-
- Potentially stabilize an error reporting type based on `anyhow` and `eyre` now that they're close to having identical feature sets.
88+
- Requires resolving downcast dependency on `Box` and blocking the
89+
stabilization of `fn backtrace`.
90+
- Potentially stabilize an error reporting type based on `anyhow` and `eyre` now
91+
that they're close to having identical feature sets.
6592

6693
### Add missing features
6794

@@ -72,11 +99,13 @@ Here is a tentative starting point, subject to change:
7299

73100
## Non Goals
74101

75-
- This group should not be involved in managing design discussions for the `Try` trait, `try` blocks, or `try` fns.
102+
- This group should not be involved in managing design discussions for the `Try`
103+
trait, `try` blocks, or `try` fns.
76104

77105
## Membership Requirements
78106

79-
- Group membership is open, any interested party can participate in discussions, repeat contributors will be added to appropriate teams.
107+
- Group membership is open, any interested party can participate in discussions,
108+
repeat contributors will be added to appropriate teams.
80109

81110
## Additional Questions
82111

@@ -86,20 +115,20 @@ I'm not sure, my main concern is getting prompt feedback on RFCs.
86115

87116
### Why should this be a project group over a community effort?
88117

89-
There isn't anything in this project group that can't be handled as a
90-
community effort, but centralizing work into a project group should help
91-
speed things. Error handling is a core aspect of the language and changes in
92-
error handling have large impacts on the ecosystem. Ensuring that efforts to
93-
refine error handling within Rust have sufficient resources and don't stall
94-
out is in the best interests of the community. By organizing efforts as a
95-
project group we will hopefully have an easier time recruiting new members,
96-
getting attention on RFCs from members of the libs team, and using the
97-
established resources and expertise of the rust organization for coordinating
98-
our efforts.
118+
There isn't anything in this project group that can't be handled as a community
119+
effort, but centralizing work into a project group should help speed things.
120+
Error handling is a core aspect of the language and changes in error handling
121+
have large impacts on the ecosystem. Ensuring that efforts to refine error
122+
handling within Rust have sufficient resources and don't stall out is in the
123+
best interests of the community. By organizing efforts as a project group we
124+
will hopefully have an easier time recruiting new members, getting attention on
125+
RFCs from members of the libs team, and using the established resources and
126+
expertise of the rust organization for coordinating our efforts.
99127

100128
### What do you expect the relationship to the team be?
101129

102-
The project group will create RFCs for various changes to the standard library and the team will review them via the standard RFC process.
130+
The project group will create RFCs for various changes to the standard library
131+
and the team will review them via the standard RFC process.
103132

104133
### Who are the initial shepherds/leaders? (This is preferably 2–3 individuals, but not required.)
105134

@@ -111,11 +140,13 @@ Temporary.
111140

112141
### If it is temporary, how long do you see it running for?
113142

114-
This depends pretty heavily on how quickly the RFCs move, anywhere between 6 months and 2 years I'd guess but don't quote me on this.
143+
This depends pretty heavily on how quickly the RFCs move, anywhere between 6
144+
months and 2 years I'd guess but don't quote me on this.
115145

116146
### If applicable, which other groups or teams do you expect to have close contact with?
117147

118-
Primarily the libs team, but there may be some small interactions with the lang team, compiler team, and traits working group.
148+
Primarily the libs team, but there may be some small interactions with the lang
149+
team, compiler team, and traits working group.
119150

120151
### Where do you see your group needing help?
121152

Diff for: CODE_OF_CONDUCT.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# The Rust Code of Conduct
22

3-
The Code of Conduct for this repository [can be found online](https://www.rust-lang.org/conduct.html).
3+
The Code of Conduct for this repository [can be found
4+
online](https://www.rust-lang.org/conduct.html).

Diff for: README.md

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# Error Handling Project Group
22

3-
Welcome to the repository for the Error Handling Project Group! We're focused on defining and communicating Rust's error handling story.
3+
Welcome to the repository for the Error Handling Project Group! We're focused on
4+
defining and communicating Rust's error handling story.
45

5-
This is the repository we use to organise our work. Please refer to our [charter] for more information on our goals and
6-
current scope.
6+
This is the repository we use to organise our work. Please refer to our
7+
[charter] for more information on our goals and current scope.
78

89
- Shepherds:
910
- [Jane Lusby (yaahc)](https://github.com/yaahc)
@@ -18,10 +19,10 @@ current scope.
1819
## How do I follow the project group's work?
1920

2021
The best place to start is probably the agenda of the next meeting. This is
21-
where we track action items from the previous meeting, the previous
22-
meetings's agenda and minutes, and upcoming topics for the next meeting. You
23-
can also check out our issue tracker, project boards, and zulip chat to see
24-
all of the pieces of work that we're doing.
22+
where we track action items from the previous meeting, the previous meetings
23+
agenda and minutes, and upcoming topics for the next meeting. You can also check
24+
out our issue tracker, project boards, and zulip chat to see all of the pieces
25+
of work that we're doing.
2526

2627
- [Upcoming Meeting Agenda][active-agenda]
2728
- [Libs Team Tracked Issues][libs-error-project-tab]

Diff for: meetings/2020-09-28.md

+25-14
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@
44

55
## Agenda Items
66

7-
- Prototyping an implementation of `std::core::Error` and stabilizing `#[feature(backtrace)]`
7+
- Prototyping an implementation of `std::core::Error` and stabilizing
8+
`#[feature(backtrace)]`
89
- Identifying existing issues and RFCs that we should track
910
- https://github.com/rust-lang/rfcs/pull/2895
1011
- Planning for "Communicating best practices"
11-
- "How users expect error handling to be, As in, we take a leap into the future and assume all this was implemented into the language, then how it would potentially look"
12+
- "How users expect error handling to be, As in, we take a leap into the future
13+
and assume all this was implemented into the language, then how it would
14+
potentially look"
1215

1316

1417
# Meeting Minutes
@@ -31,21 +34,26 @@ People in attendance:
3134
- Jubilee Young
3235

3336
## Topic 1: Discussing stabilizing `Backtrace`
34-
- Global hooks vs Boxing vs a trait-based approach for stabilizing `Backtrace` in `core`.
37+
- Global hooks vs Boxing vs a trait-based approach for stabilizing `Backtrace`
38+
in `core`.
3539
- Going with the trait-based impl for `Backtrace` in core.
36-
- Private trait + public newtype wrapper.
37-
- Start with `eddyb`'s impl and see how many hooks are necessary along the way.
40+
- Private trait + public newtype wrapper.
41+
- Start with `eddyb`'s impl and see how many hooks are necessary along the
42+
way.
3843
- private trait with a public newtype wrapper
3944
- newtype wrapper is an interface not subject to coherence so we can add new
40-
methods without worrying about breaking changes downstream
45+
methods without worrying about breaking changes downstream
4146
- https://doc.rust-lang.org/stable/src/std/io/error.rs.html#67-71
42-
- trait-based approaches have fewer magic compiler pieces and so would be easier to put together
43-
- `write_backtrace_to(&mut dyn FormatterThing) -> Result<(),FormatterThing::Error>`
47+
- trait-based approaches have fewer magic compiler pieces and so would be easier
48+
to put together
49+
- `write_backtrace_to(&mut dyn FormatterThing) ->
50+
Result<(),FormatterThing::Error>`
4451
- ultimately about moving `Error` to core
45-
- should we do a trait object based solution internally with an unstable `Backtrace`
46-
trait in core and a stable `Backtrace` type in core or should it use global hooks
47-
like `panic_impl`
48-
- **need a prototype solution for exposing `Backtrace` as a type in `core` with the interface it currently provides in `std`**
52+
- should we do a trait object based solution internally with an unstable
53+
`Backtrace` trait in core and a stable `Backtrace` type in core or should it
54+
use global hooks like `panic_impl`
55+
- **need a prototype solution for exposing `Backtrace` as a type in `core` with
56+
the interface it currently provides in `std`**
4957

5058
## Topic 2: What RFCs should this group be tracking?
5159
- This group will have its own Project board to track relevant issues/RFCs.
@@ -61,15 +69,18 @@ People in attendance:
6169
- Facilitate communication of best practices via a Book/documentation.
6270
- Should include some guidance on FFI error handling.
6371
- Adding a book section to the project repo (using mdbook).
64-
- Publish *The Rust Error Book* (name subject to change) and potentially contribute to *The Book* to make its error handling recommendations consistent with what this group decides.
72+
- Publish *The Rust Error Book* (name subject to change) and potentially
73+
contribute to *The Book* to make its error handling recommendations consistent
74+
with what this group decides.
6575

6676
## Topic 4: What is the long-term vision of what error handling in Rust looks like?
6777
- `Error` in `core`.
6878
- Stabilization of unstable `Error` interfaces.
6979
- Iterator API on `Backtrace`.
7080
- Generic member access (possibly with two-way flow).
7181
- Error return traces.
72-
- Some way to universally hook into all error reporting points for consistent error reporting.
82+
- Some way to universally hook into all error reporting points for consistent
83+
error reporting.
7384
- Better handling of error enums
7485
- Guidance on FFI error handling.
7586
- Ways of recovering from recoverable errors.

Diff for: the-rust-error-book/book.toml

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,16 @@ multilingual = false
55
src = "./src"
66
title = "The Rust Error Book (Title Pending)"
77

8+
[rust]
9+
edition = "2018"
10+
11+
[build]
12+
create-missing = true
13+
14+
[preprocessor.links]
15+
16+
[preprocessor.index]
17+
818
[output.html]
9-
no-section-label=true
10-
git-repository-url="https://github.com/rust-lang/project-error-handling"
19+
no-section-label = true
20+
git-repository-url = "https://github.com/rust-lang/project-error-handling"

Diff for: the-rust-error-book/src/SUMMARY.md

+46-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,47 @@
1-
# Summary
1+
# Summary
22

3-
- [Chapter 1](./chapter_1.md)
3+
- [Preface](./preface.md)
4+
- [Meet the Team](./team_intro.md)
5+
6+
# Rust Error Handling
7+
8+
- [Values Errors Return](./about/errors.md)
9+
- [Classic Example](./about/example.md)
10+
11+
# Generalized Rust Error Handling
12+
13+
- [Theory](./procedure/theory.md)
14+
- [Approach](./procedure/approach.md)
15+
- [Outcome](./procedure/outcome.md)
16+
17+
# Error Handling Fundamentals
18+
19+
- [Recoverable vs Unrecoverable](./fundamentals/un_recover.md)
20+
- [Panic](./fundamentals/panic.md)
21+
- [Result](./fundamentals/result.md)
22+
- [Try Trait](./fundamentals/try_trait.md)
23+
- [Error Trait](./fundamentals/error_trait.md)
24+
25+
# The Parts of Error Handling
26+
27+
- [Defining](./handling/defining.md)
28+
- [Constructing](./handling/constructing.md)
29+
- [Propagating](./handling/propagating.md)
30+
- [Reacting](./handling/reacting.md)
31+
- [Discarding](./handling/discarding.md)
32+
- [Reporting](./handling/reporting.md)
33+
34+
# Common Patterns
35+
36+
# FFI
37+
38+
# Glossary
39+
40+
- [Terms Reference](./glossary.md)
41+
42+
# Appendices
43+
44+
- [A - Error Libs](./appendix/a_error_libs.md)
45+
- [B - Logic of Error Handling](./appendix/b_logic.md)
46+
- [C - Safety](./appendix/c_safety.md)
47+
- [D - References](./appendix/d_references.md)

Diff for: the-rust-error-book/src/about/errors.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Values Errors Return

Diff for: the-rust-error-book/src/about/example.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Classic Example

Diff for: the-rust-error-book/src/appendix/a_error_libs.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# A - Error Libs

Diff for: the-rust-error-book/src/appendix/b_logic.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# B - Logic of Error Handling

Diff for: the-rust-error-book/src/appendix/c_safety.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# C - Safety

Diff for: the-rust-error-book/src/appendix/d_references.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# D - References

Diff for: the-rust-error-book/src/chapter_1.md

-1
This file was deleted.

Diff for: the-rust-error-book/src/fundamentals/error_trait.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Error Trait

Diff for: the-rust-error-book/src/fundamentals/panic.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Panic

Diff for: the-rust-error-book/src/fundamentals/result.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Result

Diff for: the-rust-error-book/src/fundamentals/try_trait.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Try Trait

Diff for: the-rust-error-book/src/fundamentals/un_recover.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Recoverable vs Unrecoverable

Diff for: the-rust-error-book/src/glossary.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Terms Reference

Diff for: the-rust-error-book/src/handling/constructing.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Constructing

Diff for: the-rust-error-book/src/handling/defining.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Defining

Diff for: the-rust-error-book/src/handling/discarding.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Discarding

Diff for: the-rust-error-book/src/handling/propagating.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Propagating

Diff for: the-rust-error-book/src/handling/reacting.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Reacting

Diff for: the-rust-error-book/src/handling/reporting.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Reporting

Diff for: the-rust-error-book/src/preface.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Preface

Diff for: the-rust-error-book/src/procedure/approach.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Approach

Diff for: the-rust-error-book/src/procedure/outcome.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Outcome

Diff for: the-rust-error-book/src/procedure/theory.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Theory

0 commit comments

Comments
 (0)