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

Improve Error Reporting for Route Parameter Mismatch #271

Open
treagod opened this issue Oct 24, 2024 · 0 comments
Open

Improve Error Reporting for Route Parameter Mismatch #271

treagod opened this issue Oct 24, 2024 · 0 comments

Comments

@treagod
Copy link
Contributor

treagod commented Oct 24, 2024

Description

Currently, when defining routes with Marten, route parameters need to align with the expected handler parameters. If there is a mismatch between the defined route parameter (e.g., id) and the expected parameter (e.g., pk), an error message like the following is raised:

'articles_show' route cannot receive {"pk" => 2} as parameters.

While the error is technically correct, it requires developers to stop and think about the mismatch, especially if the parameter names are similar or common (e.g., id vs. pk). A more descriptive error message could improve the developer experience by explicitly indicating both the expected and received parameters.

Scenario

For example, in this route definition:

path "/show/<id:int>", ArticlesShowHandler, name: "articles_show"

The handler ArticlesShowHandler, expects a id parameter, but the reversed route uses pk instead. The resulting error is:

'articles_show' route cannot receive {"pk" => 2} as parameters.

The message could be more helpful by showing what parameter was expected versus what was provided.

Discussion Points:

Expected Parameters in Error Message:

Should the error message explicitly mention what parameters the handler expects, e.g.:

'articles_show' route cannot receive {"pk" => 2} as parameters. Expected parameters: ["id"].

Clarity for Parameter Mismatch:

How can we make this more intuitive for developers, especially in cases where common parameter names like id and pk are used?

Benefits

  • Improved Debugging: A clearer message would make it faster and easier to identify parameter mismatches.
  • Better Developer Experience: Less cognitive overhead is required when interpreting error messages, especially for common parameter mismatches.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants