<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/59664>59664</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [MLIR] AsmParser doesn't allow catching errors nicely
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            mlir:core
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          lattner
      </td>
    </tr>
</table>

<pre>
    MLIR provides helper functions in DialectSymbolParser.cpp (not sure why they are here, but alas) like `mlir::parseAttribute` which are handy for parsing fragments of MLIR, unfortunately this is implemented with parseSymbol above, which has:

```
  ...
 SourceMgrDiagnosticHandler handler(
 const_cast<llvm::SourceMgr &>(parser.getSourceMgr()),
 parser.getContext());
  Token startTok = parser.getToken();
  T symbol = parserFn(parser);
```

The consequence of this design is that calling this on invalid IR will /always/ print to the console with caret diagnostics.  This is very hostile to library-based design.  I think that "handler" should just be removed, because then the error message will be handed to the MLIR diagnostic handler machinery, and clients can catch it and do whatever they want with it.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxcVE1v4zgM_TXKhajhyI7THHzoNBtsgR1gMdP7gpYYW1NZ8kp0sv73C8lpUgwgKB8knx7JR2KMpndErdh9E7vjBmcefGgtMjsKm87rpf3-19sPmIK_GE0RBrITBTjPTrHxLoJxcDRoSfHPZey8_RtDpFCoaQIhn51niHMguA4L8EALYCAYKJCQr9DNDGgxCnkAaz4IRFOO1gRRvYjqZUpIL8zBdDOTaEq4DkYNKwI6vcDZB0hexvVwDtiP5DiCP0PinB6Y3dkHnh0y2fS-iZDOOFlKvqThanjIGLTSB-z8JZNbHxswJjblUZSfd1PeTv4JUBTF7etPPwdF3_twNNg7H9moP9FpSyETthSEfL75Ku8i_6Mwsqherb2Ma9J3CBCyEdUfQj5Pa0V74rsxwchDPq83vIfXq3dM__HDp_r2SfXdf5CDyBj43X-AqI5f4rLxFvUlBOJamIfzyd1ZffX9rTDr_T5QTpX-nckpSs3JbdCUlJe6wQMyKLQ2dTHbvAPjLmiNhrcfcDXWgpAntFdcopAnmIJxDOyToDK4t7Q2UmEgBn2vfiwA3m9dv1BYYEh_W0rB1nQBw_LUYSR941MAvCUO7mOlJaS8N05CHPxsNfyaI0NHEGj0F9JZyKRwjpQIucyKQvABRooRe1pT6FbVkv5kngfrwfVTIjCiGoyjsCRkdBqUNVnYCh0oZDWA4WzQHq4DMl0orMN1RcdrJQwXG91W-lAdcEPtttlv97tG1vvN0FJXlee6bnbnEve16rr9tsSzrMrDtj7out6YVpZSbqWsyrKuy32hSXX1lpo9Kn2QzwdRlzSisUUSbuFDvzExztTuDk1Tbyx2ZGPeKVLe5ln5NPIyLZnQpqinbu6jqEtrIscHDhu2eR3lEd4d4SWO60oB7Sk6IfdpZ1h_XUuRRJOLHcEZRXbZzMG2A_OU51aehDz1hoe5K5QfhTzlUVs_nqbgf5FiIU-ZfhJXzuD_AAAA__9TXa7A">