Skip to content

Conversation

sdangol
Copy link
Contributor

@sdangol sdangol commented Sep 25, 2025

Summary

This PR resolves all the linting issues resulting from the new rules being introduced in #4545

Changes

Please provide a summary of what's being changed

  • Removed async from functions not doing await

Please add the issue number below, if no issue is present the PR might get blocked and not be reviewed

Issue number: closes #4575


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@boring-cyborg boring-cyborg bot added event-handler This item relates to the Event Handler Utility tests PRs that add or change tests labels Sep 25, 2025
@sdangol sdangol self-assigned this Sep 25, 2025
@pull-request-size pull-request-size bot added the size/L PRs between 100-499 LOC label Sep 25, 2025
@sdangol
Copy link
Contributor Author

sdangol commented Sep 25, 2025

@svozza There were some any being used in this file. There were some tests which was checking for handling null values. I wanted to check with you if those tests are needed if the null values aren't allowed for those parameters like headers, multiValueHeaders?


return this.#withErrorHandling(
() => this.#executeSingleResolver(event, context, options),
async () => await this.#executeSingleResolver(event, context, options),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just pass the unresolved promise here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, because as this is with this change, it slightly changes the behaviour from what it was.

type RouteHandler<TReturn = HandlerResponse> = (
reqCtx: RequestContext
) => Promise<TReturn>;
) => Promise<TReturn> | TReturn;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice


return this.#withErrorHandling(
() => this.#executeSingleResolver(event, context, options),
async () => await this.#executeSingleResolver(event, context, options),
Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, because as this is with this change, it slightly changes the behaviour from what it was.

context: Context,
options?: ResolveOptions
): Promise<unknown> {
) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function can still return a promise, the type signature should reflect that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are quite a few uses of unknown in the AppSyncGraphQLResolver. Do you have some suggestions on how we could we narrow down the return types for this?

};

type NextFunction = () => Promise<HandlerResponse | void>;
type NextFunction = () =>
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm worried this change is going to encourage people not to await the next function because they think it being async is optional. Failing to await next causes the an error to be thrown and the whole requst fails.

Copy link
Contributor

@dreamorosi dreamorosi Sep 25, 2025

Choose a reason for hiding this comment

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

I got an idea (haven't tested it tho):

What if whenever someone calls app.use we wrap their middleware arrow function in a function we control, before putting the wrapped middleware in the array.

Our function becomes the next and doesn't care if it's called with await or not, but it will always await the function it's wrapping before returning its result.

This way (assuming I'm not just saying something dumb), it doesn't matter if customers forget to call await next or even if the middleware is asynchronous or synchronous, we'll always treat it as async.

Copy link
Contributor

@svozza svozza Sep 26, 2025

Choose a reason for hiding this comment

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

So the issue is not with awaiting the middleware, it's the step after that, which is actually happening inside the the middlware handler. Not calling await returns immediately and messes up the execution order. Even when I tested capturing the Promise and forcing an await inside the composeMiddleware function, the problem was still there.

Copy link
Contributor

Choose a reason for hiding this comment

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

ok then - @sdangol I think this discussion is relevant to your question below.

@dreamorosi
Copy link
Contributor

Hi @sdangol - can you please address the feedback and get this merged in the next couple hrs? Thank you.

@svozza
Copy link
Contributor

svozza commented Sep 26, 2025

@svozza There were some any being used in this file. There were some tests which was checking for handling null values. I wanted to check with you if those tests are needed if the null values aren't allowed for those parameters like headers, multiValueHeaders?

Ah yeah, that test is a hangover from a bug where we used to accept null as a value with headers but it can only ever be undefined (see the type definition) so you can get rid of it.

…constructor any, added unknown to the return type of some functions in GraphQL resolver
@sdangol
Copy link
Contributor Author

sdangol commented Sep 26, 2025

I'm struggling a bit to fix this one build issue in the cors middleware where we exit early without returning anything.

image

) => Promise<HandlerResponse>;

interface ErrorConstructor<T extends Error = Error> {
// biome-ignore lint/suspicious/noExplicitAny: this is a generic type that is intentionally open
Copy link
Contributor Author

@sdangol sdangol Sep 26, 2025

Choose a reason for hiding this comment

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

@svozza @dreamorosi Can we narrow this down to something? I wasn't sure if we could

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess the issue here is supporting custom error types, which can have arbitrary parameters when constructed:

class CustomError extends Error {
  constructor(/* these parameters can be literally anything */) {
  }
}

@sdangol sdangol marked this pull request as ready for review September 26, 2025 10:35

Not all issues are linked correctly.

Please link each issue to the PR either manually or using a closing keyword in the format fixes #<issue-number> format.

If mentioning more than one issue, separate them with commas: i.e. fixes #<issue-number-1>, closes #<issue-number-2>.

@sdangol sdangol changed the title style(event-handler): apply stricter linting style(event-handler): applied stricter linting Sep 26, 2025
@sdangol sdangol changed the title style(event-handler): applied stricter linting style(event-handler): apply stricter linting Sep 26, 2025
@sdangol
Copy link
Contributor Author

sdangol commented Sep 26, 2025

@svozza @dreamorosi For the use of void in unions, I wasn't able to find a way through it so I added an ignore for the lint rule. Narrowing the unknowns on the AppSyncResolver might need more work and might not be suitable to block this PR. Rest of the issues, I've addressed them

@dreamorosi dreamorosi self-requested a review September 26, 2025 10:48
Copy link

@dreamorosi dreamorosi merged commit 3566aa2 into ci/fix_linting Sep 26, 2025
32 of 34 checks passed
@dreamorosi dreamorosi deleted the style/event-handler branch September 26, 2025 10:49
@dreamorosi dreamorosi linked an issue Sep 26, 2025 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

event-handler This item relates to the Event Handler Utility size/L PRs between 100-499 LOC tests PRs that add or change tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Maintenance: fix linting issues for the event-handler package

3 participants