diff --git a/ql/src/go.qll b/ql/src/go.qll index 0bce4c7d6b7..f4f459f2e48 100644 --- a/ql/src/go.qll +++ b/ql/src/go.qll @@ -7,6 +7,7 @@ import semmle.go.AST import semmle.go.Comments import semmle.go.Concepts import semmle.go.Decls +import semmle.go.Errors import semmle.go.Expr import semmle.go.Files import semmle.go.GoMod diff --git a/ql/src/semmle/go/Errors.qll b/ql/src/semmle/go/Errors.qll new file mode 100644 index 00000000000..8beb6877f2f --- /dev/null +++ b/ql/src/semmle/go/Errors.qll @@ -0,0 +1,50 @@ +/** Provides classes for working with Go frontend errors recorded during extraction. */ + +import go + +/** + * An error reported by the Go frontend during extraction. + */ +class Error extends @error { + /** Gets the message associated with this error. */ + string getMessage() { errors(this, _, result, _, _, _, _, _, _) } + + /** Gets the raw position reported by the frontend for this error. */ + string getRawPosition() { errors(this, _, _, result, _, _, _, _, _) } + + /** Gets the package in which this error was reported. */ + Package getPackage() { errors(this, _, _, _, _, _, _, result, _) } + + /** Gets the index of this error among all errors reported for the same package. */ + int getIndex() { errors(this, _, _, _, _, _, _, _, result) } + + /** + * Holds if this element is at the specified location. + * The location spans column `startcolumn` of line `startline` to + * column `endcolumn` of line `endline` in file `filepath`. + * For more information, see + * [LGTM locations](https://lgtm.com/help/ql/locations). + */ + predicate hasLocationInfo( + string filepath, int startline, int startcolumn, int endline, int endcolumn + ) { + errors(this, _, _, _, filepath, startline, startcolumn, _, _) and + endline = startline and + endcolumn = startcolumn + } + + /** Gets a textual representation of this error. */ + string toString() { result = getMessage() } +} + +/** An error reported by an unknown part of the Go frontend. */ +class UnknownError extends Error, @unknownerror { } + +/** An error reported by the Go frontend driver. */ +class ListError extends Error, @listerror { } + +/** An error reported by the Go parser. */ +class ParseError extends Error, @parseerror { } + +/** An error reported by the Go type checker. */ +class TypeError extends Error, @typeerror { }