You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/chapter6.1.md
+48-16Lines changed: 48 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,30 +16,62 @@ And the output:
16
16
17
17
```sh
18
18
error: division by zero
19
-
in: example.glang:1:6
20
-
+
21
-
|
22
-
| 1 / 0;
23
-
| ^
24
-
|
25
-
+
26
-
process finished with exit code -1
19
+
--> example.glang:1:6
20
+
|
21
+
1 | 1 / 0;
22
+
| ^
27
23
```
28
24
29
25
## What The Error Says
30
26
31
27
GLang highlights _exactly_ where things went wrong, showing you the offending line and character.
32
28
29
+
-`error:` tells you what error occured.
30
+
-`-->` indicates where and what file caused the issue.
31
+
-`^` shows what code stopped the program's execution
32
+
33
33
Sometimes, you’ll also get a helpful hint to steer you in the right direction:
34
34
35
35
```sh
36
36
error: variable name 'example' is undefined
37
-
in: example.glang:1:1
38
-
+
39
-
|
40
-
| example
41
-
| ^^^^^^^
42
-
|
43
-
+ --> help: you can define a variable like 'obj my_variable = 1;'
44
-
process finished with exit code -1
37
+
--> example.glang:1:1
38
+
|
39
+
1 | example
40
+
| ^^^^^^^ help: define a variable with the syntax 'obj <variable name> = <value>;'
41
+
```
42
+
43
+
Nice start, kdog — this already reads clearly and has a good flow! Let’s tighten it up a bit, make the explanation a little more structured, and highlight *why* the traceback happens so readers really “get” it.
44
+
45
+
Here’s a refined version:
46
+
47
+
---
48
+
49
+
## Tracebacks
50
+
51
+
Sometimes, multiple errors appear at once. This is called a **traceback**. A traceback happens when an error is **propagated upward** through the code, from where it occurs to wherever the function was called.
52
+
53
+
For example, consider the `push` function:
54
+
55
+
```
56
+
push("", "");
45
57
```
58
+
59
+
Here, both arguments are strings, but `push` expects the first argument to be a **list**. GLang first detects the problem inside its library code, then reports it again at the point where you called the function.
60
+
61
+
That’s why you’ll see two errors:
62
+
63
+
```sh
64
+
error: argument 'list' must be type list
65
+
--> library/fundamental/list.glang:7:9
66
+
|
67
+
7 | uhoh("argument 'list' must be type list");
68
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
69
+
70
+
error: argument 'list' must be type list
71
+
--> example.glang:1:1
72
+
|
73
+
1 | push("", "");
74
+
| ^^^^^^^^^^^
75
+
```
76
+
77
+
The first error shows **where** the problem started (inside the GLang library). The second shows **where** it reached the code.
0 commit comments