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 errors package with optional stacktrace capturing #431

Merged
merged 1 commit into from
Aug 22, 2021

Conversation

jhchabran
Copy link
Collaborator

The goal of this package is to enable to capture stack traces when the error are being raised, which speeds up the development process, if enabled at compile time. To do so, this set of changes introduces an internal/errors package to handle errors with four functions: .New, .Errorf, .Is and .Unwrap. Albeit support for reflect has been added recently to tinygo, it presently not depend on reflect in any way.

If the code is compiled with the debug build tag, the stack trace will be captured when an error is created or wrapped (both with .New). Without that build tag, the errors packages falls back to simply comparing values and performs no wrapping at all.

It also come with a new testutil/assert package which replaces the require package when it comes to checking or comparing errors and printing the stack traces if needed.

Finally, the test target of the Makefile uses the debug build tag by default. A testnodebug target is also provided for convenience and to make sure no tests breaks due to not having used the internal/errors or testutil/assert package.

@codecov-commenter
Copy link

codecov-commenter commented Aug 21, 2021

Codecov Report

Merging #431 (442c4df) into main (a45d2c1) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #431   +/-   ##
=======================================
  Coverage   70.45%   70.45%           
=======================================
  Files          93       93           
  Lines        9689     9689           
=======================================
  Hits         6826     6826           
  Misses       2144     2144           
  Partials      719      719           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a45d2c1...442c4df. Read the comment docs.

The goal of this package is to enable to capture stack traces when the error are being raised, which speeds up the development process, if enabled at compile time. To do so, this set of changes introduces an internal/errors package to handle errors with four functions: .New, .Errorf, .Is and .Unwrap. Albeit support for reflect has been added recently to tinygo, it presently not depend on reflect in any way.

If the code is compiled with the debug build tag, the stack trace will be captured when an error is created or wrapped (both with .New). Without that build tag, the errors packages falls back to simply comparing values and performs no wrapping at all.

It also come with a new testutil/assert package which replaces the require package when it comes to checking or comparing errors and printing the stack traces if needed.

Finally, the test target of the Makefile uses the debug build tag by default. A testnodebug target is also provided for convenience and to make sure no tests breaks due to not having used the internal/errors or testutil/assert package.
@jhchabran jhchabran merged commit 5602572 into main Aug 22, 2021
@jhchabran jhchabran deleted the internal-errors-pkg branch August 22, 2021 08:22
jhchabran added a commit that referenced this pull request Aug 22, 2021
All new error handling code now rely on internal/errors package
which provides a compilation time toggle that enables to capture
stacktraces for easier debugging while developing.

See #431 for more details
jhchabran added a commit that referenced this pull request Aug 22, 2021
All new error handling code now rely on internal/errors package
which provides a compilation time toggle that enables to capture
stacktraces for easier debugging while developing.

It also comes with a new testutil/assert package which replaces the require
package when it comes to checking or comparing errors and printing the
stack traces if needed.

Finally, the test target of the Makefile uses the debug build tag by default. 
A testnodebug target is also provided for convenience and to make sure no
tests are broken due to not having used the internal/errors or testutil/assert package.

See #431 for more details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants