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

fix: error on scheduled/event-triggered functions with custom route #5344

Merged
merged 9 commits into from
Oct 25, 2023

Conversation

Skn0tt
Copy link
Contributor

@Skn0tt Skn0tt commented Oct 20, 2023

Closes https://linear.app/netlify/issue/COM-48/error-when-v2-function-define-custom-paths-for-scheduled-functions.

This PR adds detection for scheduled/event-triggered functions that define a custom route. We're throwing an error, because changing the route will break them being triggered correctly - plus, they're not publically callable anyways, so there's no reason to change their route.

@Skn0tt Skn0tt self-assigned this Oct 20, 2023
@Skn0tt Skn0tt requested review from a team as code owners October 20, 2023 13:55
@Skn0tt Skn0tt marked this pull request as draft October 20, 2023 13:55
@Skn0tt
Copy link
Contributor Author

Skn0tt commented Oct 20, 2023

Turning to draft to write some tests. @eduardoboucas let me know if you think this should live in ZISI instead.

Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

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

Nice! I think it makes sense for this to live in Netlify Build, since ZISI doesn't typically show any messaging. I just wonder what'll happen when running in Netlify Dev, since we won't go through build?

Perhaps we can add an additional check in the CLI, that doesn't throw an error and stop everything in its tracks, but instead shows a warning to tell people that this will be an issue when deploying?


if (schedule) {
const error = new Error(
`Scheduled functions must not specify a custom route. Please remove the "routes" configuration or pick a different name for the function. Learn more about scheduled functions at https://docs.netlify.com/functions/scheduled-functions.`,
Copy link
Member

Choose a reason for hiding this comment

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

routes is not a public-facing property. Did you mean path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, good catch! updated.


if (schedule) {
const error = new Error(
`Scheduled functions must not specify a custom route. Please remove the "routes" configuration or pick a different name for the function. Learn more about scheduled functions at https://docs.netlify.com/functions/scheduled-functions.`,
Copy link
Member

Choose a reason for hiding this comment

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

nit: I would use a ntl.fyi short link here. It's more consistent with with other messaging and lets us point it to somewhere else if needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good idea, done in 9fd107b

@github-actions
Copy link
Contributor

This pull request adds or modifies JavaScript (.js, .cjs, .mjs) files.
Consider converting them to TypeScript.

@Skn0tt Skn0tt marked this pull request as ready for review October 23, 2023 13:31

if (schedule) {
const error = new Error(
`Scheduled functions must not specify a custom path. Please remove the "path" configuration or pick a different name for the function. Learn more about scheduled functions at https://ntl.fyi/custom-path-scheduled-functions.`,
Copy link
Member

Choose a reason for hiding this comment

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

Hmm how will picking a different name for the function help in the case of a scheduled function?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

copy & paste error!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed in 4a5a13b

@Skn0tt
Copy link
Contributor Author

Skn0tt commented Oct 23, 2023

Perhaps we can add an additional check in the CLI, that doesn't throw an error and stop everything in its tracks, but instead shows a warning to tell people that this will be an issue when deploying?

We could do that, but it's not super obvious where that'd live. Would we log an error during ntl dev, or show a custom error page when the user tries requesting the custom route? I don't think that'll happen a lot, and I don't think it's worth adding this to our CLI codebase. Having it in a build step will prevent people from scratching their head when this does occur, but I don't think we need a lot more.

eduardoboucas
eduardoboucas previously approved these changes Oct 23, 2023
Copy link
Member

@eduardoboucas eduardoboucas left a comment

Choose a reason for hiding this comment

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

Nice!

packages/build/src/plugins_core/functions/index.ts Outdated Show resolved Hide resolved
@Skn0tt Skn0tt enabled auto-merge (squash) October 23, 2023 13:50
@Skn0tt Skn0tt merged commit 9ef1a15 into main Oct 25, 2023
35 checks passed
@Skn0tt Skn0tt deleted the detect-invalid-functions branch October 25, 2023 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants