Skip to content

CFSQL-1473: fix D1 exec throwing TypeError on invalid SQL queries#6029

Open
FlorentCollin wants to merge 4 commits intomainfrom
fcollin/CFSQL-1473-fix-db-exec-type-error
Open

CFSQL-1473: fix D1 exec throwing TypeError on invalid SQL queries#6029
FlorentCollin wants to merge 4 commits intomainfrom
fcollin/CFSQL-1473-fix-db-exec-type-error

Conversation

@FlorentCollin
Copy link
Member

We were trying to call addAggregatedD1MetaToSpan before checking if any of the results are errors in a .exec call. When an error is returned the meta property is not set.

This commit is now checking the errors first and then call the addAggregatedD1MetaToSpan if there is no error.

We were trying to call `addAggregatedD1MetaToSpan` before checking if
any of the results are errors in a `.exec` call. When an error is returned the meta
property is not set.

This commit is now checking the errors first and then call the
`addAggregatedD1MetaToSpan` if there is no error.
@FlorentCollin FlorentCollin requested review from a team as code owners February 6, 2026 14:39
}
);
} else {
addAggregatedD1MetaToSpan(
Copy link
Contributor

@lambrospetrou lambrospetrou Feb 6, 2026

Choose a reason for hiding this comment

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

This is good. We should also make the function addAggregatedD1MetaToSpan defensive in my opinion on its own, so that it doesn't crash even if an invalid object is passed in. It should only process things that exist on the given meta span.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. I added defensive checks to both the addAggregatedD1MetaToSpan and aggregateD1Meta. It should be good now.

Copy link
Member Author

Choose a reason for hiding this comment

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

It turns out that eslint is annoying

  785:32  error  Unnecessary conditional, expected left-hand side of `??` operator to be possibly null or undefined  @typescript-eslint/no-unnecessary-condition

For now I added a bunch of eslint-disable-next-line but it's starting to get a bit ugly even though it's good to have these defensive checks.

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 6, 2026

Merging this PR will not alter performance

✅ 70 untouched benchmarks
⏩ 129 skipped benchmarks1


Comparing fcollin/CFSQL-1473-fix-db-exec-type-error (480ee72) with main (2cba16b)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@FlorentCollin FlorentCollin force-pushed the fcollin/CFSQL-1473-fix-db-exec-type-error branch 2 times, most recently from a4cf765 to d9b21f5 Compare February 6, 2026 16:44
@FlorentCollin FlorentCollin force-pushed the fcollin/CFSQL-1473-fix-db-exec-type-error branch from d9b21f5 to 47e7695 Compare February 6, 2026 17:23
aggregatedMeta.last_row_id = meta.last_row_id;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
aggregatedMeta.size_after = meta.size_after ?? 0;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
Copy link
Member

Choose a reason for hiding this comment

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

If you have to add ??, then the typescript types are wrong. Rather than ignoring eslint, can we fix the types please?

}

function addAggregatedD1MetaToSpan(span: Span, metas: D1Meta[]): void {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
Copy link
Member

Choose a reason for hiding this comment

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

This would be unnecessary if you changed the param types.


for (const meta of metas) {
aggregatedMeta.duration += meta.duration;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
Copy link
Member

Choose a reason for hiding this comment

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

Again, this is unnecessary if the type is correct. If it's not correct, then let's update the types.

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.

3 participants