Skip to content

Commit b53efc2

Browse files
committed
Book Updates
-add traceback info in 6.1
1 parent 47801c9 commit b53efc2

File tree

1 file changed

+48
-16
lines changed

1 file changed

+48
-16
lines changed

book/chapter6.1.md

Lines changed: 48 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,62 @@ And the output:
1616

1717
```sh
1818
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+
| ^
2723
```
2824

2925
## What The Error Says
3026

3127
GLang highlights _exactly_ where things went wrong, showing you the offending line and character.
3228

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+
3333
Sometimes, you’ll also get a helpful hint to steer you in the right direction:
3434

3535
```sh
3636
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("", "");
4557
```
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

Comments
 (0)