Skip to content
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

Add fancy output implementation for error-stack #794

Merged
merged 170 commits into from
Aug 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
170 commits
Select commit Hold shift + click to select a range
4cd39a3
feat: restore impl from #747
indietyp Jul 12, 2022
04a3c4c
feat: first implementation of instruction set
indietyp Jul 12, 2022
a9e586f
chore: move hook/text into fmt
indietyp Jul 19, 2022
4d5d026
feat: build hook system
indietyp Jul 19, 2022
edce0c8
feat: context change
indietyp Jul 19, 2022
565e933
feat: Builtin hook
indietyp Jul 19, 2022
d06c798
chore: remove old specialized code
indietyp Jul 19, 2022
ee94faf
feat: convert to hook
indietyp Jul 19, 2022
af1867d
feat: fmt work
indietyp Jul 23, 2022
811e533
fix: AnyContext over whole `Debug`, Hooks `Send + Sync`
indietyp Jul 24, 2022
0638c6f
fix: preliminary tests
indietyp Jul 24, 2022
341fc02
chore: docs for `add_debug_hook`
indietyp Jul 25, 2022
2799707
feat: don't leak `HookContextImpl` to public interface
indietyp Jul 25, 2022
fe3b537
feat: enable the ability for `Fn(&T)` to be used as hook.
indietyp Jul 25, 2022
f7e6c36
chore: docs
indietyp Jul 25, 2022
c41ca80
docs: Hooks::new() and Hooks::bare()
indietyp Jul 25, 2022
3b6a164
feat: `install_hook`
indietyp Jul 25, 2022
34abe5c
docs: `Line`, `Builtin`, `Instruction`
indietyp Jul 25, 2022
6d86f2d
chore: remove unused imports
indietyp Jul 25, 2022
5edb12b
docs: most of the newly introduced items
indietyp Jul 26, 2022
73eb06e
feat: add location information
indietyp Jul 26, 2022
b81d490
feat: snapshot tests + location formatting fix
indietyp Jul 26, 2022
492264f
chore: clippy
indietyp Jul 26, 2022
afba4c9
chore: docrs warnings
indietyp Jul 26, 2022
9097fed
test: experimentation with multiple time hook set
indietyp Jul 26, 2022
4cfdd2e
test: attempt to fix `OnceCell` snapshotting problems
indietyp Jul 26, 2022
bf29401
fix: snapshot naming
indietyp Jul 26, 2022
db62ec7
test: snapshot testing files
indietyp Jul 27, 2022
c2823ab
fix: formatting
indietyp Jul 27, 2022
4739978
test: add remaining snapshots
indietyp Jul 27, 2022
23d53d0
test: update snapshots
indietyp Jul 27, 2022
0aed303
test: snapshots for stable
indietyp Jul 27, 2022
a9411d3
chore: update insta
indietyp Jul 27, 2022
4364398
test: update snapshots
indietyp Jul 27, 2022
f076c20
test: redact all snapshots
indietyp Jul 27, 2022
d1499f6
chore: clippy
indietyp Jul 27, 2022
c214502
feat: remove pin for glyph loc indicator
indietyp Jul 28, 2022
bb6e221
Merge branch 'main' into feature/fancy
indietyp Jul 28, 2022
efd362c
test: update snaps and doc tests
indietyp Jul 28, 2022
7ac2f13
test: revert ui change
indietyp Jul 28, 2022
96cb68d
test: disable miri for test_debug
indietyp Jul 28, 2022
28bf3a1
test: snapshots update code location
indietyp Jul 28, 2022
f0c9b6b
docs: title docs
indietyp Jul 29, 2022
e45164b
chore: rename tasks, fix powerset
indietyp Aug 3, 2022
ea9dd37
chore: mark snapshots as generated
indietyp Aug 4, 2022
1cfc710
chore: move gitattributes
indietyp Aug 4, 2022
ee4ce19
chore: change to full path
indietyp Aug 4, 2022
f788e65
chore: change .gitattributes again
indietyp Aug 4, 2022
389bbe5
chore: add snapshots folder to generated
indietyp Aug 4, 2022
45d9a80
feat: apply requested changes
indietyp Aug 4, 2022
f09b8e2
Update packages/libs/error-stack/tests/test_debug.rs
indietyp Aug 4, 2022
bb74d2e
feat: apply suggestions
indietyp Aug 4, 2022
5507d38
Merge branch 'feature/fancy' of github.com:indietyp/hash into feature…
indietyp Aug 4, 2022
d8a1276
feat: docs and remove inherent `HookContext` limitation
indietyp Aug 4, 2022
cbbb8d1
docs: improve `HookContext` documentation
indietyp Aug 4, 2022
d58d16a
docs: clarify role of `HookContext::cast`
indietyp Aug 4, 2022
23ef4ab
fix: broken link
indietyp Aug 4, 2022
9e661ff
test: change set_snapshot_suffix to macro
indietyp Aug 4, 2022
8966bf6
chore: move .gitattributes into error-stack lib
indietyp Aug 4, 2022
ba99398
fix: `DebugDiagnostic` example now uses `assert`
indietyp Aug 4, 2022
0f785a6
docs: add glyph feature, fix: expose `Install` trait
indietyp Aug 4, 2022
21fe1bc
docs: `Line` redo example
indietyp Aug 5, 2022
1cb6824
feat: remove `Box` from API of `HookContext`
indietyp Aug 5, 2022
0b7b22d
feat: pub export only on hooks feture
indietyp Aug 6, 2022
3a9b396
docs: rework for `Hook<T, U>`
indietyp Aug 6, 2022
627dba1
Merge branch 'main' into feature/fancy
indietyp Aug 8, 2022
1bce26c
Update packages/libs/error-stack/Makefile.toml
indietyp Aug 8, 2022
c631a39
docs: `fmt` module level documentation
indietyp Aug 8, 2022
33cbe5a
chore: cfg hell to satisfy clippy
indietyp Aug 8, 2022
4f350fd
feat: rename `Line` to `Emit` to clarify intent
indietyp Aug 10, 2022
97ba731
feat: `Line` and `Lines` from type alias to newtype
indietyp Aug 10, 2022
43883a8
feat: rework instruction based infrastructure
indietyp Aug 11, 2022
98edd18
feat: rework `Debug` implementation
indietyp Aug 11, 2022
e2efb75
fix: lint issues
indietyp Aug 11, 2022
695a68b
Merge branch 'main' into feature/fancy
indietyp Aug 11, 2022
3effe00
test: update snapshots
indietyp Aug 11, 2022
7dfa522
test: large complex debug test, and reduce snapshots
indietyp Aug 12, 2022
a522875
feat: move stack to examples (tbd), move to new hook architecture
indietyp Aug 13, 2022
dca81b5
chore: remove debug stack example
indietyp Aug 13, 2022
e0971a8
chore: write down notes
indietyp Aug 13, 2022
5667232
feat: switch to `Call` to support context propagation
indietyp Aug 13, 2022
71c0252
feat: add debug_stack example back
indietyp Aug 13, 2022
48f0f9c
feat: remove `Hook` trait
indietyp Aug 14, 2022
40e3892
feat: remove once_cell requirement for `hooks`
indietyp Aug 14, 2022
72f38a3
test: improve tree rendering
indietyp Aug 15, 2022
5cd2ba0
feat: reverse attachments
indietyp Aug 15, 2022
67a8019
docs: clarification
indietyp Aug 15, 2022
0fab0b6
test: doc test update
indietyp Aug 15, 2022
51fa49d
feat: use expect-test in doctest
indietyp Aug 15, 2022
8a4eadd
docs: file based output w/ HTML
indietyp Aug 15, 2022
fe560fc
docs: update
indietyp Aug 15, 2022
189f160
fix: test_debug from `Hooks` to `instal_debug_hook`
indietyp Aug 15, 2022
0ee4ce1
chore: remove cfg hell
indietyp Aug 16, 2022
4724f07
fix: docs
indietyp Aug 16, 2022
b7fd19e
ci: update-snapshots docs only on nightly
indietyp Aug 16, 2022
d89d09f
docs: replace old formatting in `lib.rs`
indietyp Aug 16, 2022
db34217
feat: remove redundant `hooks` feature
indietyp Aug 16, 2022
f62ce26
chore: flippy
indietyp Aug 16, 2022
5b779ad
feat: improve attachment wording
indietyp Aug 16, 2022
2e759c4
fix: private docs
indietyp Aug 16, 2022
96f26d9
Replace `Call` with `Option<Emit>`
TimDiekmann Aug 18, 2022
3079f59
Merge branch 'feature/fancy' into td/fancy-pr-review-option-emit
TimDiekmann Aug 18, 2022
c470fd5
Revert changes to Makefile.toml
TimDiekmann Aug 18, 2022
dfa8c41
Merge pull request #1 from hashintel/td/fancy-pr-review-option-emit
indietyp Aug 18, 2022
8bf8ab9
Apply suggestions from code review
indietyp Aug 18, 2022
e616d49
feat: apply suggestions
indietyp Aug 18, 2022
44e690b
Merge branch 'feature/fancy' of github.com:indietyp/hash into feature…
indietyp Aug 18, 2022
973be19
Merge branch 'main' into feature/fancy
indietyp Aug 18, 2022
eaf527a
Merge branch 'feature/fancy' of github.com:indietyp/hash into feature…
indietyp Aug 18, 2022
8d6c880
feat: apply suggestions II
indietyp Aug 18, 2022
0c800e9
Apply suggestions from code review
indietyp Aug 18, 2022
e680f16
chore: move snapshots
indietyp Aug 18, 2022
d622fe8
Merge branch 'feature/fancy' of github.com:indietyp/hash into feature…
indietyp Aug 18, 2022
555212e
feat: apply suggestions III
indietyp Aug 18, 2022
bf93f36
chore: update snapshots
indietyp Aug 18, 2022
1d9eb92
Update packages/libs/error-stack/src/fmt/nightly.rs
indietyp Aug 18, 2022
c131858
fix: doclink
indietyp Aug 18, 2022
6344268
Merge branch 'feature/fancy' of github.com:indietyp/hash into feature…
indietyp Aug 18, 2022
9cffbbe
feat: hooks feature warning by @TimDiekmann
indietyp Aug 18, 2022
578506d
feat: apply suggestions IV
indietyp Aug 18, 2022
b2142b4
feat: doc expect gate nightly
indietyp Aug 18, 2022
aea50fb
feat: doc test allow dead_code on not-nightly
indietyp Aug 19, 2022
6c05dea
fix: doctest cfg_attr
indietyp Aug 19, 2022
1cc69a4
fix: docs
indietyp Aug 19, 2022
73e4d7f
fix: docs
indietyp Aug 19, 2022
3dfbd88
feat: update snaphots
indietyp Aug 19, 2022
5ebf52c
doc: add cfg nightly
indietyp Aug 19, 2022
6e5aa03
Merge branch 'main' into feature/fancy
indietyp Aug 19, 2022
405b561
feat: remove `nightly` on `DebugDiagnostic`
indietyp Aug 19, 2022
b016e0e
Merge branch 'main' into feature/fancy
indietyp Aug 19, 2022
a2310be
fix: snapshot
indietyp Aug 19, 2022
36b18e8
Merge branch 'feature/fancy' of github.com:indietyp/hash into feature…
indietyp Aug 19, 2022
d947ee3
fix: forgot nightly cfg on doc
indietyp Aug 19, 2022
4b33137
feat: remove suffix
indietyp Aug 19, 2022
55aa0f4
Apply suggestions from code review
indietyp Aug 19, 2022
c60b7ec
fix: remove stringify
indietyp Aug 19, 2022
e71cabe
Merge branch 'feature/fancy' of github.com:indietyp/hash into feature…
indietyp Aug 19, 2022
7a8f2cd
docs: make TODO more accurate
indietyp Aug 19, 2022
23be617
docs: brief explanation about snapshots
indietyp Aug 19, 2022
3d098c4
feat: rename experimental -> unstable
indietyp Aug 19, 2022
90ee40e
fix: flippy
indietyp Aug 19, 2022
e54a17d
fix: trim char not str
indietyp Aug 19, 2022
63d994b
chore: fmt docstring
indietyp Aug 19, 2022
4891911
Merge branch 'main' into feature/fancy
indietyp Aug 19, 2022
3117f49
Apply suggestions from code review
indietyp Aug 19, 2022
630eed4
chore: remove unneccesary doc_cfg
indietyp Aug 19, 2022
7e78347
Merge branch 'feature/fancy' of github.com:indietyp/hash into feature…
indietyp Aug 19, 2022
ac8c366
fix: experimental flag rename
indietyp Aug 19, 2022
4022e1b
chore: remove statement that is no longer true
indietyp Aug 19, 2022
fe6e867
feat: rename glyph into `pretty-print`
indietyp Aug 19, 2022
718b304
test: rename snapshots
indietyp Aug 19, 2022
e9c9567
Apply suggestions from code review
indietyp Aug 19, 2022
93a150a
fix: context alternate not set
indietyp Aug 19, 2022
83d447c
Merge branch 'feature/fancy' of github.com:indietyp/hash into feature…
indietyp Aug 19, 2022
5cdcc58
fix: fmt builtin rename
indietyp Aug 19, 2022
f6281c2
test: previous alternate regression
indietyp Aug 19, 2022
bb1ee2d
docs: `HookContext::cast`
indietyp Aug 19, 2022
03b994f
Merge branch 'main' into feature/fancy
TimDiekmann Aug 19, 2022
9ee0e09
Update packages/libs/error-stack/Cargo.toml
indietyp Aug 20, 2022
e9e2509
chore: alphabetically sort features
indietyp Aug 20, 2022
9233ac1
docs: update README
indietyp Aug 20, 2022
a145d05
docs: collapse backtrace in README
indietyp Aug 20, 2022
f25e0bd
test: explicit multiline handling
indietyp Aug 20, 2022
c70cb87
docs: move to image in README
indietyp Aug 20, 2022
162fd64
docs: remove emacs workaround
indietyp Aug 20, 2022
e830cd0
feat: footnote about color force
indietyp Aug 20, 2022
f52b3d1
feat: no pretty print: `━` -> `=`, `@` -> `at`
indietyp Aug 20, 2022
1d8863c
fix: clippy
indietyp Aug 20, 2022
1b5a5e0
Tweak output for non-pretty-printing
TimDiekmann Aug 20, 2022
099a832
Merge branch 'main' into feature/fancy
TimDiekmann Aug 20, 2022
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
3 changes: 3 additions & 0 deletions packages/libs/error-stack/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
tests/snapshots/*.snap linguist-generated=true
tests/snapshots/doc/*.snap linguist-generated=true
tests/snapshots/ linguist-generated=true
21 changes: 15 additions & 6 deletions packages/libs/error-stack/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,40 @@ categories = ["rust-patterns", "no-std"]

[dependencies]
tracing-error = { version = "0.2", optional = true, default_features = false }
once_cell = { version = "1.10.0", optional = true, default_features = false }
pin-project = { version = "1.0.10", optional = true, default_features = false }
futures-core = { version = "0.3", optional = true, default-features = false }
smallvec = { version = "1", optional = true, default_features = false, features = ['union'] }
anyhow = { version = "1", default-features = false, optional = true }
eyre = { version = "0.6", default-features = false, optional = true }

owo-colors = { version = "3.4.0", default-features = false, optional = true, features = ['supports-colors'] }

[dev-dependencies]
serde = { version = "1.0.137", features = ["derive"] }
serde_json = "1.0.81"
futures = { version = "0.3.21", default-features = false, features = ["executor"] }
trybuild = "1.0.63"
tracing = "0.1.35"
tracing-subscriber = "0.3.14"
insta = { version = "1.18.0", features = ['filters'] }
regex = "1.6.0"
expect-test = "1.4.0"
ansi-to-html = "0.1.0"
once_cell = "1.13.0"

[build-dependencies]
rustc_version = "0.4"

[features]
default = ["std", "small"]
std = ["anyhow?/std", "once_cell?/std"]
hooks = ["dep:once_cell", "std"]
spantrace = ["dep:tracing-error"]
default = ["std", "small", "pretty-print"]

futures = ["dep:pin-project", "dep:futures-core"]
hooks = ["std"]
pretty-print = ["dep:owo-colors"]
small = ["dep:smallvec"]
spantrace = ["dep:tracing-error"]
std = ["anyhow?/std"]
unstable = []

[package.metadata.docs.rs]
all-features = true
Expand All @@ -48,7 +56,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[[example]]
name = "json_output"
required-features = ["hooks"]
required-features = ["std"]

[[example]]
name = "demo"
Expand All @@ -62,6 +70,7 @@ required-features = ["std"]
name = "parse_config"
required-features = ["std"]


[[test]]
name = "common"
test = false
42 changes: 42 additions & 0 deletions packages/libs/error-stack/Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ CARGO_CLIPPY_HACK_FLAGS = "${CARGO_CLIPPY_HACK_FLAGS_BASE} --group-features anyh
CARGO_TEST_HACK_FLAGS_BASE = "--workspace --feature-powerset --exclude-features default --optional-deps eyre,anyhow"
CARGO_TEST_HACK_FLAGS = "${CARGO_TEST_HACK_FLAGS_BASE} --group-features anyhow,eyre --group-features spantrace,futures,small"
CARGO_MIRI_FLAGS = "--tests --lib"
CARGO_INSTA_TEST_FLAGS = "--no-fail-fast"
# The only features that are of relevance are: spantrace, pretty-print, std, hooks
# all others do not change the output
CARGO_INSTA_TEST_HACK_FLAGS = "--workspace --keep-going --feature-powerset --include-features spantrace,pretty-print,std,unstable"

[env.release]
CARGO_CLIPPY_HACK_FLAGS = "${CARGO_CLIPPY_HACK_FLAGS_BASE}"
Expand All @@ -18,3 +22,41 @@ dependencies = ["install-rust-src"]
[tasks.install-rust-src]
private = true
install_crate = { rustup_component_name = "rust-src" }

# Snapshot Tests
# ==============
#
# Several features make use of snapshots for acceptance/integration tests, these are files
# with expected output for a specific input.
# We use insta for tests https://github.com/mitsuhiko/insta and expect-test https://docs.rs/expect-test/latest/expect_test/ for doc tests.
# expect-test enables us to directly include the snapshot in documentation, while insta provides a more complete feature-set.
#
# You should invoke this task whenever you change `test_debug`, a file which includes a doctest with `expect_test`, or change the formatting of a `Report`.
#
# Reviewing Tests
# ---------------
#
# To review snapshots generated by insta install `cargo-insta` (https://github.com/mitsuhiko/insta) and invoke `cargo insta review`,
# you will be led through all changes one-by-one and need to compare them to see if they are what you expected the outcome to be.
#
# To review snapshots generated by expect-test use gits diffing capabilities.
[tasks.update-snapshots]
category = "Test"
description = "Test against insta to update snapshots"
run_task = { name = ['update-snapshots-task'] }

[tasks.update-snapshots-task]
private = true
run_task = { name = ['update-snapshots-task-lib', 'update-snapshots-task-doc'] }

[tasks.update-snapshots-task-lib]
extend = "task"
args = ["hack", "@@split(CARGO_INSTA_TEST_HACK_FLAGS, )", "nextest", "run", "--cargo-profile", "${CARGO_MAKE_CARGO_PROFILE}", "@@split(CARGO_TEST_FLAGS, )", "@@split(CARGO_INSTA_TEST_FLAGS, )", "${@}"]
env = { "INSTA_FORCE_PASS" = "1", "RUST_BACKTRACE" = "1", "INSTA_UPDATE" = "new" }

[tasks.update-snapshots-task-doc]
# only run on nightly, as backtraces are otherwise not included
condition = { channels = ["nightly"] }
extend = "task"
args = ["test", "--profile", "${CARGO_MAKE_CARGO_PROFILE}", "@@split(CARGO_DOC_TEST_FLAGS, )", "--doc", "${@}"]
env = { "UPDATE_EXPECT" = "1", "RUST_BACKTRACE" = "1" }
29 changes: 1 addition & 28 deletions packages/libs/error-stack/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,33 +95,6 @@ fn main() -> Result<(), ExperimentError> {

This will most likely result in an error and print

```text
Error: Experiment error: Could not run experiment
at examples/demo.rs:54:18
- Unable to set up experiments

Caused by:
0: invalid experiment description
at examples/demo.rs:24:10
- Experiment 2 could not be parsed
1: invalid digit found in string
at examples/demo.rs:22:10
- "3o" could not be parsed as experiment

```
![](assets/full.png)

Please see the [documentation] for a full description.

## Troubleshooting

### Emacs [rust-mode](https://github.com/rust-lang/rust-mode) workaround

Due to [rust-lang/rust-mode#452](https://github.com/rust-lang/rust-mode/issues/452), errors messages are improperly parsed. As a result, the error messages show incorrect highlighting but also yield an incorrect hyperlink.

The one workaround is to modify the regular expression used to format the string and create a hyperlink.

```emacs-lisp
(setq cargo-compilation-regexps
'("\\(?:at\\|',\\) \\(\\([^:\s]+\\):\\([0-9]+\\)\\)"
2 3 nil nil 1))
```
Binary file added packages/libs/error-stack/assets/full.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions packages/libs/error-stack/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@ fn main() {
if version_meta().unwrap().channel == Channel::Nightly {
println!("cargo:rustc-cfg=nightly")
}

#[cfg(feature = "hooks")]
println!(
"cargo:warning=The `hooks` feature for `error-stack` is deprecated as it's not required \
anymore"
)
}
Loading