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

ES2022: Error Cause #1714

Closed
2 tasks
azu opened this issue Feb 10, 2024 · 4 comments · Fixed by #1732
Closed
2 tasks

ES2022: Error Cause #1714

azu opened this issue Feb 10, 2024 · 4 comments · Fixed by #1732
Labels
Lang: ES2022 ECMAScript 2022 Status: Proposal 提案段階の状態
Milestone

Comments

@azu
Copy link
Collaborator

azu commented Feb 10, 2024

ここで対応しないとしていたけど、再検討する。

具体的には次の場所では、Error causeを使った方が明らかに良いので、ここで使えるように基礎文法で紹介したい。

function main() {
    fetchUserInfo("js-primer-example")
        .catch((error) => {
            // Promiseチェーンの中で発生したエラーを受け取る
            console.error(`エラーが発生しました (${error})`);
        });
}

Promiseを活用する · JavaScript Primer #jsprimer

TODO

課題として、Error Causeの効果(スタックトレースの話とか)をどうやって表現するかという問題がありそう

@azu azu added Lang: ES2022 ECMAScript 2022 Status: Proposal 提案段階の状態 labels Feb 10, 2024
@azu azu added this to the v6(ES2024) milestone Feb 10, 2024
@azu azu changed the title [ES2022] Error Cause ES2022: Error Cause Feb 10, 2024
@azu
Copy link
Collaborator Author

azu commented Feb 10, 2024

他にも文中にこういうケースがないかは見つけないといけない。
非同期 or try-catchぐらいだと思うので、ないような気もしているけどどうだろ?

@azu
Copy link
Collaborator Author

azu commented Mar 24, 2024

@himanoa さんに担当してもらう。

入れること自体(Error Cause自体の説明とPromiseを活用するなどでの利用)は多分そこまで難しくないのですが、
例外処理で、スタックトレースの説明が最後になってるので、
スタックトレースの説明してからじゃないとError Causeを説明できない気がしていて、説明の順番どうしようというのがちょっと悩みどころになってます。

エラーとデバッグの中に入れてしまうか、もうちょっとセクションを整理して再構成する(スタックトレースをErrorあたりとか前の方に持ってくる)などの選択肢がありそうな気はします。

あとは、Error Cause自体をシンプルに意味ある説明をしようとすると、re-throwになる気がしてて、
エラーメッセージを書き換えつつスタックトレースは維持するには?(or シンプルにError Cause[^E2022]というタイトル) という感じのセクションを追加(コラムっぽい感じもしますが、ユースケースで使うので本文として入れる)的な方法が良いのかもなーとも思ったりします。

@himanoa
Copy link
Contributor

himanoa commented Mar 24, 2024

@azu
説明ありがとうございます!

例外処理の最後に Error Cause[^E2022] のセクションを追加して、re-throwした時にスタックトレースを維持するための説明を書く方針で進めようとおもいます!

himanoa added a commit to himanoa/js-primer that referenced this issue Mar 24, 2024
@azu
Copy link
Collaborator Author

azu commented Mar 26, 2024

Error Causeの表示を対応してる例

@azu azu closed this as completed in #1732 Mar 27, 2024
azu added a commit that referenced this issue Mar 27, 2024
* feat: add a `error-cause` section to `error-try-catch`

See. #1714

* chore: add a error-cause to `error-try-catch` conclusion section

* chore: Use cause property in ajaxapp/promise example codes

* chore: access to cause property in `Error cause` section's example code

* refactor: Exec `npm run textlint:fix`

* chore: align with other heading expressions

* chore: change from active form to passive form

See. #1732 (comment)

Co-authored-by: azu <azu@users.noreply.github.com>

* chore: add conjunction

Co-authored-by: Suguru Inatomi <suguru.inatomi@gmail.com>

* chore: 表記ゆれの統一(送出 -> 投げられる)

Co-authored-by: azu <azu@users.noreply.github.com>

* chore: cut out a example code

* fix: remove unnecessary console.error

* fix: Error Causeの説明をより丁寧にする

* fix: remove logging cause property

* fix: exec `npm run textlint:fix`

* fix: broken test

Co-authored-by: azu <azu@users.noreply.github.com>

* chore: Remove empty lines

Co-authored-by: azu <azu@users.noreply.github.com>

* fix: add cause description

* fix: use Number.parseInt instead of parseInt

Co-authored-by: azu <azu@users.noreply.github.com>

* chore: change function definition order safeParseInt and sumNumStrings

---------

Co-authored-by: azu <azu@users.noreply.github.com>
Co-authored-by: Suguru Inatomi <suguru.inatomi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Lang: ES2022 ECMAScript 2022 Status: Proposal 提案段階の状態
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants