没有不值得去解决的问题,也没有不值得去学习的技术!

Analyzing and Improving Unfriendly Error Messages When Uniqueness Validation Fails in Yii 2.0

From this, I concluded that the reason the uniqueness validation failure prompt became more user-friendly was that Yii Framework had been upgraded from version 2.0.15.1 to 2.0.31. To determine which intermediate version caused this, I checked the GitHub log for /vendor/yiisoft/yii2/messages/zh-CN/yii.php. Reference URL: https://github.com/yiisoft/yii2/commit/b8a3fa4ff96cb80d77fcf8003163c9001770ae8b#diff-9083c63f8544587712f4083785a317cf . In commit b8a3fa, a new line was added. It was committed on April 5, 2018

1. A tester submitted a bug report stating that the prompt for a failed uniqueness validation was not user-friendly (it mixed Chinese and English, making it difficult for users to understand). The prompt message is shown in Figure 1.

A tester submitted a bug report stating that the prompt for a failed uniqueness validation was not user-friendly (it mixed Chinese and English, making it difficult for users to understand)
Figure 1

2. While preparing to reproduce the issue in the latest version of the local environment, I unexpectedly found that the prompt messages were already displayed entirely in Chinese. The prompt message is shown in Figure 2.

While preparing to reproduce the issue in the latest version of the local environment, I unexpectedly found that the prompt messages were already displayed entirely in Chinese
Figure 2
JSON

{
    "code": 226004,
    "message": "数据验证失败:租户ID, 栏目名称, 是否被删除 与 删除时间 的值 \"\"015ce30b116ce86058fa6ab4fea4ac63\"-\"深圳市9\"-\"0\"-\"0\"\" 已经被占用了。"
}

3. I checked the relevant program files and found that no adjustments had been made to the prompt messages. Reviewing the Git log, I found the commit: updated Yii 2 to the latest version by running composer update, which upgraded Yii Framework from version 2.0.15.1 to 2.0.31. I initially suspected that the Yii framework upgrade had consequently adjusted the prompt messages. This is shown in Figure 3.

I checked the relevant program files and found that no adjustments had been made to the prompt messages. Reviewing the Git log, I found the commit: updated Yii 2 to the latest version by running composer update, which upgraded Yii Framework from version 2.0.15.1 to 2.0.31. I initially suspected that the Yii framework upgrade had consequently adjusted the prompt messages.
Figure 3

4. The deployment tag 1.10.4-alpha.5 is the pre-upgrade version. The bug was successfully reproduced, as shown in Figure 4.

The deployment tag 1.10.4-alpha.5 is the pre-upgrade version. The bug was successfully reproduced
Figure 4
JSON

{
    "code": 226004,
    "message": "数据验证失败:The combination \"015ce30b116ce86058fa6ab4fea4ac63\"-\"深圳市1\"-\"0\"-\"0\" of 租户ID, 栏目名称, 是否被删除 and 删除时间 has already been taken."
}

5. The deployment tag 1.10.4-alpha.6 is the post-upgrade version. The bug has been fixed, the English text has disappeared, and the prompt message is more user-friendly, as shown in Figure 5.

The deployment tag 1.10.4-alpha.6 is the post-upgrade version. The bug has been fixed, the English text has disappeared, and the prompt message is more user-friendly
Figure 5
JSON

{
    "code": 226004,
    "message": "数据验证失败:租户ID, 栏目名称, 是否被删除 与 删除时间 的值 \"\"015ce30b116ce86058fa6ab4fea4ac63\"-\"深圳市1\"-\"0\"-\"0\"\" 已经被占用了。"
}

6. From this, I concluded that the reason the uniqueness validation failure prompt became more user-friendly was that Yii Framework had been upgraded from version 2.0.15.1 to 2.0.31. To determine which intermediate version caused this, I checked the GitHub log for /vendor/yiisoft/yii2/messages/zh-CN/yii.php. Reference URL: https://github.com/yiisoft/yii2/commit/b8a3fa4ff96cb80d77fcf8003163c9001770ae8b#diff-9083c63f8544587712f4083785a317cf . In commit b8a3fa, a new line was added. It was committed on April 5, 2018, as shown in Figure 6.

From this, I concluded that the reason the uniqueness validation failure prompt became more user-friendly was that Yii Framework had been upgraded from version 2.0.15.1 to 2.0.31. To determine which intermediate version caused this, I checked the GitHub log for /vendor/yiisoft/yii2/messages/zh-CN/yii.php. Reference URL: https://github.com/yiisoft/yii2/commit/b8a3fa4ff96cb80d77fcf8003163c9001770ae8b#diff-9083c63f8544587712f4083785a317cf . In commit b8a3fa, a new line was added. It was committed on April 5, 2018
Figure 6
PHP

    'The combination {values} of {attributes} has already been taken.' => '{attributes} 的值 "{values}" 已经被占用了。',

7. Reference URL: https://github.com/yiisoft/yii2/tree/2.0.16/framework/messages/zh-CN . Commit b8a3fa exists in Tag 2.0.16. Therefore, it can be confirmed that Yii Framework version 2.0.16 has already optimized the corresponding prompt messages, as shown in Figure 7.

Reference URL: https://github.com/yiisoft/yii2/tree/2.0.16/framework/messages/zh-CN . Commit b8a3fa exists in Tag 2.0.16. Therefore, it can be confirmed that Yii Framework version 2.0.16 has already optimized the corresponding prompt messages.
Figure 7

关于作者 · 持续学习与技术实践

我是一名拥有 15 年以上开发经验的技术从业者,自 2013 年起持续运营个人技术博客,记录工作与个人项目中遇到的真实问题,以及解决问题过程中的探索、实践和思考。

除了技术写作,我也在持续开发和维护自己的独立项目,探索新技术和新工具在实际场景中的应用。我始终相信,没有不值得去解决的问题,也没有不值得去学习的技术。

如果这篇文章对你有所帮助,欢迎浏览博客中的其他文章,也欢迎交流技术经验与想法。

关于我  ·  GitHub  ·  邮件联系