mirror of
https://github.com/github/codeql.git
synced 2026-01-29 22:32:58 +01:00
Add QL library for working with Go frontend errors.
This commit is contained in:
@@ -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
|
||||
|
||||
50
ql/src/semmle/go/Errors.qll
Normal file
50
ql/src/semmle/go/Errors.qll
Normal file
@@ -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 { }
|
||||
Reference in New Issue
Block a user