Skip to content

Commit

Permalink
doc: book section on error handling (#393)
Browse files Browse the repository at this point in the history
  • Loading branch information
molpopgen authored Nov 6, 2022
1 parent 75ff794 commit 6cd9efe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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://raw.githubusercontent.com/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.

0 comments on commit 6cd9efe

Please sign in to comment.