report
Types
Some additional information attached to the end of a report.
pub type Info {
Text(message: String)
Note(prefix: String, message: String)
Rows(rows: List(#(String, String)), divider: String)
}
Constructors
-
Text(message: String)
Results in the text passed in without any prefix. This is an improvement over simply appending text to the generated report since the message will be wrapped nicely on multiple lines as needed.
-
Note(prefix: String, message: String)
Results in
<prefix>: <message>
-
Rows(rows: List(#(String, String)), divider: String)
Create a formatted group of rows of text. The divider string is inserted between each row header and content.
Rows( rows: [ #("expected type", "SomeType"), #("found type", "SomeOtherType"), ], divider: " = ", )
Rendered as (also would have additional styling):
expected type = SomeType found type = SomeOtherType
Functions
pub fn context_label(
message message: String,
from start: #(Int, Int),
to end: #(Int, Int),
) -> Label
Create a context label. Context labels provide locational context to the report, normally by pointing out landmarks in the source code such as a surrounding list or function. This can be especially useful when reporting parsing errors:
foo([1, 2 3])
┬ ━ I wanted a comma
╰╴ in this list
pub fn error(
file file: String,
source source: String,
message message: String,
labels labels: List(Label),
info info: List(Info),
) -> Report
Create an error report.
Parameters:
file
: The name or path of the source file.source
: The source code of the file.message
: A short message describing the report, such asType mismatch
.labels
: A list of labels to annotate the source code. If multiple labels in the list overlap, the first in the list will take precedence.info
: A list ofInfo
messages to add to the end of the report.
pub fn info(
file file: String,
source source: String,
message message: String,
labels labels: List(Label),
info info: List(Info),
) -> Report
Create an informational report.
Parameters:
file
: The name or path of the source file.source
: The source code of the file.message
: A short message describing the report.labels
: A list of labels to annotate the source code. If multiple labels in the list overlap, the first in the list will take precedence.info
: A list ofInfo
messages to add to the end of the report.
pub fn primary_label(
message message: String,
from start: #(Int, Int),
to end: #(Int, Int),
) -> Label
Create a primary label. Primary labels represent the main reason for the report (though multiple can be included as needed). The first primary label in the list of labels will have its location included in the report’s header.
pub fn secondary_label(
message message: String,
from start: #(Int, Int),
to end: #(Int, Int),
) -> Label
Create a secondary label. Secondary labels support the reason for the report by giving additional information and context.
pub fn to_string(report: Report, style has_style: Bool) -> String
Transform a Report
into a string, ready to be presented to the
end user. Styling is optional but recommended for most use cases.
report.error(...)
|> report.to_string(style: True)
//-> "Error: ..."
pub fn warning(
file file: String,
source source: String,
message message: String,
labels labels: List(Label),
info info: List(Info),
) -> Report
Create a warning report.
Parameters:
file
: The name or path of the source file.source
: The source code of the file.message
: A short message describing the report, such asUnused function
.labels
: A list of labels to annotate the source code. If multiple labels in the list overlap, the first in the list will take precedence.info
: A list ofInfo
messages to add to the end of the report.