afuna (
afuna) wrote in
dw_dev_training2009-12-16 02:55 pm
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
![[site community profile]](https://www.dreamwidth.org/img/comm_staff.png)
BML, line numbers, and you!
So one of the quirks of BML is that if there's an error, the line number in the error message displayed is numbered as if "1" were the very first line of the code block you are currently in, and not the line number of the BML file.
So to find out exactly which line is causing the error, you need to:
1.) open up the BML file
2.) find which-th line the starting <?_code tag is located
3.) add that number to the line displayed in the error message, then subtract 1.
So, for example, if you have this BML file:
You will get this error message:
[Error: BLAH BLAH BLAH at '/dreamhack/8080-afuna/dw/htdocs/blah.bml' line 3. @ li-166]
Line 3 in the BML file is just part of the header comments. The actual line causing the page to fail is at line 9 (where code block begins) + 3 (line number in the error message) - 1 (because that's just the way things turn out to be!) = 11.
Right where the code is told to
If you're working on huge BML files, with multiple errors, it can be somewhat of a pain to calculate the error location manually each time. So a tip to make it easier: use the
On the very first line of your code block, add this:
So now your BML file looks like this:
1 <?_c
2 # header
3 # header
4 # header
5 # more header
6 _c?>
7 <?page
8 body<=
9 <?_code
10 {
11 # line 12
12 die "BLAH " x 3;
13 return "blah";
14 }
15 _code?>
16 <=body
17 page?>
And now your error message tells you the exact line that's erroring:
[Error: BLAH BLAH BLAH at '/dreamhack/8080-afuna/dw/htdocs/blah.bml' line 12. @ li-166]
No need to remember which line the
Note that the "#" of the #line directive must be the very first character in the line (don't indent it). Also note that you should give it the line number immediately after your #line directive -- think of it as telling the Perl compiler, "the next line is line 12. Start counting from there".
You'll probably find the line number in your text editor -- either on the side, or on some sort of status bar at the bottom. Depending on your text editor, you may first need to figure out how to display the line numbers in the first place.
As for which of the two methods to use: The first method involves math, but is more convenient if you need to troubleshoot something very very quickly. The second method involves just a bit more effort up front, but means that you don't need to do any calculations in your head. I prefer it for if I'm going to be spending a lot of time with this file (just need to remember to take it out before generating the patch...)
Phew, that's it. I am so looking forward to the day Dreamwidth pages are fully on .tt instead of .bml.
So to find out exactly which line is causing the error, you need to:
1.) open up the BML file
2.) find which-th line the starting <?_code tag is located
3.) add that number to the line displayed in the error message, then subtract 1.
So, for example, if you have this BML file:
1 <?_c
2 # header
3 # header
4 # header
5 # more header
6 _c?>
7 <?page
8 body<=
9 <?_code
10 {
11 die "BLAH " x 3;
12 return "blah";
13 }
14 _code?>
15 <=body
16 page?>
You will get this error message:
[Error: BLAH BLAH BLAH at '/dreamhack/8080-afuna/dw/htdocs/blah.bml' line 3. @ li-166]
Line 3 in the BML file is just part of the header comments. The actual line causing the page to fail is at line 9 (where code block begins) + 3 (line number in the error message) - 1 (because that's just the way things turn out to be!) = 11.
Right where the code is told to
die
.If you're working on huge BML files, with multiple errors, it can be somewhat of a pain to calculate the error location manually each time. So a tip to make it easier: use the
#line
directive, which says that we should start the line counting at this location, from this number.On the very first line of your code block, add this:
# line next_line_number
So now your BML file looks like this:
1 <?_c
2 # header
3 # header
4 # header
5 # more header
6 _c?>
7 <?page
8 body<=
9 <?_code
10 {
11 # line 12
12 die "BLAH " x 3;
13 return "blah";
14 }
15 _code?>
16 <=body
17 page?>
And now your error message tells you the exact line that's erroring:
[Error: BLAH BLAH BLAH at '/dreamhack/8080-afuna/dw/htdocs/blah.bml' line 12. @ li-166]
No need to remember which line the
<?_code
block is on, or do addition in your head.Note that the "#" of the #line directive must be the very first character in the line (don't indent it). Also note that you should give it the line number immediately after your #line directive -- think of it as telling the Perl compiler, "the next line is line 12. Start counting from there".
You'll probably find the line number in your text editor -- either on the side, or on some sort of status bar at the bottom. Depending on your text editor, you may first need to figure out how to display the line numbers in the first place.
As for which of the two methods to use: The first method involves math, but is more convenient if you need to troubleshoot something very very quickly. The second method involves just a bit more effort up front, but means that you don't need to do any calculations in your head. I prefer it for if I'm going to be spending a lot of time with this file (just need to remember to take it out before generating the patch...)
Phew, that's it. I am so looking forward to the day Dreamwidth pages are fully on .tt instead of .bml.
no subject
no subject
(Actually, hope we end up removing BML quickly enough that no one ever needs to know all this!!)
no subject
You didn't say it explicitly here, but it's probably best to remove the line number definition before making a patch, if only because adding lines to the header at the top of the file later will make it have the wrong value, which will be confusing if someone forgets to update it.
no subject
no subject
no subject
no subject
no subject
Eek.
no subject