Struct ara_reporting::issue::Issue
source · pub struct Issue {
pub severity: IssueSeverity,
pub code: Option<String>,
pub message: String,
pub source: Option<(String, usize, usize)>,
pub annotations: Vec<Annotation>,
pub notes: Vec<String>,
}
Fields§
§severity: IssueSeverity
§code: Option<String>
§message: String
§source: Option<(String, usize, usize)>
§annotations: Vec<Annotation>
§notes: Vec<String>
Implementations§
source§impl Issue
impl Issue
A report issue.
An issue is a single error or warning in a report.
Example:
use ara_reporting::issue::Issue;
let issue = Issue::error("0003", "standalone type `void` cannot be part of a union")
.with_source("main.ara", 10, 14)
.with_annotation(
Annotation::secondary("main.ara", 9, 10)
.with_message("union type starts here")
)
.with_note("`void`, `never`, and `mixed` are standalone types and cannot be part of a union, or an intersection")
.with_note("consider using `null` instead of `void`");
sourcepub fn new<M: Into<String>>(severity: IssueSeverity, message: M) -> Self
pub fn new<M: Into<String>>(severity: IssueSeverity, message: M) -> Self
Create a new issue with the given code and message.
sourcepub fn error<C: Into<String>, M: Into<String>>(code: C, message: M) -> Self
pub fn error<C: Into<String>, M: Into<String>>(code: C, message: M) -> Self
Create a new error issue with the given code and message.
Example:
use ara_reporting::issue::Issue;
use ara_reporting::issue::IssueSeverity;
let issue = Issue::error("0003", "...")
.with_source("main.ara", 10, 11);
assert_eq!(issue.severity, IssueSeverity::Error);
Examples found in repository?
examples/cross_file.rs (line 41)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![
Source::new(
SourceKind::Script,
"src/main.ara",
r#"
use function Math\add;
function main(): int {
$value = add(1, '2');
$value
}
"#,
),
Source::new(
SourceKind::Script,
"vendor/some-vendor/some-lib/src/add.ara",
r#"
namespace Math;
function add(int $a, int $b): int {
return $a + $b;
}
"#,
),
]);
let report = Report::new().with_issue(
Issue::error("", "mismatched types expected `{int}`, found `{string}`")
.with_source("src/main.ara", 68, 71)
.with_annotation(
Annotation::secondary("src/main.ara", 61, 64)
.with_message("arguments to this function are incorrect"),
)
.with_annotation(
Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
.with_message("function defined here"),
)
.with_note(
"you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
),
);
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
More examples
examples/compact.rs (line 42)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![
Source::new(
SourceKind::Script,
"src/main.ara",
r#"
use function Math\add;
function main(): int {
$value = add(1, '2');
$value
}
"#,
),
Source::new(
SourceKind::Script,
"vendor/some-vendor/some-lib/src/add.ara",
r#"
namespace Math;
function add(int $a, int $b): int {
return $a + $b;
}
"#,
),
]);
let report = Report::new().with_issue(
Issue::error("", "mismatched types expected `{int}`, found `{string}`")
.with_source("src/main.ara", 68, 71)
.with_annotation(
Annotation::secondary("src/main.ara", 61, 64)
.with_message("arguments to this function are incorrect"),
)
.with_annotation(
Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
.with_message("function defined here"),
)
.with_note(
"you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
),
);
let builder = ReportBuilder::new(&map)
.with_charset(CharSet::Unicode)
.with_colors(ColorChoice::Always)
.with_style(DisplayStyle::Compact);
builder.print(&report)
}
examples/comfortable.rs (line 42)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![
Source::new(
SourceKind::Script,
"src/main.ara",
r#"
use function Math\add;
function main(): int {
$value = add(1, '2');
$value
}
"#,
),
Source::new(
SourceKind::Script,
"vendor/some-vendor/some-lib/src/add.ara",
r#"
namespace Math;
function add(int $a, int $b): int {
return $a + $b;
}
"#,
),
]);
let report = Report::new().with_issue(
Issue::error("", "mismatched types expected `{int}`, found `{string}`")
.with_source("src/main.ara", 68, 71)
.with_annotation(
Annotation::secondary("src/main.ara", 61, 64)
.with_message("arguments to this function are incorrect"),
)
.with_annotation(
Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
.with_message("function defined here"),
)
.with_note(
"you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
),
);
let builder = ReportBuilder::new(&map)
.with_charset(CharSet::Unicode)
.with_colors(ColorChoice::Always)
.with_style(DisplayStyle::Comfortable);
builder.print(&report)
}
examples/simple.rs (line 27)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn main() -> Result<(), Error> {
let origin = "example.ara";
let code = r#"
$b = match $a {
1 => 2,
2 => 3,
default => "string",
};
"#;
let map = SourceMap::new(vec![Source::new(SourceKind::Script, origin, code)]);
let report = Report::new()
.with_issue(
Issue::error("E0417", "`match` arms have incompatible types")
.with_source(origin, 6, 67)
.with_annotation(
Annotation::secondary(origin, 26, 27)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(origin, 38, 39)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(origin, 56, 64)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0417`"),
)
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
examples/collection.rs (line 36)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
fn main() -> Result<(), Error> {
let first_origin = "example.ara";
let first_code = r#"
$b = match $a {
1 => 2,
2 => 3,
default => "string",
};
"#;
let second_origin = "example-2.ara";
let second_code = r#"
function foo(Bar&float) {}
"#;
let map = SourceMap::new(vec![
Source::new(SourceKind::Script, first_origin, first_code),
Source::new(SourceKind::Script, second_origin, second_code),
]);
let first_report = Report::new()
.with_issue(
Issue::error("E0417", "`match` arms have incompatible types")
.with_source(first_origin, 6, 67)
.with_annotation(
Annotation::secondary(first_origin, 26, 27)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(first_origin, 38, 39)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(first_origin, 56, 64)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0417`"),
)
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let second_report = Report::new()
.with_issue(
Issue::error(
"P0015",
"scalar type `float` cannot be used in an intersection",
)
.with_source(second_origin, 18, 23)
.with_annotation(
Annotation::secondary(second_origin, 17, 19)
.with_message("scalar type `float` cannot be used in an intersection"),
)
.with_note("a scalar type is either `int`, `float`, `string`, or `bool`.")
.with_note("try using a different type for the intersection."),
)
.with_issue(Issue::bug("B0001", "failed to read the file"))
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let reports: ReportCollection = vec![&first_report, &second_report];
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&reports)
}
examples/example.rs (line 37)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![Source::inline(
SourceKind::Script,
r#"
function main(): int|string {
$a = 1;
$b = 2;
$c = $a + $b;
$b = match ($a) {
1 => 2,
2 => 3,
default => "string",
};
return $c + $b;
}
"#,
)]);
let report = Report::new()
.with_issue(
Issue::error("E123", "some error here")
.with_source(DEFAULT_NAME, 35, 41)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W123", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W124", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::note("N123", "some note here")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 121, 128)
.with_message("another annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::help("H123", "some help here")
.with_source(DEFAULT_NAME, 137, 147)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::bug("E123", "`match` arms have incompatible types")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 110, 111)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 148, 156)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0308`"),
)
.with_footer(ReportFooter::new("this is a report footer message"));
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
sourcepub fn warning<C: Into<String>, M: Into<String>>(code: C, message: M) -> Self
pub fn warning<C: Into<String>, M: Into<String>>(code: C, message: M) -> Self
Create a new warning issue with the given code and message.
Example:
use ara_reporting::issue::Issue;
use ara_reporting::issue::IssueSeverity;
let issue = Issue::warning("0003", "...")
.with_source("main.ara", 10, 11);
assert_eq!(issue.severity, IssueSeverity::Warning);
Examples found in repository?
examples/example.rs (line 45)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![Source::inline(
SourceKind::Script,
r#"
function main(): int|string {
$a = 1;
$b = 2;
$c = $a + $b;
$b = match ($a) {
1 => 2,
2 => 3,
default => "string",
};
return $c + $b;
}
"#,
)]);
let report = Report::new()
.with_issue(
Issue::error("E123", "some error here")
.with_source(DEFAULT_NAME, 35, 41)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W123", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W124", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::note("N123", "some note here")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 121, 128)
.with_message("another annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::help("H123", "some help here")
.with_source(DEFAULT_NAME, 137, 147)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::bug("E123", "`match` arms have incompatible types")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 110, 111)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 148, 156)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0308`"),
)
.with_footer(ReportFooter::new("this is a report footer message"));
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
sourcepub fn help<C: Into<String>, M: Into<String>>(code: C, message: M) -> Self
pub fn help<C: Into<String>, M: Into<String>>(code: C, message: M) -> Self
Create a new help issue with the given code and message.
Example:
use ara_reporting::issue::Issue;
use ara_reporting::issue::IssueSeverity;
let issue = Issue::help("0003", "...")
.with_source("main.ara", 10, 11);
assert_eq!(issue.severity, IssueSeverity::Help);
Examples found in repository?
examples/example.rs (line 76)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![Source::inline(
SourceKind::Script,
r#"
function main(): int|string {
$a = 1;
$b = 2;
$c = $a + $b;
$b = match ($a) {
1 => 2,
2 => 3,
default => "string",
};
return $c + $b;
}
"#,
)]);
let report = Report::new()
.with_issue(
Issue::error("E123", "some error here")
.with_source(DEFAULT_NAME, 35, 41)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W123", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W124", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::note("N123", "some note here")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 121, 128)
.with_message("another annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::help("H123", "some help here")
.with_source(DEFAULT_NAME, 137, 147)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::bug("E123", "`match` arms have incompatible types")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 110, 111)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 148, 156)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0308`"),
)
.with_footer(ReportFooter::new("this is a report footer message"));
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
sourcepub fn note<C: Into<String>, M: Into<String>>(code: C, message: M) -> Self
pub fn note<C: Into<String>, M: Into<String>>(code: C, message: M) -> Self
Create a new note issue with the given code and message.
Example:
use ara_reporting::issue::Issue;
use ara_reporting::issue::IssueSeverity;
let issue = Issue::note("0003", "...")
.with_source("main.ara", 10, 11);
assert_eq!(issue.severity, IssueSeverity::Note);
Examples found in repository?
examples/example.rs (line 61)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![Source::inline(
SourceKind::Script,
r#"
function main(): int|string {
$a = 1;
$b = 2;
$c = $a + $b;
$b = match ($a) {
1 => 2,
2 => 3,
default => "string",
};
return $c + $b;
}
"#,
)]);
let report = Report::new()
.with_issue(
Issue::error("E123", "some error here")
.with_source(DEFAULT_NAME, 35, 41)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W123", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W124", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::note("N123", "some note here")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 121, 128)
.with_message("another annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::help("H123", "some help here")
.with_source(DEFAULT_NAME, 137, 147)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::bug("E123", "`match` arms have incompatible types")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 110, 111)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 148, 156)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0308`"),
)
.with_footer(ReportFooter::new("this is a report footer message"));
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
sourcepub fn bug<C: Into<String>, M: Into<String>>(code: C, message: M) -> Self
pub fn bug<C: Into<String>, M: Into<String>>(code: C, message: M) -> Self
Create a new bug issue with the given code and message.
Example:
use ara_reporting::issue::Issue;
use ara_reporting::issue::IssueSeverity;
let issue = Issue::bug("0003", "...")
.with_source("main.ara", 10, 11);
assert_eq!(issue.severity, IssueSeverity::Bug);
Examples found in repository?
examples/collection.rs (line 71)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
fn main() -> Result<(), Error> {
let first_origin = "example.ara";
let first_code = r#"
$b = match $a {
1 => 2,
2 => 3,
default => "string",
};
"#;
let second_origin = "example-2.ara";
let second_code = r#"
function foo(Bar&float) {}
"#;
let map = SourceMap::new(vec![
Source::new(SourceKind::Script, first_origin, first_code),
Source::new(SourceKind::Script, second_origin, second_code),
]);
let first_report = Report::new()
.with_issue(
Issue::error("E0417", "`match` arms have incompatible types")
.with_source(first_origin, 6, 67)
.with_annotation(
Annotation::secondary(first_origin, 26, 27)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(first_origin, 38, 39)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(first_origin, 56, 64)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0417`"),
)
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let second_report = Report::new()
.with_issue(
Issue::error(
"P0015",
"scalar type `float` cannot be used in an intersection",
)
.with_source(second_origin, 18, 23)
.with_annotation(
Annotation::secondary(second_origin, 17, 19)
.with_message("scalar type `float` cannot be used in an intersection"),
)
.with_note("a scalar type is either `int`, `float`, `string`, or `bool`.")
.with_note("try using a different type for the intersection."),
)
.with_issue(Issue::bug("B0001", "failed to read the file"))
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let reports: ReportCollection = vec![&first_report, &second_report];
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&reports)
}
More examples
examples/example.rs (line 84)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![Source::inline(
SourceKind::Script,
r#"
function main(): int|string {
$a = 1;
$b = 2;
$c = $a + $b;
$b = match ($a) {
1 => 2,
2 => 3,
default => "string",
};
return $c + $b;
}
"#,
)]);
let report = Report::new()
.with_issue(
Issue::error("E123", "some error here")
.with_source(DEFAULT_NAME, 35, 41)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W123", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W124", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::note("N123", "some note here")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 121, 128)
.with_message("another annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::help("H123", "some help here")
.with_source(DEFAULT_NAME, 137, 147)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::bug("E123", "`match` arms have incompatible types")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 110, 111)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 148, 156)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0308`"),
)
.with_footer(ReportFooter::new("this is a report footer message"));
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
sourcepub fn from_string<M: Into<String>>(message: M) -> Self
pub fn from_string<M: Into<String>>(message: M) -> Self
Create a new error Issue
from a string.
Example:
use ara_reporting::issue::Issue;
use ara_reporting::issue::IssueSeverity;
let issue = Issue::from_string("invalid digit found in string");
assert_eq!(issue.severity, IssueSeverity::Error);
assert_eq!("invalid digit found in string", issue.message);
sourcepub fn with_annotation(self, annotation: Annotation) -> Self
pub fn with_annotation(self, annotation: Annotation) -> Self
Add an annotation to this issue.
Examples found in repository?
examples/cross_file.rs (lines 43-46)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![
Source::new(
SourceKind::Script,
"src/main.ara",
r#"
use function Math\add;
function main(): int {
$value = add(1, '2');
$value
}
"#,
),
Source::new(
SourceKind::Script,
"vendor/some-vendor/some-lib/src/add.ara",
r#"
namespace Math;
function add(int $a, int $b): int {
return $a + $b;
}
"#,
),
]);
let report = Report::new().with_issue(
Issue::error("", "mismatched types expected `{int}`, found `{string}`")
.with_source("src/main.ara", 68, 71)
.with_annotation(
Annotation::secondary("src/main.ara", 61, 64)
.with_message("arguments to this function are incorrect"),
)
.with_annotation(
Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
.with_message("function defined here"),
)
.with_note(
"you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
),
);
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
More examples
examples/compact.rs (lines 44-47)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![
Source::new(
SourceKind::Script,
"src/main.ara",
r#"
use function Math\add;
function main(): int {
$value = add(1, '2');
$value
}
"#,
),
Source::new(
SourceKind::Script,
"vendor/some-vendor/some-lib/src/add.ara",
r#"
namespace Math;
function add(int $a, int $b): int {
return $a + $b;
}
"#,
),
]);
let report = Report::new().with_issue(
Issue::error("", "mismatched types expected `{int}`, found `{string}`")
.with_source("src/main.ara", 68, 71)
.with_annotation(
Annotation::secondary("src/main.ara", 61, 64)
.with_message("arguments to this function are incorrect"),
)
.with_annotation(
Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
.with_message("function defined here"),
)
.with_note(
"you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
),
);
let builder = ReportBuilder::new(&map)
.with_charset(CharSet::Unicode)
.with_colors(ColorChoice::Always)
.with_style(DisplayStyle::Compact);
builder.print(&report)
}
examples/comfortable.rs (lines 44-47)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![
Source::new(
SourceKind::Script,
"src/main.ara",
r#"
use function Math\add;
function main(): int {
$value = add(1, '2');
$value
}
"#,
),
Source::new(
SourceKind::Script,
"vendor/some-vendor/some-lib/src/add.ara",
r#"
namespace Math;
function add(int $a, int $b): int {
return $a + $b;
}
"#,
),
]);
let report = Report::new().with_issue(
Issue::error("", "mismatched types expected `{int}`, found `{string}`")
.with_source("src/main.ara", 68, 71)
.with_annotation(
Annotation::secondary("src/main.ara", 61, 64)
.with_message("arguments to this function are incorrect"),
)
.with_annotation(
Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
.with_message("function defined here"),
)
.with_note(
"you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
),
);
let builder = ReportBuilder::new(&map)
.with_charset(CharSet::Unicode)
.with_colors(ColorChoice::Always)
.with_style(DisplayStyle::Comfortable);
builder.print(&report)
}
examples/simple.rs (lines 29-32)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn main() -> Result<(), Error> {
let origin = "example.ara";
let code = r#"
$b = match $a {
1 => 2,
2 => 3,
default => "string",
};
"#;
let map = SourceMap::new(vec![Source::new(SourceKind::Script, origin, code)]);
let report = Report::new()
.with_issue(
Issue::error("E0417", "`match` arms have incompatible types")
.with_source(origin, 6, 67)
.with_annotation(
Annotation::secondary(origin, 26, 27)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(origin, 38, 39)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(origin, 56, 64)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0417`"),
)
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
examples/collection.rs (lines 38-41)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
fn main() -> Result<(), Error> {
let first_origin = "example.ara";
let first_code = r#"
$b = match $a {
1 => 2,
2 => 3,
default => "string",
};
"#;
let second_origin = "example-2.ara";
let second_code = r#"
function foo(Bar&float) {}
"#;
let map = SourceMap::new(vec![
Source::new(SourceKind::Script, first_origin, first_code),
Source::new(SourceKind::Script, second_origin, second_code),
]);
let first_report = Report::new()
.with_issue(
Issue::error("E0417", "`match` arms have incompatible types")
.with_source(first_origin, 6, 67)
.with_annotation(
Annotation::secondary(first_origin, 26, 27)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(first_origin, 38, 39)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(first_origin, 56, 64)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0417`"),
)
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let second_report = Report::new()
.with_issue(
Issue::error(
"P0015",
"scalar type `float` cannot be used in an intersection",
)
.with_source(second_origin, 18, 23)
.with_annotation(
Annotation::secondary(second_origin, 17, 19)
.with_message("scalar type `float` cannot be used in an intersection"),
)
.with_note("a scalar type is either `int`, `float`, `string`, or `bool`.")
.with_note("try using a different type for the intersection."),
)
.with_issue(Issue::bug("B0001", "failed to read the file"))
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let reports: ReportCollection = vec![&first_report, &second_report];
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&reports)
}
examples/example.rs (lines 39-41)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![Source::inline(
SourceKind::Script,
r#"
function main(): int|string {
$a = 1;
$b = 2;
$c = $a + $b;
$b = match ($a) {
1 => 2,
2 => 3,
default => "string",
};
return $c + $b;
}
"#,
)]);
let report = Report::new()
.with_issue(
Issue::error("E123", "some error here")
.with_source(DEFAULT_NAME, 35, 41)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W123", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W124", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::note("N123", "some note here")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 121, 128)
.with_message("another annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::help("H123", "some help here")
.with_source(DEFAULT_NAME, 137, 147)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::bug("E123", "`match` arms have incompatible types")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 110, 111)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 148, 156)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0308`"),
)
.with_footer(ReportFooter::new("this is a report footer message"));
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
sourcepub fn with_note<S: Into<String>>(self, note: S) -> Self
pub fn with_note<S: Into<String>>(self, note: S) -> Self
Add a note to this issue.
Examples found in repository?
examples/cross_file.rs (lines 51-53)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![
Source::new(
SourceKind::Script,
"src/main.ara",
r#"
use function Math\add;
function main(): int {
$value = add(1, '2');
$value
}
"#,
),
Source::new(
SourceKind::Script,
"vendor/some-vendor/some-lib/src/add.ara",
r#"
namespace Math;
function add(int $a, int $b): int {
return $a + $b;
}
"#,
),
]);
let report = Report::new().with_issue(
Issue::error("", "mismatched types expected `{int}`, found `{string}`")
.with_source("src/main.ara", 68, 71)
.with_annotation(
Annotation::secondary("src/main.ara", 61, 64)
.with_message("arguments to this function are incorrect"),
)
.with_annotation(
Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
.with_message("function defined here"),
)
.with_note(
"you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
),
);
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
More examples
examples/compact.rs (lines 52-54)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![
Source::new(
SourceKind::Script,
"src/main.ara",
r#"
use function Math\add;
function main(): int {
$value = add(1, '2');
$value
}
"#,
),
Source::new(
SourceKind::Script,
"vendor/some-vendor/some-lib/src/add.ara",
r#"
namespace Math;
function add(int $a, int $b): int {
return $a + $b;
}
"#,
),
]);
let report = Report::new().with_issue(
Issue::error("", "mismatched types expected `{int}`, found `{string}`")
.with_source("src/main.ara", 68, 71)
.with_annotation(
Annotation::secondary("src/main.ara", 61, 64)
.with_message("arguments to this function are incorrect"),
)
.with_annotation(
Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
.with_message("function defined here"),
)
.with_note(
"you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
),
);
let builder = ReportBuilder::new(&map)
.with_charset(CharSet::Unicode)
.with_colors(ColorChoice::Always)
.with_style(DisplayStyle::Compact);
builder.print(&report)
}
examples/comfortable.rs (lines 52-54)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![
Source::new(
SourceKind::Script,
"src/main.ara",
r#"
use function Math\add;
function main(): int {
$value = add(1, '2');
$value
}
"#,
),
Source::new(
SourceKind::Script,
"vendor/some-vendor/some-lib/src/add.ara",
r#"
namespace Math;
function add(int $a, int $b): int {
return $a + $b;
}
"#,
),
]);
let report = Report::new().with_issue(
Issue::error("", "mismatched types expected `{int}`, found `{string}`")
.with_source("src/main.ara", 68, 71)
.with_annotation(
Annotation::secondary("src/main.ara", 61, 64)
.with_message("arguments to this function are incorrect"),
)
.with_annotation(
Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
.with_message("function defined here"),
)
.with_note(
"you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
),
);
let builder = ReportBuilder::new(&map)
.with_charset(CharSet::Unicode)
.with_colors(ColorChoice::Always)
.with_style(DisplayStyle::Comfortable);
builder.print(&report)
}
examples/simple.rs (line 41)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn main() -> Result<(), Error> {
let origin = "example.ara";
let code = r#"
$b = match $a {
1 => 2,
2 => 3,
default => "string",
};
"#;
let map = SourceMap::new(vec![Source::new(SourceKind::Script, origin, code)]);
let report = Report::new()
.with_issue(
Issue::error("E0417", "`match` arms have incompatible types")
.with_source(origin, 6, 67)
.with_annotation(
Annotation::secondary(origin, 26, 27)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(origin, 38, 39)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(origin, 56, 64)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0417`"),
)
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
examples/collection.rs (line 50)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
fn main() -> Result<(), Error> {
let first_origin = "example.ara";
let first_code = r#"
$b = match $a {
1 => 2,
2 => 3,
default => "string",
};
"#;
let second_origin = "example-2.ara";
let second_code = r#"
function foo(Bar&float) {}
"#;
let map = SourceMap::new(vec![
Source::new(SourceKind::Script, first_origin, first_code),
Source::new(SourceKind::Script, second_origin, second_code),
]);
let first_report = Report::new()
.with_issue(
Issue::error("E0417", "`match` arms have incompatible types")
.with_source(first_origin, 6, 67)
.with_annotation(
Annotation::secondary(first_origin, 26, 27)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(first_origin, 38, 39)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(first_origin, 56, 64)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0417`"),
)
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let second_report = Report::new()
.with_issue(
Issue::error(
"P0015",
"scalar type `float` cannot be used in an intersection",
)
.with_source(second_origin, 18, 23)
.with_annotation(
Annotation::secondary(second_origin, 17, 19)
.with_message("scalar type `float` cannot be used in an intersection"),
)
.with_note("a scalar type is either `int`, `float`, `string`, or `bool`.")
.with_note("try using a different type for the intersection."),
)
.with_issue(Issue::bug("B0001", "failed to read the file"))
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let reports: ReportCollection = vec![&first_report, &second_report];
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&reports)
}
examples/example.rs (line 42)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![Source::inline(
SourceKind::Script,
r#"
function main(): int|string {
$a = 1;
$b = 2;
$c = $a + $b;
$b = match ($a) {
1 => 2,
2 => 3,
default => "string",
};
return $c + $b;
}
"#,
)]);
let report = Report::new()
.with_issue(
Issue::error("E123", "some error here")
.with_source(DEFAULT_NAME, 35, 41)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W123", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W124", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::note("N123", "some note here")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 121, 128)
.with_message("another annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::help("H123", "some help here")
.with_source(DEFAULT_NAME, 137, 147)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::bug("E123", "`match` arms have incompatible types")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 110, 111)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 148, 156)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0308`"),
)
.with_footer(ReportFooter::new("this is a report footer message"));
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
sourcepub fn with_source<O: Into<String>>(
self,
source: O,
from: usize,
to: usize
) -> Self
pub fn with_source<O: Into<String>>(
self,
source: O,
from: usize,
to: usize
) -> Self
Add a source/position details to this issue.
Examples found in repository?
examples/cross_file.rs (line 42)
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![
Source::new(
SourceKind::Script,
"src/main.ara",
r#"
use function Math\add;
function main(): int {
$value = add(1, '2');
$value
}
"#,
),
Source::new(
SourceKind::Script,
"vendor/some-vendor/some-lib/src/add.ara",
r#"
namespace Math;
function add(int $a, int $b): int {
return $a + $b;
}
"#,
),
]);
let report = Report::new().with_issue(
Issue::error("", "mismatched types expected `{int}`, found `{string}`")
.with_source("src/main.ara", 68, 71)
.with_annotation(
Annotation::secondary("src/main.ara", 61, 64)
.with_message("arguments to this function are incorrect"),
)
.with_annotation(
Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
.with_message("function defined here"),
)
.with_note(
"you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
),
);
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
More examples
examples/compact.rs (line 43)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![
Source::new(
SourceKind::Script,
"src/main.ara",
r#"
use function Math\add;
function main(): int {
$value = add(1, '2');
$value
}
"#,
),
Source::new(
SourceKind::Script,
"vendor/some-vendor/some-lib/src/add.ara",
r#"
namespace Math;
function add(int $a, int $b): int {
return $a + $b;
}
"#,
),
]);
let report = Report::new().with_issue(
Issue::error("", "mismatched types expected `{int}`, found `{string}`")
.with_source("src/main.ara", 68, 71)
.with_annotation(
Annotation::secondary("src/main.ara", 61, 64)
.with_message("arguments to this function are incorrect"),
)
.with_annotation(
Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
.with_message("function defined here"),
)
.with_note(
"you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
),
);
let builder = ReportBuilder::new(&map)
.with_charset(CharSet::Unicode)
.with_colors(ColorChoice::Always)
.with_style(DisplayStyle::Compact);
builder.print(&report)
}
examples/comfortable.rs (line 43)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![
Source::new(
SourceKind::Script,
"src/main.ara",
r#"
use function Math\add;
function main(): int {
$value = add(1, '2');
$value
}
"#,
),
Source::new(
SourceKind::Script,
"vendor/some-vendor/some-lib/src/add.ara",
r#"
namespace Math;
function add(int $a, int $b): int {
return $a + $b;
}
"#,
),
]);
let report = Report::new().with_issue(
Issue::error("", "mismatched types expected `{int}`, found `{string}`")
.with_source("src/main.ara", 68, 71)
.with_annotation(
Annotation::secondary("src/main.ara", 61, 64)
.with_message("arguments to this function are incorrect"),
)
.with_annotation(
Annotation::secondary("vendor/some-vendor/some-lib/src/add.ara", 27, 51)
.with_message("function defined here"),
)
.with_note(
"you can cast a `{string}` to an `{int}` using `Psl\\Str\\to_int(...)` function",
),
);
let builder = ReportBuilder::new(&map)
.with_charset(CharSet::Unicode)
.with_colors(ColorChoice::Always)
.with_style(DisplayStyle::Comfortable);
builder.print(&report)
}
examples/simple.rs (line 28)
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
fn main() -> Result<(), Error> {
let origin = "example.ara";
let code = r#"
$b = match $a {
1 => 2,
2 => 3,
default => "string",
};
"#;
let map = SourceMap::new(vec![Source::new(SourceKind::Script, origin, code)]);
let report = Report::new()
.with_issue(
Issue::error("E0417", "`match` arms have incompatible types")
.with_source(origin, 6, 67)
.with_annotation(
Annotation::secondary(origin, 26, 27)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(origin, 38, 39)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(origin, 56, 64)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0417`"),
)
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
examples/collection.rs (line 37)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
fn main() -> Result<(), Error> {
let first_origin = "example.ara";
let first_code = r#"
$b = match $a {
1 => 2,
2 => 3,
default => "string",
};
"#;
let second_origin = "example-2.ara";
let second_code = r#"
function foo(Bar&float) {}
"#;
let map = SourceMap::new(vec![
Source::new(SourceKind::Script, first_origin, first_code),
Source::new(SourceKind::Script, second_origin, second_code),
]);
let first_report = Report::new()
.with_issue(
Issue::error("E0417", "`match` arms have incompatible types")
.with_source(first_origin, 6, 67)
.with_annotation(
Annotation::secondary(first_origin, 26, 27)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(first_origin, 38, 39)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(first_origin, 56, 64)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0417`"),
)
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let second_report = Report::new()
.with_issue(
Issue::error(
"P0015",
"scalar type `float` cannot be used in an intersection",
)
.with_source(second_origin, 18, 23)
.with_annotation(
Annotation::secondary(second_origin, 17, 19)
.with_message("scalar type `float` cannot be used in an intersection"),
)
.with_note("a scalar type is either `int`, `float`, `string`, or `bool`.")
.with_note("try using a different type for the intersection."),
)
.with_issue(Issue::bug("B0001", "failed to read the file"))
.with_footer(
ReportFooter::new("this is a report footer message")
.with_note("this is a note message"),
);
let reports: ReportCollection = vec![&first_report, &second_report];
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&reports)
}
examples/example.rs (line 38)
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
fn main() -> Result<(), Error> {
let map = SourceMap::new(vec![Source::inline(
SourceKind::Script,
r#"
function main(): int|string {
$a = 1;
$b = 2;
$c = $a + $b;
$b = match ($a) {
1 => 2,
2 => 3,
default => "string",
};
return $c + $b;
}
"#,
)]);
let report = Report::new()
.with_issue(
Issue::error("E123", "some error here")
.with_source(DEFAULT_NAME, 35, 41)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 41, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W123", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::warning("W124", "some warning here")
.with_source(DEFAULT_NAME, 29, 187)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::note("N123", "some note here")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 105, 112).with_message("an annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 121, 128)
.with_message("another annotation"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 137, 147).with_message("and another"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::help("H123", "some help here")
.with_source(DEFAULT_NAME, 137, 147)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 35, 42).with_message("an annotation"),
)
.with_note("this is a note"),
)
.with_issue(
Issue::bug("E123", "`match` arms have incompatible types")
.with_source(DEFAULT_NAME, 84, 163)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 110, 111)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 126, 127)
.with_message("this is found to be of type `{int}`"),
)
.with_annotation(
Annotation::secondary(DEFAULT_NAME, 148, 156)
.with_message("expected `{int}`, found `{string}`"),
)
.with_note("for more information about this error, try `ara --explain E0308`"),
)
.with_footer(ReportFooter::new("this is a report footer message"));
let builder = ReportBuilder::new(&map)
.with_colors(ColorChoice::Always)
.with_charset(CharSet::Unicode);
builder.print(&report)
}
Trait Implementations§
source§impl<'de> Deserialize<'de> for Issue
impl<'de> Deserialize<'de> for Issue
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Display for Issue
impl Display for Issue
Display the issue as a string.
Example:
use ara_reporting::issue::Issue;
use ara_reporting::issue::IssueSeverity;
let issue = Issue::error("E0231", "unexpected token `{`, expecting `[`")
.with_source("main.ara", 10, 1);
assert_eq!(issue.to_string(), "error[E0231]: unexpected token `{`, expecting `[` at main.ara@10:1");
let issue = Issue::bug("B0001", "failed to read the file");
assert_eq!(issue.to_string(), "bug[B0001]: failed to read the file");
let issue = Issue::new(IssueSeverity::Error, "some error just happened");
assert_eq!(issue.to_string(), "error: some error just happened");
source§impl JsonSchema for Issue
impl JsonSchema for Issue
source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
source§fn json_schema(gen: &mut SchemaGenerator) -> Schema
fn json_schema(gen: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref
keyword. Read more