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

Emit a better error message if a user writes a table! macro without #3708

Merged
merged 1 commit into from
Jul 24, 2023

Conversation

weiznich
Copy link
Member

id column and without explicit primary Key

Previously we did ignore that case, which resulted in the following error message:

error[E0412]: cannot find type `id` in this scope
 --> tests/fail/table_without_primary_key.rs:3:1
  |
3 | / table! {
4 | |     user {
5 | |         user_id -> Integer,
6 | |         name -> Text,
7 | |     }
8 | | }
  | |_^ help: a builtin type with a similar name exists: `i8`
  |
  = note: this error originates in the macro `table` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find value `id` in this scope
 --> tests/fail/table_without_primary_key.rs:3:1
  |
3 | / table! {
4 | |     user {
5 | |         user_id -> Integer,
6 | |         name -> Text,
7 | |     }
8 | | }
  | |_^ not found in this scope
  |
  = help: consider importing this function:
          std::process::id
  = note: this error originates in the macro `table` (in Nightly builds, run with -Z macro-backtrace for more info)

This can be confusing for new users. This commit introduces an explicit check for that case and emits an targeted error messages that makes it hopefully clear what's the problem here. It also suggests to specify the first column as primary key.

`id` column and without explicit primary Key

Previously we did ignore that case, which resulted in the following
error message:

```
error[E0412]: cannot find type `id` in this scope
 --> tests/fail/table_without_primary_key.rs:3:1
  |
3 | / table! {
4 | |     user {
5 | |         user_id -> Integer,
6 | |         name -> Text,
7 | |     }
8 | | }
  | |_^ help: a builtin type with a similar name exists: `i8`
  |
  = note: this error originates in the macro `table` (in Nightly builds, run with -Z macro-backtrace for more info)

error[E0425]: cannot find value `id` in this scope
 --> tests/fail/table_without_primary_key.rs:3:1
  |
3 | / table! {
4 | |     user {
5 | |         user_id -> Integer,
6 | |         name -> Text,
7 | |     }
8 | | }
  | |_^ not found in this scope
  |
  = help: consider importing this function:
          std::process::id
  = note: this error originates in the macro `table` (in Nightly builds, run with -Z macro-backtrace for more info)
```

This can be confusing for new users. This commit introduces an explicit
check for that case and emits an targeted error messages that makes it
hopefully clear what's the problem here. It also suggests to specify the
first column as primary key.
@weiznich weiznich requested a review from a team July 20, 2023 15:34
@Ten0
Copy link
Member

Ten0 commented Jul 23, 2023

commit message seems to be weirdly split but otherwise LGTM :)

@weiznich weiznich added this pull request to the merge queue Jul 24, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 24, 2023
@weiznich weiznich added this pull request to the merge queue Jul 24, 2023
@weiznich weiznich added the maybe backport Maybe backport this pr to the latest diesel release label Jul 24, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jul 24, 2023
@weiznich weiznich added this pull request to the merge queue Jul 24, 2023
Merged via the queue into diesel-rs:master with commit ca47924 Jul 24, 2023
32 checks passed
weiznich added a commit to weiznich/diesel that referenced this pull request Aug 18, 2023
Emit a better error message if a user writes a `table!` macro without
@weiznich weiznich mentioned this pull request Aug 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maybe backport Maybe backport this pr to the latest diesel release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants