qitab / cl-protobufs

Common Lisp protocol buffer implementation.
MIT License
84 stars 18 forks source link

Error Message Best Practices #414

Closed copybara-service[bot] closed 1 year ago

copybara-service[bot] commented 1 year ago

Error Message Best Practices

The function report-error-with-line is designed to report errors in a provided stream. It calculates the line number and character position of the error in the stream. Then it constructs a visual string with a caret (^) marking the error position on the line.

Initially stores the error's file position in the stream and then iterates over the stream from the beginning, line by line, until it reaches the error's position or the end of the file. During this iteration, it keeps track of the current line, line number, and starting position of the line. After finding the line containing the error, it calculates the column of the error within that line. The function then constructs a visual marker to indicate the error's position on the line, and calls protobuf-error to output the error message, line number, line content, and the visual marker.