Skip to content

sqlctemplate: Error on template-like artifacts that are probably mistakes#858

Merged
brandur merged 1 commit intomasterfrom
brandur-error-on-obvious-template-problems
Apr 28, 2025
Merged

sqlctemplate: Error on template-like artifacts that are probably mistakes#858
brandur merged 1 commit intomasterfrom
brandur-error-on-obvious-template-problems

Conversation

@brandur
Copy link
Contributor

@brandur brandur commented Apr 26, 2025

While implementing #848 I made a couple typos in SQL queries at a few
points where I made some minor problem in a template tag like putting in
/* TEMPLATE schema */ instead of /* TEMPLATE: schema */.

sqlctemplate isn't a real compiler, so instead of these problems getting
flagged, they're silently ignored, and this is made even worse because
sqlc strips comments from queries so we often end up with absolutely
nothing to debug with. This results in a long, frustrating debugging
experience.

Here, perform a post-replace match to check for obvious problems and
tell the caller about them immediately. It's not perfect, but will save
time in diagnosing common problems.

@brandur brandur requested a review from bgentry April 26, 2025 09:06
Copy link
Contributor

@bgentry bgentry left a comment

Choose a reason for hiding this comment

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

LGTM aside from comment issue ✌️

require.EqualError(t, err, "sqlctemplate found template-like tag after replacements; probably syntax error or missing end tag: /* TEMPLATE_BEGIN")
}

// Missing "TEMPLATE_END".
Copy link
Contributor

Choose a reason for hiding this comment

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

wrong comment? This one has TEMPLATE_END

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, that's right. Fixed.

…akes

While implementing #848 I made a couple typos in SQL queries at a few
points where I made some minor problem in a template tag like putting in
`/* TEMPLATE schema */` instead of `/* TEMPLATE: schema */`.

sqlctemplate isn't a real compiler, so instead of these problems getting
flagged, they're silently ignored, and this is made even worse because
sqlc strips comments from queries so we often end up with absolutely
nothing to debug with. This results in a long, frustrating debugging
experience.

Here, perform a post-replace match to check for obvious problems and
tell the caller about them immediately. It's not perfect, but will save
time in diagnosing common problems.
@brandur brandur force-pushed the brandur-error-on-obvious-template-problems branch from abf7b28 to dec0cca Compare April 28, 2025 05:44
@brandur brandur merged commit 5914a2c into master Apr 28, 2025
10 checks passed
@brandur brandur deleted the brandur-error-on-obvious-template-problems branch April 28, 2025 05:52
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.

2 participants