strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

Initial implementation of friendlier errors

Open patrick91 opened this issue 3 years ago • 8 comments

I'll add a proper description later, this PR is just for testing the CI steps.

Related: #2107

TODO:

  • [x] assert that documentation exists (via pytest)
  • [x] make all of this optional (flag and checking for imports)
  • [x] Don't fail bad if ast parsing fails (for example with dynamic code)
  • [x] don't add libcst as main dependency
  • [x] print standard exception if we can't find the source (?)
  • [x] redirect from errors.strawberry.rocks

Future release:

  • [ ] Errors in wasm (if libcst works)

Maybe:

  • [ ] custom flake8 plugin to disable pytest.raises with StrawberryExceptions

patrick91 avatar Jul 18 '22 20:07 patrick91

Codecov Report

Merging #2027 (81ab49e) into main (39edd31) will decrease coverage by 0.06%. The diff coverage is 96.71%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2027      +/-   ##
==========================================
- Coverage   97.87%   97.80%   -0.07%     
==========================================
  Files         163      180      +17     
  Lines        6688     7299     +611     
  Branches     1251     1316      +65     
==========================================
+ Hits         6546     7139     +593     
- Misses         69       76       +7     
- Partials       73       84      +11     

codecov[bot] avatar Jul 18 '22 20:07 codecov[bot]

/pre-release

patrick91 avatar Aug 22 '22 14:08 patrick91

Pre-release

:wave:

Pre-release 0.145.0.dev.1670175214 [46f9ee1d244f6d929ea3dd3e5125058d0c3a8099] has been released on PyPi! :rocket: You can try it by doing:

poetry add strawberry-graphql==0.145.0.dev.1670175214

botberry avatar Aug 22 '22 14:08 botberry

Pre-release

:wave:

Pre-release 0.127.0.dev.1661177678 [1c694722e2c8ac628ec8fb603029a1adf0c67aa2] has been released on PyPi! :rocket: You can try it by doing:

poetry add strawberry-graphql==0.127.0.dev.1661177678

botberry avatar Aug 22 '22 14:08 botberry

/pre-release

patrick91 avatar Aug 22 '22 21:08 patrick91

Hi 👋 You can find a preview of the docs here:

https://strawberry.rocks/docs/pr/2027/types/exceptions https://strawberry.rocks/docs/pr/2027/errors https://strawberry.rocks/docs/pr/2027/errors/_template https://strawberry.rocks/docs/pr/2027/errors/invalid-argument-type https://strawberry.rocks/docs/pr/2027/errors/invalid-type-for-union-merge https://strawberry.rocks/docs/pr/2027/errors/invalid-union-type https://strawberry.rocks/docs/pr/2027/errors/missing-arguments-annotations https://strawberry.rocks/docs/pr/2027/errors/missing-field-annotation https://strawberry.rocks/docs/pr/2027/errors/missing-return-annotation https://strawberry.rocks/docs/pr/2027/errors/object-is-not-an-enum https://strawberry.rocks/docs/pr/2027/errors/object-is-not-class https://strawberry.rocks/docs/pr/2027/errors/private-strawberry-field https://strawberry.rocks/docs/pr/2027/errors/scalar-already-registered

github-actions[bot] avatar Sep 03 '22 17:09 github-actions[bot]

Thanks for adding the RELEASE.md file!

Here's a preview of the changelog:


This release introduced improved errors! Now, when you have a syntax error in your code, you'll get a nice error message with a line number and a pointer to the exact location of the error. ✨

This is a huge improvement over the previous behavior, which was providing a stack trace with no clear indication of where the error was. 🙈

You can enable rich errors by installing Strawberry with the cli extra:

pip install strawberry-graphql[cli]

Here's the preview release card for twitter:

Here's the tweet text:

🆕 Release (next) is out! Thanks to @patrick91 for the PR 👏

Get it here 👉 https://github.com/strawberry-graphql/strawberry/releases/tag/(next)

botberry avatar Sep 03 '22 18:09 botberry

/pre-release

patrick91 avatar Sep 17 '22 09:09 patrick91

from discord:

we should make this error better, if not already done here:

import strawberry
from strawberry.scalars import JSON
strawberry.union(
    name='NamedUnion',
    types=(
        # some other types
        JSON,
    ),
)

AttributeError: 'ScalarWrapper' object has no attribute 'name'. Did you mean: 'ne'.

patrick91 avatar Nov 10 '22 19:11 patrick91

/pre-release

patrick91 avatar Dec 01 '22 23:12 patrick91

/pre-release

patrick91 avatar Dec 04 '22 15:12 patrick91

/pre-release

patrick91 avatar Dec 04 '22 16:12 patrick91

/pre-release

patrick91 avatar Dec 04 '22 17:12 patrick91