An open API service providing package, version and dependency metadata of many open source software ecosystems and registries.

Top 8.5% on proxy.golang.org
Top 4.7% dependent repos on proxy.golang.org

proxy.golang.org : github.com/rhysd/locerr

Package locerr is a small library to make an error with source code location information. It provides a struct to represent a source file, a specific position in code and an error related to specific range or position in source. It's important to make a good error when compilation or execution errors found. locerr helps it. This library is actually used in some my compiler implementation. Repository: https://github.com/rhysd/locerr At first you should gain entire source as *Source instance. You can get *Source instance from file (NewSourceFromFile) or stdin (NewSourceFromStdin) also. Let's say to find an error at some range in the source. ErrorIn or other factory functions make a new error instance with the range. Error instance implements error interface so it can be handled like other error types. Assume that you find additional information (location of variable and its type). Then you can add some notes to the error. Notes can be added by wrapping errors like pkg/errors library. Finally you can see the result! err.Error() gets the error message as string. Note that this is only for non-Windows OS. It should output following: To support Windows, please use PrintToFile() method. It directly writes the error message into given file. This supports Windows and is useful to output from stdout or stderr. Labels such as 'Error:' or 'Notes:' are colorized. Main error message is emphasized with bold font. And source code location information (file name, line and column) is added with gray text. If the error has range information, the error shows code snippet which caused the error at the end of error message Colorized output can be seen at https://github.com/rhysd/ss/blob/master/locerr/output.png?raw=true If you have only one position information rather than two, 'start' position and 'end' position, ErrorAt() is available instead of ErrorIn() ErrorAt() takes one Pos instance. In this case, line snippet is shown in error message. `pos.Line` is used to get line from source text. It should output following:

Registry - Source - Documentation - JSON
purl: pkg:golang/github.com/rhysd/locerr
Keywords: error , go , golang , source
License: MIT
Latest release: almost 8 years ago
First release: almost 8 years ago
Namespace: github.com/rhysd
Dependent repositories: 1
Stars: 16 on GitHub
Forks: 2 on GitHub
See more repository details: repos.ecosyste.ms
Last synced: about 2 months ago

    Loading...
    Readme
    Loading...