elbywan / wretch

A tiny wrapper built around fetch with an intuitive syntax. :candy:
MIT License
4.83k stars 98 forks source link

Redundant stack information #156

Closed SamyCookie closed 1 year ago

SamyCookie commented 1 year ago

Concatenate stacks is useless since https://caniuse.com/mdn-javascript_builtins_error_cause implementation. This tends to be more tricky to understand stacks than it helps.

https://github.com/elbywan/wretch/blob/d18ef68a6c9e0bbf5f9cc24199fa3bd15e7fc2cf/src/resolver.ts#L44

I recommend to remove the + "\nCAUSE: " + referenceError.stack.

Example:

13:15:19,102 Uncaught (in promise) Error: 42
    s https://samuel:8443/js/0.bullseye+22-1/common/wretch/wretch.js:36
    _ https://samuel:8443/js/0.bullseye+22-1/common/wretch/wretch.js:51
    promise callback*i https://samuel:8443/js/0.bullseye+22-1/common/wretch/wretch.js:49
    fetch https://samuel:8443/js/0.bullseye+22-1/common/wretch/wretch.js:188
    get https://samuel:8443/js/0.bullseye+22-1/common/wretch/wretch.js:191
    _bodylessQueryMethodFactory https://samuel:8443/js/0.bullseye+22-1/common/wretch.js:61
    <anonymous> https://samuel:8443/js/0.bullseye+22-1/home.js:23
    <anonymous> https://samuel:8443/js/0.bullseye+22-1/home.js:25
    CAUSE: i https://samuel:8443/js/0.bullseye+22-1/common/wretch/wretch.js:44
    fetch https://samuel:8443/js/0.bullseye+22-1/common/wretch/wretch.js:188
    get https://samuel:8443/js/0.bullseye+22-1/common/wretch/wretch.js:191
    _bodylessQueryMethodFactory https://samuel:8443/js/0.bullseye+22-1/common/wretch.js:61
    <anonymous> https://samuel:8443/js/0.bullseye+22-1/home.js:23
    <anonymous> https://samuel:8443/js/0.bullseye+22-1/home.js:25
Caused by: Error: 
    i https://samuel:8443/js/0.bullseye+22-1/common/wretch/wretch.js:44
    fetch https://samuel:8443/js/0.bullseye+22-1/common/wretch/wretch.js:188
    get https://samuel:8443/js/0.bullseye+22-1/common/wretch/wretch.js:191
    _bodylessQueryMethodFactory https://samuel:8443/js/0.bullseye+22-1/common/wretch.js:61
    <anonymous> https://samuel:8443/js/0.bullseye+22-1/home.js:23
    <anonymous> https://samuel:8443/js/0.bullseye+22-1/home.js:25
wretch.js:36:1
elbywan commented 1 year ago

Hey @SamyCookie,

I understand that it can be frustrating to have some duplicated entries in the stack trace. However, the behaviour seems to be different based on the browser used.

Given the following snippet:

<script type="module">
  import wretch from "https://unpkg.com/wretch?module";

   wretch("https://httpstat.us/401").get().text(console.log)
</script>

Here is a screenshot from Chrome…

Capture d’écran 2022-12-12 à 20 53 40

…and here is one from Firefox.

Capture d’écran 2022-12-12 à 20 53 55

As you can see in Chrome there is no perceived issue.

Furthermore the change has been originally requested a while ago because not having the full stack trace caused issues with tools like Sentry: https://github.com/elbywan/wretch/issues/98

Given these reasons, and the fact that I don't find it that critical to have some duplicated lines sometimes I am not keen on changing the code.

SamyCookie commented 1 year ago

I understand ! Thanks for the answer ! :)