Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add value path in error message if schema is invalid #158

Closed
leoadonia opened this issue Oct 16, 2024 · 2 comments · Fixed by #195
Closed

Add value path in error message if schema is invalid #158

leoadonia opened this issue Oct 16, 2024 · 2 comments · Fixed by #195
Assignees
Labels
enhancement New feature or request

Comments

@leoadonia
Copy link
Collaborator

If some property is invalid in property.json, the property path should be shown in logs.

@leoadonia leoadonia added the enhancement New feature or request label Oct 16, 2024
@leoadonia leoadonia self-assigned this Oct 16, 2024
@halajohn halajohn added this to Kanban Oct 23, 2024
@leoadonia leoadonia changed the title Add value in error message if schema is invalid Add value path in error message if schema is invalid Oct 23, 2024
@leoadonia
Copy link
Collaborator Author

当 property 中的 field 的 schema 非法时, 需要在报错信息中给出路径的 field 在 property 树状结构中的路径, 方便识别. 适用于 property.json 以及 msg 中的 property.

property 自身是一个 object, 按 field 的类型分成以下情况:

  • 基础类型 (除 array 或 object 外, 包括 buf, pointer), 如:

    {
        "a": "",
        "b": 1
    }

    如果 a 的值非法, 报错信息如 a is invalid.

  • array

    • array item 是基础类型

        {
          "a": ["10"]
        }

      报错信息如 a[0] is invalid.

    • array item 是符合类型, 如 object

      {
        "a": [
           {
               "b": "1"
            }
        ]
      }

      报错信息如 a[0].b is invalid.

  • object 类型

    {
      "a": {
        "b": "",
        "c": 0
      }
    }

    报错如 a.c is invalid.

@leoadonia
Copy link
Collaborator Author

  • 补充 array 的规范:

    • array item 只能有一种类型
    • 如果 array item 的类型是 object, 从 array 角度不会要求每个 item 对应的 object 的 fields 都一致. 具体 object 的要求, 按 object 自身的 schema 来定.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
1 participant