Skip to content

doc: book section on error handling #393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
- [Defining metadata types in rust](./metadata_derive.md)
- [Metadata and tables](./metadata_tables.md)
- [Metadata schema](./metadata_schema.md)

* [Error handling](./error_handling.md)


[Crate prelude](./prelude.md)
Expand Down
17 changes: 17 additions & 0 deletions book/src/error_handling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Error handling <img align="right" width="73" height="45" src="https://github.com/raw/tskit-dev/administrative/main/logos/svg/tskit-rust/Tskit_rust_logo.eps.svg">

The error type is [`tskit::error::TskitError`](https://docs.rs/tskit/latest/tskit/error/enum.TskitError.html#).

This type implements `Display` and may thus be printed via:

```rust, noplayground, ignore
let x = match operation() {
Ok(y) => y,
Err(e) => panic("{}", e);
};
```

The enum variant `TskitError::ErrorCode` represents integer return values from `tskit-c`.
When printed via `Display`, the detailed error message is fetched.
When printed via `Debug`, the numerical error code is shown.