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

Add context to RecordNotSaved/RecordNotDestroyed error messages #452

Merged

Conversation

pyrsmk
Copy link
Contributor

@pyrsmk pyrsmk commented Jul 19, 2021

Hello,

I struggled to display error messages from Granite when testing my code. The RecordNotSaved and RecordNotDestroyed messages are too generic and do not provide any clue about what is going on when an error is triggered when calling save! or destroy!.

We could, indeed, call save instead of save! and collect those error messages. But it would be cumbersome and need to add boilerplate everywhere. IMHO, it is usually simpler (and preferred) to manage exceptions.

So, I've added the message of the first error in the model to ease the feedback loop and have some understandings on the error directly instead of having to add code around to know what is the real issue.

Please let me know if you disagree with this and if you would see a better implementation.

Cheers!

@crimson-knight crimson-knight merged commit d9fca08 into amberframework:master Apr 24, 2023
crimson-knight added a commit that referenced this pull request May 3, 2023
* Add a check to ensure created_at and updated_at are Time

If a column is named `created_at` or `updated_at` is not a type `Time?`, then the following occurs:

```There was a problem expanding macro 'macro_4801706624'

Code in lib/granite/src/granite/transactions.cr:82:5

 82 | {% if @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.name.stringify).includes? "created_at" %}
      ^
Called macro defined in lib/granite/src/granite/transactions.cr:82:5

 82 | {% if @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.name.stringify).includes? "created_at" %}

Which expanded to:

 > 1 |
 > 2 |       if mode == :create
 > 3 |         @created_at = time.at_beginning_of_second
                                  ^---------------------
```

this simply adds a type check.

* fix allowing enum columns

* ameba fixes

* fix build_find_by_clause for bool values

* minor update

* Fix issue where primary key can be pushed twice on create

* fix infinate recusion when searching with enum

* add retry to adapter base

* add retry to adapters

* minor update

* add support for querying with Array(UUID)

* format docs

* FIX: add converter to read_attribute

* Fix for type declaration in has_one

* Fix callback runs on #import

* more has_one fixes; fixes for through associations

* small formatting fixes

* fix passing primary_key to has_one

* Add to docs (#446)

* Quote fields in PG query assembler

* Created converter for PG Enums that are returned as bytes

* Quote table names in adapter methods only if not already quoted

* Check if table/column string has already been quoted

* Quote foreign key

* Quote fields in query assemblers

* added some docs

* Created converter for Postgres enum arrays

* Incorrect variable name

* Added target key to association collection for many relations type

* Added truncate function for postgres adapter

* Removed unrequired parameter

* Rogue value in log for truncate

* Added truncate method for models

* Add JsonString converter

* Must use chars to check string index equality

* add note for custom select macro

* removed some other commits

* removed changes from other pr

* removed work from other pr

* removed work from other pr

* removed commits from other pr

---------

Co-authored-by: ionica21 <ionicat@windowslive.com>

* add support for foreign key converters (#438)

Co-authored-by: Joakim Repomaa <mail@jreinert.com>

* fix build_find_by_clause for bool values (#455)

* Add context to RecordNotSaved/RecordNotDestroyed error messages (#452)

* Add a check to ensure created_at and updated_at are Time (#454)

If a column is named `created_at` or `updated_at` is not a type `Time?`, then the following occurs:

```There was a problem expanding macro 'macro_4801706624'

Code in lib/granite/src/granite/transactions.cr:82:5

 82 | {% if @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.name.stringify).includes? "created_at" %}
      ^
Called macro defined in lib/granite/src/granite/transactions.cr:82:5

 82 | {% if @type.instance_vars.select { |ivar| ivar.annotation(Granite::Column) }.map(&.name.stringify).includes? "created_at" %}

Which expanded to:

 > 1 |
 > 2 |       if mode == :create
 > 3 |         @created_at = time.at_beginning_of_second
                                  ^---------------------
```

this simply adds a type check.

* small formatting fixes

* fix passing primary_key to has_one

* fix spec: Granite no longer escapes strings, but passes them to the underlying adapter

* Fix yaml spec to ignore whitespaces

* working mysql spec tests

* spec updates

* add github workflows (#1)

* update docker to use crystal 1.8 and added github action
* fix workflow if statements
* split workflow into separate jobs for each database
* workflow: fix missing envs
* workflow: add psql db var
* attempt to use workflow services
* split tests by database to speed things up

* fix sql test

* comment out workflow schedule

* re-enable ameba

---------

Co-authored-by: Seth T <crimsonknightstudios@gmail.com>
Co-authored-by: Richard Howell-Peak <development@richardhowellpeak.com>
Co-authored-by: ionica21 <ionicat@windowslive.com>
Co-authored-by: Joakim Repomaa <mail@j.repomaa.com>
Co-authored-by: Joakim Repomaa <mail@jreinert.com>
Co-authored-by: Aurélien Delogu <aurelien.delogu@gmail.com>
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.

None yet

2 participants