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

エラーハンドリングを実装 #46

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

yapatta
Copy link
Collaborator

@yapatta yapatta commented Dec 18, 2020

解決する Issue

close #45

改善内容

  • buildChildを実行時にエラー発生した場合にエラーハンドリングしそれ相当のメッセージを表示(以前はハンドリングしておらず自動で落ちていた)

@yapatta yapatta requested review from n4o847 and masa5555 December 18, 2020 05:47
@yapatta
Copy link
Collaborator Author

yapatta commented Dec 18, 2020

急に思いついて作業しただけなので、思いついたときにレビューお願いしますw

Copy link
Owner

@n4o847 n4o847 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

良い感じだと思います、例外が起こりうるときに throw するか返り値を Either 風にするかみたいな問題ですね。

型安全になるのはいいんですが、アルゴリズム的に色々やってるぶん予期しないところで throw される可能性も拭えないので、公開する関数を絶対に throw しない仕様にしたければ try は残したほうがいい気もしなくもないですし、そこまで気にしなければ別にいいかなと思います。

以前はハンドリングしておらず自動で落ちていた

エラーハンドリングしていなかったのは test.ts だけで、外部に公開している index.ts の方ではハンドリングできてた気はします。

@n4o847
Copy link
Owner

n4o847 commented Dec 18, 2020

あれ、レビューが消えてる

} else {
return { status: 'Error', message: 'Undefined Error.' };
}
const pat = new Parser(src, flags).parse();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parse は構文エラーを throw する可能性があるので try で囲ったほうがいいと思います。

return { status: 'Error', message: 'Undefined Error.' };
}
const pat = new Parser(src, flags).parse();
const enfa = buildEpsilonNFA(pat);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

buildEpsilonNFA も文字集合を構築するときに throw する可能性があった気がします……。

Comment on lines +136 to +139
export type BuildChildResult = { type: 'BuildChildResult' } & Pick<
EpsilonNFA,
'initialState' | 'acceptingState'
>;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たぶん buildChild 限定の内部的な型だと思うので enfa.ts にあった方がいい気がします。

throw new Error('Illigal use LineBegin');
for (let i = 0; i < node.children.length; i++) {
if (i > 0 && node.children[i].type === 'LineBegin') {
return { type: 'Error', error: new Error('Illigal use LineBegin') };
Copy link
Owner

@n4o847 n4o847 Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このコミットのものではないですが、以下のほうが良い気がしたのでついでに修正してもらいたいです……。

Suggested change
return { type: 'Error', error: new Error('Illigal use LineBegin') };
return { type: 'Error', error: new Error('Illegal use of LineBegin') };

i < node.children.length - 1 &&
node.children[i].type === 'LineEnd'
) {
return { type: 'Error', error: new Error('Illigal use LineEnd') };
Copy link
Owner

@n4o847 n4o847 Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return { type: 'Error', error: new Error('Illigal use LineEnd') };
return { type: 'Error', error: new Error('Illegal use of LineEnd') };

@n4o847 n4o847 linked an issue Dec 18, 2020 that may be closed by this pull request
@yapatta
Copy link
Collaborator Author

yapatta commented Dec 18, 2020

レビューありがとうございます!(EitherとかResultみたいな雰囲気を醸し出したいなと思いました)
エラーをcatchしないのは僕が誤解していたようです(test.tsと混同していた)。。。(detectReDoSのtry catchで拾ってくれていました)
三浦くんが言う通りtryは残すべきところは残したほうがよさそうですね〜
後ほど修正します

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.

buildChild内で投げられた例外をハンドリング
2 participants