title: How can I check for errors in CRUD operations using GORM?
body: <p>The <a href="https://github.com/jinzhu/gorm/wiki/Basic-CRUD" rel="noreferrer">official documentation</a> for GORM demonstrates a way in which one can test for the existence of a record, i.e.:</p>
  
  <pre><code>user := User{Name: "Jinzhu", Age: 18, Birthday: time.Now()}
  
  // returns true if record hasn’t been saved (primary key `Id` is blank)
  db.NewRecord(user) // =&gt; true
  
  db.Create(&amp;user)
  
  // will return false after `user` created
  db.NewRecord(user) // =&gt; false
  </code></pre>
  
  <p>This can be used to test indirectly for errors in record creation but reports no useful information in the event of a failure.</p>
  
  <p>Having checked the <a href="https://github.com/jinzhu/gorm/blob/master/callback_create.go#L21" rel="noreferrer">source code for <code>db.Create</code></a>, there seems to be some sort of stack-frame inspection that checks for errors before proceeding, meaning that transactional errors will fail silently:</p>
  
  <pre><code>func Create(scope *Scope) {
      defer scope.Trace(NowFunc())
  
      if !scope.HasError() {
          // actually perform the transaction
      }
  }
  </code></pre>
  
  <ul>
  <li>Is this a bug, or am I missing something?</li>
  <li><strong>How can/should I be informed of a failed transaction?</strong></li>
  <li>Where can I get useful debugging information?</li>
  </ul>