Skip to content

fix(routing): improve error handling#14161

Closed
ematipico wants to merge 3 commits into
mainfrom
fix/routing-validation
Closed

fix(routing): improve error handling#14161
ematipico wants to merge 3 commits into
mainfrom
fix/routing-validation

Conversation

@ematipico

Copy link
Copy Markdown
Member

Changes

Closes #12036

Astro didn't perform any validation of the route mappings. This PR introduces a new function that performs this task.

An error is thrown when a redirect can't be mapped to a new route.

Testing

Added a new test

Docs

@changeset-bot

changeset-bot Bot commented Jul 30, 2025

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9bdc5ad

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) docs pr labels Jul 30, 2025
@codspeed-hq

codspeed-hq Bot commented Jul 30, 2025

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #14161 will not alter performance

Comparing fix/routing-validation (92632a6) with main (34e6b3a)1

Summary

✅ 6 untouched benchmarks

Footnotes

  1. No successful run was found on main (c86b5bb) during the generation of this report, so 34e6b3a was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

@ematipico ematipico force-pushed the fix/routing-validation branch from df7778d to 942a721 Compare July 30, 2025 10:49
@ematipico ematipico force-pushed the fix/routing-validation branch from 942a721 to 37e57c5 Compare July 30, 2025 11:01

@ascorbic ascorbic left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What would be the behaviour now, if one of these invalid redirects was created?

Comment thread .changeset/witty-wasps-tie.md
@ematipico

Copy link
Copy Markdown
Member Author

What would be the behaviour now, if one of these invalid redirects was created?

As mentioned in the bug report, the error is generic:

[ERROR] [build] Failed to call getStaticPaths for /categories/[category]
[GetStaticPathsRequired] `getStaticPaths()` function is required for dynamic routes. Make sure that you `export` a `getStaticPaths` function from your dynamic route.

Co-authored-by: Matt Kane <m@mk.gg>
@ematipico ematipico requested a review from ascorbic July 31, 2025 11:26
Comment thread packages/astro/test/redirects.test.js
Comment thread packages/astro/test/redirects.test.js Outdated
@ematipico ematipico requested a review from ascorbic July 31, 2025 13:19
@ascorbic

Copy link
Copy Markdown
Contributor

This still doesn't test for the example in the issue, and I'm not sure it would catch it. The original had the same number of dynamic segments on each side:

redirects: {
  '/categories/[category]': '/category/[category]/1',
}

@ematipico

Copy link
Copy Markdown
Member Author

Sorry, I missed that. I'll add a test for that too

@florian-lefebvre

Copy link
Copy Markdown
Member

@ematipico what are your plans for this PR?

@ematipico

Copy link
Copy Markdown
Member Author

@florian-lefebvre It requires some thinking about how to catch the edge case and throw an error. Unfortunately I'm focused on other things, and jumping on this one again would require some time to fix

@ematipico ematipico marked this pull request as draft October 16, 2025 10:00
@Princesseuh

Copy link
Copy Markdown
Member

Closing due to inactivity, I assume that with Astro 6 this might require some code change as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs pr pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading missing getStaticPaths error with configured redirects and dynamic routes

4 participants