Skip to content

Conversation

@iseki0
Copy link

@iseki0 iseki0 commented Jul 22, 2025

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

Provide a detailed error message during Create/Save/Update...

User Case Description

Currently the error message too simple to diagnostic what's happened.

It's relative to #7510. I don't think the code is good. But to achieve the goal, we have to change our minds on error handling.
My opinion is create a customized error type, even it's internal. But looks like you don't like it? (Of course I understand it's difficult to make decision about make the error type public or not)

@iseki0
Copy link
Author

iseki0 commented Jul 22, 2025

/reviewer @jinzhu

@jinzhu
Copy link
Member

jinzhu commented Jul 22, 2025

Hi @iseki0

I means we can rewrite more details error in each Set func like this one

return fmt.Errorf("failed to set string %v to time.Time field %s, failed to parse it as time, got error %v", v, field.Name, err)

@propel-code-bot propel-code-bot bot changed the title feat: make a more detailed error message during field value setting failed feat: Provide detailed error messages for field.Set failures Nov 20, 2025
@propel-code-bot
Copy link
Contributor

Improve error context when field.Set fails

Adds a thin wrapper around every generated field.Set function in schema/field.go to prepend the field name to any propagated error. This gives users clearer diagnostics during Create/Save/Update operations without changing the public API or the original error value (wrapped with %w).

Key Changes

• Introduced local variable oldSetter and reassigned field.Set with a closure that calls oldSetter, inspects the returned error, and if not nil wraps it using fmt.Errorf("failed to set value to field %s: %w", field.Name, err)
• Added duplicate-prevention logic that aborts wrapping when the error text already contains "to field "
• Imported strings where necessary (already present in file)

Affected Areas

schema/field.go – generation of every field.Set implementation
fallbackSetter call sites indirectly affected because wrapped errors now propagate

This summary was automatically generated by @propel-code-bot

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