iflytek/astron-agent · error
insert auth data,data must not been nil
Error message
insert auth data,data must not been nil
What it means
AuthDao.Insert refuses to execute its INSERT when the *models.Auth argument is nil. A nil Auth has no AppId/ApiKey/ApiSecret values, so the DAO fails fast rather than dereferencing nil fields in Exec.
Solutions
- Validate that *models.Auth is non-nil (and ApiKey/ApiSecret non-empty) before calling SaveApp/Insert.
- Ensure the credentials-generation step always returns a valid Auth or a propagated error so nil never reaches the DAO.
- In SaveApp, bail out of the transaction early with a clear error if auth is nil so the app insert is rolled back too.
- Log the caller path that produced the nil Auth to locate the construction bug.
Example fix
// before
id, err := authDao.Insert(auth, tx) // auth may be nil
// after
if auth == nil {
return 0, fmt.Errorf("auth credentials are required")
}
id, err := authDao.Insert(auth, tx) Defensive patterns
Strategy: validation
Validate before calling
func validAuth(a *models.Auth) bool { return a != nil && a.AppId != "" && a.ApiKey != "" && a.ApiSecret != "" } Type guard
if auth == nil {
return fmt.Errorf("auth credentials required")
} Try / catch
if err != nil {
if strings.Contains(err.Error(), "data must not been nil") {
return fmt.Errorf("auth credentials missing for app save: %w", err)
}
return err
} Prevention
- Generate AppId/ApiKey/ApiSecret in one constructor that cannot return (nil, nil).
- Validate credentials non-empty before SaveApp.
- Roll back the app insert if auth construction fails by using the shared transaction.
When it happens
Trigger: Calling Insert(nil, tx), or via SaveApp when the Auth record paired with the app was never constructed (nil pointer passed into the transaction flow).
Common situations: SaveApp builds the app row but the credentials-generation step silently returned nil auth; JSON binding to *models.Auth failed and the nil pointer flowed through; refactoring moved Auth construction behind a branch that was not taken.
Related errors
- insert app data, data must not been nil
- adopt tenant bootstrap credential failed
- check tenant bootstrap managed credential failed
- database config is nil or dbType is empty
- database password is required
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/73456c8c64a27f68.
Report an issue: GitHub.
Appendix: source
Thrown at core/tenant/internal/dao/auth_dao.go:49
updateSql := `UPDATE tb_auth SET %s `
selectSql := fmt.Sprintf(`SELECT %s FROM tb_auth `, sqlField)
countSql := `SELECT count(1) from tb_auth `
return &AuthDao{
db: db,
insertSql: insertSql,
updateSql: updateSql,
selectSql: selectSql,
countSql: countSql,
}, nil
}
func (dao *AuthDao) BeginTx() (*sql.Tx, error) {
return dao.db.GetMysql().Begin()
}
func (dao *AuthDao) Insert(data *models.Auth, tx *sql.Tx) (int64, error) {
if data == nil {
return 0, fmt.Errorf("insert auth data,data must not been nil")
}
log.Printf("insert auth sql is %s", dao.insertSql)
if tx == nil {
result, err := dao.db.GetMysql().Exec(dao.insertSql, //
data.AppId, data.ApiKey, data.ApiSecret, data.Source, data.IsDelete,
data.CreateTime, data.UpdateTime, data.Extend)
if err != nil {
log.Printf("insert auth error: %v", err)
return 0, err
}
return result.RowsAffected()
}
result, err := tx.Exec(dao.insertSql, //
data.AppId, data.ApiKey, data.ApiSecret, data.Source, data.IsDelete,
data.CreateTime, data.UpdateTime, data.Extend)
if err != nil {
log.Printf("insert auth error: %v", err)
return 0, errView on GitHub (pinned to 5e758547a8)