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 strict type-checks that most switch statements cover all cases #477

Merged
merged 2 commits into from
Jun 22, 2023

Conversation

lukaw3d
Copy link
Member

@lukaw3d lukaw3d commented Jun 8, 2023

No description provided.

@lukaw3d lukaw3d requested review from csillag and lubej June 8, 2023 00:20
@github-actions
Copy link

github-actions bot commented Jun 8, 2023

Deployed to Cloudflare Pages

Latest commit: e9932b7f77e92f2ed1bc92bd12fbd57dec39bcbd
Status:✅ Deploy successful!
Preview URL: https://9b1c0141.oasis-explorer.pages.dev

src/types/errors.ts Outdated Show resolved Hide resolved
return (
<div>
<div>{eventName}</div>
<pre>{JSON.stringify(event, null, ' ')}</pre>
</div>
)
default:
throw new ExhaustedTypeError('Unexpected event type', event.type)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not happy with throwing an error (and hence breaking the whole page) just because we see something we don't recognize. I thing we should also have an exhaustedTypeWarning() function, which just uses console.warn(), and use that in the milder cases like this one.

Copy link
Member Author

Choose a reason for hiding this comment

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

Converted to warnings in production and errors in development

@lukaw3d lukaw3d force-pushed the lw/strict branch 3 times, most recently from 1c815e8 to 4c71566 Compare June 21, 2023 13:18
@lukaw3d lukaw3d requested a review from csillag June 22, 2023 09:19
default:
exhaustedTypeWarning('Unexpected layer', layer)
throw new AppError(AppErrors.UnsupportedLayer)
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we are throwing two exceptions on quick succession. (At least in PROD mode.) Are they both necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, unless we introduce more fallbacks

Copy link
Contributor

@csillag csillag left a comment

Choose a reason for hiding this comment

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

Reviewed, LGTM (except one comment)

@lukaw3d lukaw3d merged commit 300d407 into master Jun 22, 2023
@lukaw3d lukaw3d deleted the lw/strict branch June 22, 2023 11:06
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