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 message for missing semicolon in query #3851

Open
bupd opened this issue Feb 19, 2025 · 1 comment
Open

Improve error message for missing semicolon in query #3851

bupd opened this issue Feb 19, 2025 · 1 comment
Labels
📚 sqlite bug Something isn't working

Comments

@bupd
Copy link

bupd commented Feb 19, 2025

Version

1.28.0

What happened?

Currently, when there is a missing semicolon in the query, the error message indicates a "duplicate query name," which can be misleading and doesn't clearly explain the problem. It would be more helpful if the error message indicated that there is a "missing semicolon" instead, as this would provide more accurate and actionable feedback for developers.

Proposed Solution

I would suggest Instead of error message duplicate query name.

- # package
- sql/queries/windows.sql:1:1: duplicate query name: ListAllWindows
+ # package
+ sql/queries/windows.sql:1:17: missing semicolon in query: ListAllWindows

or atleast syntax error like below would be good

+ # package
+ sql/queries/windows.sql:1:17: Syntax error: ListAllWindows

missing semicolon is better error message than duplicate query name

Related Issue

Relevant log output

# package
sql/queries/windows.sql:1:1: duplicate query name: ListAllWindows

Database schema

CREATE TABLE windows (
  id INTEGER PRIMARY KEY AUTOINCREMENT,
  wm_class TEXT UNIQUE NOT NULL,
  is_active INTEGER NOT NULL,
  created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
  FOREIGN KEY(wm_class) REFERENCES wmclass(wm_class)
);

SQL queries

-- name: ListAllWindows :many
SELECT * FROM windows;

-- name: AddWindows :one
INSERT OR REPLACE INTO windows (wm_class, is_active, updated_at)
VALUES (:wm_class, :is_active, :updated_at)
RETURNING *;

-- name: ListLastHourWindows :many
SELECT *
FROM windows
WHERE updated_at >= datetime('now', '-1 hour')

-- name: ListLastDayWindows :many
SELECT *
FROM windows
WHERE created_at >= DATETIME('now', '-1 day');

Configuration

version: "2"
sql:
  - engine: "sqlite"
    queries: "sql/queries"
    schema: "sql/schema"
    gen:
      go:
        out: "internal/database"

Playground URL

https://play.sqlc.dev/p/6f1378cad4cd769f36f69593f2a1ab25118baca1b9a0639bd8d3d91448384084

What operating system are you using?

Linux

What database engines are you using?

SQLite

What type of code are you generating?

Go

@bupd bupd added the bug Something isn't working label Feb 19, 2025
@bupd
Copy link
Author

bupd commented Feb 19, 2025

BTW thanks for making this amazing library

@dosubot dosubot bot added the 📚 sqlite label Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📚 sqlite bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant