Skip to content

feat: add duplicate workflow name validation and localization support#578

Merged
BugsGuru merged 1 commit intomainfrom
commit/optimize-error
Mar 10, 2026
Merged

feat: add duplicate workflow name validation and localization support#578
BugsGuru merged 1 commit intomainfrom
commit/optimize-error

Conversation

@winfredLIN
Copy link
Collaborator

@winfredLIN winfredLIN commented Mar 10, 2026

  • Introduced a new error for duplicate data export workflow names in the business logic.
  • Enhanced the DMSController to return a localized error message when a duplicate name is detected.
  • Implemented a method in the WorkflowRepo to check for existing workflow names.
  • Updated localization files to include messages for duplicate workflow name errors in both English and Chinese.

关联的 issue

https://github.com/actiontech/dms-ee/issues/746

link https://github.com/actiontech/dms-ee/pull/747

描述你的变更

确认项(pr提交后操作)

Tip

请在指定复审人之前,确认并完成以下事项,完成后✅


  • 我已完成自测
  • 我已记录完整日志方便进行诊断
  • 我已在关联的issue里补充了实现方案
  • 我已在关联的issue里补充了测试影响面
  • 我已确认了变更的兼容性,如果不兼容则在issue里标记 not_compatible
  • 我已确认了是否要更新文档,如果要更新则在issue里标记 need_update_doc

- Introduced a new error for duplicate data export workflow names in the business logic.
- Enhanced the DMSController to return a localized error message when a duplicate name is detected.
- Implemented a method in the WorkflowRepo to check for existing workflow names.
- Updated localization files to include messages for duplicate workflow name errors in both English and Chinese.
@LordofAvernus LordofAvernus requested review from BugsGuru and removed request for BugsGuru March 10, 2026 07:02
@github-actions
Copy link

PR Reviewer Guide 🔍

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

错误处理

在检测到重复工单名称错误时,将错误信息本地化后返回。建议复查此处是否与后续错误码映射和整体异常处理保持一致,确保错误包装的一致性。

if errors.Is(err, biz.ErrDataExportWorkflowNameDuplicate) {
	return NewErrResp(c, errors.New(locale.Bundle.LocalizeMsgByCtx(c.Request().Context(), locale.DataExportWorkflowNameDuplicateErr)), apiError.BadRequestErr)
}
错误包装

在返回添加工单错误时,使用 fmt.Errorf 的 %w 格式包裹错误。建议确认该错误包装方式是否与全局错误处理策略一致。

return nil, fmt.Errorf("add data export workflow failed: %w", err)
重复校验逻辑

在查询重复工单名称时,事务和查询逻辑的实现需要在高并发场景下确保数据一致性。建议对查询条件和事务处理进行复查以防误判。

func (d *WorkflowRepo) IsDataExportWorkflowNameDuplicate(ctx context.Context, projectUID, workflowName string) (bool, error) {
	var count int64
	if err := transaction(d.log, ctx, d.db, func(tx *gorm.DB) error {
		if err := tx.WithContext(ctx).Model(&model.Workflow{}).
			Where("project_uid = ? AND name = ?", projectUID, workflowName).
			Count(&count).Error; err != nil {
			return fmt.Errorf("failed to check workflow name duplicate: %v", err)
		}
		return nil
	}); err != nil {
		return false, err
	}
	return count > 0, nil
}

@github-actions
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
优化错误包装

建议使用 %w 替换 %v 来包装错误,以便保留错误链信息,便于追踪根本原因。此外,这有助于与其他地方采用错误包装一致,保证错误处理的一致性。

internal/dms/storage/workflow.go [50-54]

 if err := tx.WithContext(ctx).Model(&model.Workflow{}).
 		Where("project_uid = ? AND name = ?", projectUID, workflowName).
 		Count(&count).Error; err != nil {
-			return fmt.Errorf("failed to check workflow name duplicate: %v", err)
+			return fmt.Errorf("failed to check workflow name duplicate: %w", err)
 		}
Suggestion importance[1-10]: 6

__

Why: The suggestion improves error wrapping by replacing %v with %w, retaining error chain information, but it only touches a minor stylistic issue.

Low

@BugsGuru BugsGuru merged commit df4a1a4 into main Mar 10, 2026
1 check passed
@BugsGuru BugsGuru deleted the commit/optimize-error branch March 10, 2026 07:04
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