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

qol(routing): warn when api route method doesn't match the casing of an export #9497

Merged
merged 5 commits into from
Dec 27, 2023

Conversation

lilnasy
Copy link
Contributor

@lilnasy lilnasy commented Dec 21, 2023

Changes

Testing

Does not affect behavior, just messaging - existing tests should pass.

Docs

Does not affect usage.

Copy link

changeset-bot bot commented Dec 21, 2023

🦋 Changeset detected

Latest commit: e71cfae

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions github-actions bot added pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review labels Dec 21, 2023
Comment on lines 26 to 30
logger.warn(
'router',
`No API Route handler exists for the method "${method}" for the route ${url.pathname}.\n` +
`Found handlers: ${Object.keys(mod).map(method => JSON.stringify(method)).join(', ')}\n`
);
Copy link
Contributor Author

@lilnasy lilnasy Dec 21, 2023

Choose a reason for hiding this comment

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

image

@lilnasy lilnasy force-pushed the endpoint-wrong-export-message branch from 4e4152d to ccd644f Compare December 21, 2023 21:46
Copy link
Contributor

@VoxelMC VoxelMC left a comment

Choose a reason for hiding this comment

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

Hello! I have never reviewed here, so I am sorry if anything I have said is out of scope.

These changes look very helpful for someone who has just upgraded to v4.0! I especially like the Found handlers: log, which will be great now that there are no deprecation notices on lowercase methods anymore.

I have left a couple of comments on my opinions. I hope they are helpful :)

.changeset/tidy-dogs-remain.md Outdated Show resolved Hide resolved
'router',
`No API Route handler exists for the method "${method}" for the route ${url.pathname}.\n` +
`Found handlers: ${Object.keys(mod).map(exp => JSON.stringify(exp)).join(', ')}\n` +
('all' in mod ? `One of the exported handlers is "all" (lowercase), did you mean to export 'ALL'?\n` : '')
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering why all is the only case to handle, and not any of the other verbs?

I would assume that, if the user reads "get" in the Found handlers: log, it should be enough.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The most recent user to run into this was exporting "all". I agree this message should expand to "get", "post" depending what the current request's method is.

Co-authored-by: Voxel <voxelmc@hotmail.com>
Copy link
Member

@bluwy bluwy left a comment

Choose a reason for hiding this comment

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

I like the new warnings! Looks great

'router',
`No API Route handler exists for the method "${method}" for the route ${url.pathname}.\n` +
`Found handlers: ${Object.keys(mod).map(exp => JSON.stringify(exp)).join(', ')}\n` +
('all' in mod ? `One of the exported handlers is "all" (lowercase), did you mean to export 'ALL'?\n` : '')
Copy link
Member

@ematipico ematipico Dec 22, 2023

Choose a reason for hiding this comment

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

We removed the support lower-case functions in v4 (they were deprecated in v3), so we shouldn't show this particular line, otherwise it sounds like we still support it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This message would only be shown when pages/x.ts existed but /x failed to match a handler. I think at that point, it's safe to say the user could use a helpful nudge.

Copy link
Member

Choose a reason for hiding this comment

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

To be more precise, I talk about the all check. We don't support that anymore, so we shouldn't write new code around that. New developers would see this line and won't understand why it is there.

@matthewp matthewp merged commit 7f7a7f1 into withastro:main Dec 27, 2023
14 checks passed
@astrobot-houston astrobot-houston mentioned this pull request Dec 27, 2023
@lilnasy lilnasy deleted the endpoint-wrong-export-message branch January 12, 2024 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: astro Related to the core `astro` package (scope) pr: docs A PR that includes documentation for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrading to v4 make tRPC api requests fail in 404 error
5 participants