occa
occa copied to clipboard
Add error codes
There are currently about 150 OCCA_ERRORs and 150 printErrors, it would be nice to standardize an error code format and make it easy to document and find reasons/causes
For example, Rust's error codes and outputs are pretty nice
- [ ] Come up with an error code format
- [ ] Add error codes to appropriate
OCCA_ERRORandprintErrorlocations - [ ] Add reason/possible solutions somewhere
- [ ] Make error code information accessible through
occaCLI
Random notes
Rules:
- 2 lines before first line
- 2 lines after last line
- Right align line numbers
- Pad line numbers by 2 spaces
- Separate line numbers and code line by ' | '
- Separate messages by ' # '
- Separate gaps by ' - ' unless line number gap <= 2
- Separate first gap by '^^^ ' if next source is above the original source
- Separate with '*** ' if supressing error/warnings
- Order messages left-to-right with down-to-up strategy
Errors:
1st: ' ' between ^~~~ and message
2nd: Add 'L ' below ^
nth: Add '|' below ^ and 'L ' below last '|'
- line # yellow
-
#red or yellow based error/warning -
-blue -
^^^blue - Error messages alternate between colors (blue / green)
errorCode("P1234")
.withMessage(token->origin,
"[@tile] Iterator variable needs to be of type [char, short, int, long]")
.print();
errorCode("P1234")
.withMessage(*token,
"[@tile] Iterator variable needs to be of type [char, short, int, long]")
.print();
(source):2 Error P1234: [@tile] Iterator variable needs to be of type [char, short, int, long]
1 | // test
2 | const int_ blah() {
# ^~~~
3 | return 1;
4 | }
errorCode("P1234")
.withMessage(*token,
"[@tile] Iterator variable needs to be of type [char, short, int, long]")
.withSource(*token, "Unknown identifier, did you mean int?")
.print();
(source):2 Error P1234: [@tile] Iterator variable needs to be of type [char, short, int, long]
1 | // test
2 | const int_ blah() {
# ^~~~ Unknown identifier, did you mean int?
3 | return 1;
4 | }
errorCode("P1234")
.withMessage(*token,
"[@tile] Iterator variable needs to be of type [char, short, int, long]")
.withSource(*token, "Unknown identifier, did you mean int?")
.withSource(*token, "What about x?")
.print();
(source):2 Error P1234: [@tile] Iterator variable needs to be of type [char, short, int, long]
1 | // test
2 | const int_ blah() {
# ^--- Unknown identifier, did you mean int?
# What about x?
3 | return 1;
4 | }
errorCode("P1234")
.withMessage(token1,
"[@tile] Iterator variable needs to be of type [char, short, int, long]")
.withSource(token1, "Did you mean blah2?")
.withSource(token2, "Unknown identifier, did you mean int?")
.withSource(token3, "Unknown identifier, did you mean int?")
.print();
(source):10 Error P1234: [@tile] Iterator variable needs to be of type [char, short, int, long]
8 |
9 | // test
10 | const int_ blah() {
# ^---- ^--- ^--- Did you mean blah2?
# | L Unknown identifier, did you mean int?
# L Unknown identifier, did you mean int?
11 | return 1;
12 | }
errorCode("P1234")
.withMessage(token1,
"[@tile] Iterator variable needs to be of type [char, short, int, long]")
.withSource(token1, "Did you mean blah2?")
.withSource(token2, "Unknown identifier, did you mean int?")
.withSource(token3, "Unknown identifier, did you mean int?")
.withSource(token4, "Used here")
.print();
(source):10,21 Error P1234: [@tile] Iterator variable needs to be of type [char, short, int, long]
8 |
9 | // test
10 | const int_ blah() {
# ^~~~~ ^~~~ ^~~~ Did you mean blah2?
# | L Unknown identifier, did you mean int?
# L Unknown identifier, did you mean int?
11 | int x;
12 | int y;
-
21 | return 1;
# ^ Used here
errorCode("P1234")
.withMessage(token1,
"[@tile] Iterator variable needs to be of type [char, short, int, long]")
.withSource(token1, "Did you mean blah2?")
.withSource(token2, "Used here")
.print();
(source):10,21 Error P1234: [@tile] Iterator variable needs to be of type [char, short, int, long]
8 |
9 | // test
10 | const int_ blah() {
# ^~~~ Did you mean blah2?
11 | return 1;
12 | }
^^^
1 | blah2();
# ^~~~ Defined here
errorCode("P1234")
.withMessage(token1,
"[@tile] Iterator variable needs to be of type [char, short, int, long]")
.withSource(token1, "Did you mean blah2?")
.withSource(token2, "Used here")
.print();
(source):10 Error P1234: [@tile] Iterator variable needs to be of type [char, short, int, long]
8 |
9 | // test
10 | const int_ blah() {
# ^~~~ Did you mean blah2?
11 | return 1;
12 | }
(source2):21
21 | blah2();
# ^~~~ Defined here
(source3):21
21 | blah2();
# ^~~~ Defined here
errorCode("P1234")
.withMessage(token1,
"[@tile] Iterator variable needs to be of type [char, short, int, long]")
.withSource(token1, "Did you mean blah2?")
.withSource(token2, "Used here")
...
.withSource(token100, "Used here")
.print();
(source):10 & 21 Error P1234: [@tile] Iterator variable needs to be of type [char, short, int, long]
8 |
9 | // test
10 | const int_ blah() {
# ^~~~ Did you mean blah2?
11 | return 1;
12 | }
^^^
1 | blah2();
# ^~~~ Defined here
2 | blah2();
# ^~~~ Defined here
Supressed 98 additional error/warning locations
errorCode("P1234")
.withMessage("[@tile] Iterator variable needs to be of type [char, short, int, long]")
.withSource(*token)
.print();
(source):2 Error P1234: [@tile] Iterator variable needs to be of type [char, short, int, long]
1 | // test
2 | const int_ blah() {
# ^__...
-
4 | }
# - Cannot define block here
Error P1234: [@tile] Iterator variable needs to be of type [char, short, int, long]
(source)
8 |
9 | // test
10 | const int_ blah() {
# ^-- Did you mean blah2?
11 | return 1;
12 | }
^^^
1 | blah2();
# ^--- Defined here
2 | blah2();
# ^--- Defined here
(source)
8 |
9 | // test
10 | const int_ blah() {
# ^~~~ Did you mean blah2?
11 | return 1;
12 | }
^^^
1 | blah2();
# ^~~~ Defined here
2 | blah2();
# ^~~~ Defined here
Supressed 98 additional error/warning locations
Error P1234: [@tile] Iterator variable needs to be of type [char, short, int, long]
(source):10:9: Included file
(source):20:13: Expanded from macro 'bar'
(source):40:13: Test message 2
(source)
8 |
9 | // test
10 | const int_ blah() {
# ^~~~ Did you mean blah2?
11 | return 1;
12 | }
^^^
1 | blah2();
# ^~~~ Defined here
2 | blah2();
# ^~~~ Defined here
Supressed 98 additional error/warning locations
print(file)
print(file, line, 2)
print(file, line, 1)
- origin file
- origin line
print(file, false)
- file
- line
- source
- source
[s1, s2, s3, ...]