flipped-aurora/gin-vue-admin · error

请不要搞事

Error message

请不要搞事

What it means

DeleteSysDictionary first loads the dictionary (with its details) by the given ID. If the record is not found, it returns this playful message instead of a raw gorm.ErrRecordNotFound, signaling the caller tried to delete a dictionary that doesn't exist. Any other DB error is passed through unchanged.

Source

Thrown at server/service/system/sys_dictionary.go:43

func (dictionaryService *DictionaryService) CreateSysDictionary(ctx context.Context, sysDictionary system.SysDictionary) (system.SysDictionary, error) {
	if (!errors.Is(global.GVA_DB.WithContext(ctx).First(&system.SysDictionary{}, "type = ?", sysDictionary.Type).Error, gorm.ErrRecordNotFound)) {
		return system.SysDictionary{}, errors.New("存在相同的type,不允许创建")
	}
	// Create 会把自增主键回写进 sysDictionary,直接返回创建后的实体(含 ID),免去调用方二次回查
	err := global.GVA_DB.WithContext(ctx).Create(&sysDictionary).Error
	return sysDictionary, err
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteSysDictionary
//@description: 删除字典数据
//@param: sysDictionary model.SysDictionary
//@return: err error

func (dictionaryService *DictionaryService) DeleteSysDictionary(ctx context.Context, sysDictionary system.SysDictionary) (err error) {
	err = global.GVA_DB.WithContext(ctx).Where("id = ?", sysDictionary.ID).Preload("SysDictionaryDetails").First(&sysDictionary).Error
	if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
		return errors.New("请不要搞事")
	}
	if err != nil {
		return err
	}
	err = global.GVA_DB.WithContext(ctx).Delete(&sysDictionary).Error
	if err != nil {
		return err
	}

	if sysDictionary.SysDictionaryDetails != nil {
		return global.GVA_DB.WithContext(ctx).Where("sys_dictionary_id=?", sysDictionary.ID).Delete(sysDictionary.SysDictionaryDetails).Error
	}
	return
}

//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateSysDictionary
//@description: 更新字典数据

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Refresh the dictionary list and confirm the record still exists before deleting
  2. Verify the ID being sent is the actual dictionary ID (not 0/undefined)
  3. Treat this as an idempotent outcome if the goal is 'ensure deleted' — ignore or handle gracefully in the caller
Defensive patterns

Strategy: try-catch

Validate before calling

var count int64
global.GVA_DB.Model(&system.SysDictionary{}).Where("id = ?", dict.ID).Count(&count)
if count == 0 {
    return errors.New("dictionary not found; nothing to delete")
}

Try / catch

if err := dictService.DeleteSysDictionary(ctx, dict); err != nil {
    if err.Error() == "请不要搞事" {
        // record already gone: treat as idempotent success or refresh list
        return nil
    }
    return err
}

Prevention

When it happens

Trigger: Calling DeleteSysDictionary with a SysDictionary whose ID doesn't exist — deleted already, wrong ID, or ID=0 from an unbound request.

Common situations: Double-click delete (second request hits an already-deleted row); stale list data after another admin deleted it; API consumers passing fabricated IDs; tests with unpersisted structs.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/3ae9717785b4b254. Report an issue: GitHub.