Skip to content

feat(inject-params): add required parameter validation and error handling for injectParams#670

Open
eneajaho wants to merge 4 commits intomainfrom
feat/inject-params-required
Open

feat(inject-params): add required parameter validation and error handling for injectParams#670
eneajaho wants to merge 4 commits intomainfrom
feat/inject-params-required

Conversation

@eneajaho
Copy link
Collaborator

No description provided.

…dling

Introduce `required` option to enforce the presence of parameters in `injectParams`. Throws an error if the required parameter is missing. Includes updated typings, logic, and documentation improvements.
…for missing parameters

Introduce `required` option to enforce the presence of query parameters in `injectQueryParams`. Throws an error if the required parameter is not provided. Includes updated typings, logic, documentation, and overloads for stricter parameter validation.
…meters with error handling

Implement `required` option for `injectQueryParams.array` to enforce the presence of array query parameters. Includes stricter typings, new test cases, and error handling for missing required parameters.
Introduce test cases for required parameter handling in `injectParams`. Verify error handling when a required parameter is missing and successful resolution when it is present. Includes new test component `RequiredParamComponent`.
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the injectParams and injectQueryParams utilities by introducing a required option. This new feature allows developers to explicitly mark route parameters or query parameters as mandatory. If a parameter marked as required is not found in the route or query string, the utility will now throw a clear, descriptive error, preventing unexpected behavior and aiding in debugging. This improves the robustness and predictability of parameter injection within Angular applications.

Highlights

  • Required Parameter Validation: Introduced a required option for both injectParams and injectQueryParams to enforce the presence of specific route or query parameters.
  • Error Handling: Implemented robust error handling that throws a descriptive error message when a parameter marked as required is missing.
  • Type Safety Enhancements: Expanded the type definitions for injectParams and injectQueryParams to correctly reflect the behavior of the required option, ensuring improved type safety.
  • Comprehensive Testing: Added extensive unit tests to validate the new required functionality, covering scenarios for both successful retrieval and error-throwing when parameters are absent, including for array query parameters.
Changelog
  • libs/ngxtension/inject-params/src/inject-params.spec.ts
    • Added test cases to verify that injectParams throws an error when a required parameter is missing.
    • Added a test case to confirm injectParams correctly retrieves a required parameter when present.
    • Introduced RequiredParamComponent for testing purposes.
  • libs/ngxtension/inject-params/src/inject-params.ts
    • Defined missingRequiredParamError function for consistent error messages.
    • Extended ParamsOptions to include RequiredOptions.
    • Destructured required from options in injectParamsCore.
    • Added logic to throw missingRequiredParamError if a parameter is required but not found.
    • Updated injectParams overloads to reflect the new required option and its return type implications.
  • libs/ngxtension/inject-query-params/src/inject-query-params.spec.ts
    • Added test cases to verify that injectQueryParams throws an error when a required query parameter is missing.
    • Added a test case to confirm injectQueryParams correctly retrieves a required query parameter when present.
    • Added test cases for injectQueryParams.array to ensure required array query parameters are validated.
    • Introduced RequiredQueryParamComponent and RequiredArrayQueryParamComponent for testing.
  • libs/ngxtension/inject-query-params/src/inject-query-params.ts
    • Defined missingRequiredParamError function for consistent error messages.
    • Extended QueryParamsOptions to include RequiredOptions.
    • Updated injectQueryParams overloads to reflect the new required option.
    • Destructured required from options in injectQueryParams and injectQueryParams.array.
    • Added logic to throw missingRequiredParamError if a query parameter (single or array) is required but not found or empty.
  • libs/ngxtension/shared/src/options/index.ts
    • Exported required options.
  • libs/ngxtension/shared/src/options/required.ts
    • Added RequiredOptions type definition.
Activity
  • No activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@nx-cloud
Copy link

nx-cloud bot commented Feb 27, 2026

View your CI Pipeline Execution ↗ for commit 24a1d64

Command Status Duration Result
nx affected --target=build --parallel=3 --exclu... ✅ Succeeded 14s View ↗
nx affected --target=test --parallel=3 --exclud... ✅ Succeeded 15s View ↗
nx affected --target=lint --parallel=3 ✅ Succeeded 44s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 2s View ↗

☁️ Nx Cloud last updated this comment at 2026-02-27 14:59:08 UTC

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new "required" option for injectParams and injectQueryParams functions, enhancing parameter validation by throwing an error if a required parameter is missing. The changes include adding the RequiredOptions type, updating the core logic to check for missing required parameters, and providing appropriate error messages. New test cases have been added to cover scenarios where required parameters are both present and missing, ensuring the feature works as expected. The type overloads have also been updated to reflect the non-nullable return type when required: true is used.

if (!param) {
if (required) {
throw missingRequiredParamError(
keyOrParamsTransform as string | undefined,

Choose a reason for hiding this comment

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

medium

In this context, keyOrParamsTransform is guaranteed to be a string because the preceding if conditions handle undefined and function types. The as string | undefined assertion is therefore redundant and can be simplified to keyOrParamsTransform.

Suggested change
keyOrParamsTransform as string | undefined,
keyOrParamsTransform,

if (!param) {
if (required) {
throw missingRequiredParamError(
keyOrParamsTransform as string | undefined,

Choose a reason for hiding this comment

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

medium

Similar to the inject-params.ts file, keyOrParamsTransform is guaranteed to be a string at this point in the execution flow. The as string | undefined assertion is redundant and can be simplified to keyOrParamsTransform.

Suggested change
keyOrParamsTransform as string | undefined,
keyOrParamsTransform,

if (param.length < 1) {
if (required) {
throw missingRequiredParamError(
keyOrParamsTransform as string | undefined,

Choose a reason for hiding this comment

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

medium

Here, keyOrParamsTransform is already known to be a string. The as string | undefined assertion is redundant and can be simplified to keyOrParamsTransform.

Suggested change
keyOrParamsTransform as string | undefined,
keyOrParamsTransform,

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.

1 participant