Skip to content

Improve error message for missing semicolon in query #3851

Open
@bupd

Description

@bupd

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions