[JSON] Display errors associated with Paths in context
authorSam McCall <sam.mccall@gmail.com>
Wed, 23 Sep 2020 22:28:52 +0000 (00:28 +0200)
committerSam McCall <sam.mccall@gmail.com>
Wed, 23 Sep 2020 22:34:11 +0000 (00:34 +0200)
commit38de1c33a8374bb16abfb024a973d851c170bafc
tree955f614f49deb9e40614f199f62a5f79b4f2318a
parent111aa4e36614d9a056cf5040d4d7bbfddeb9ebb2
[JSON] Display errors associated with Paths in context

When an error occurs processing a JSON object, seeing the actual
surrounding data helps. Dumping just the node where the problem
was identified can be too much or too little information.

printErrorContext() shows the error message in its context, as a comment.
JSON values along the path to the broken place are shown in some detail,
the rest of the document is elided. For example:

```
{
  "credentials": [
    {
      "username": /* error: expected string */ 42,
      "password": "secret"
    },
    { ... }
  ]
  "backups": { ... }
}
```

Differential Revision: https://reviews.llvm.org/D88103
llvm/include/llvm/Support/JSON.h
llvm/lib/Support/JSON.cpp
llvm/unittests/Support/JSONTest.cpp