Skip to content

Commit 9ea5fc1

Browse files
committed
FIX: Line numbering for error messages doesn't account for header
resolves: Oldes/Rebol-issues#2302
1 parent 5e9b14a commit 9ea5fc1

File tree

3 files changed

+23
-10
lines changed

3 files changed

+23
-10
lines changed

src/mezz/sys-load.reb

+13-10
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ load-header: function/with [
128128
not data: script? tmp [ ; no script header found
129129
return either required ['no-header] [reduce [none tmp tail tmp]]
130130
]
131-
set/any [key: rest:] transcode/only data none ; get 'rebol keyword
132-
set/any [hdr: rest:] transcode/next/error rest none ; get header block
131+
set/any [key: rest: line:] transcode/only/line data 1 none ; get 'rebol keyword
132+
set/any [hdr: rest: line:] transcode/next/error/line rest :line none ; get header block
133133
not block? :hdr [return 'no-header] ; header block is incomplete
134134
not attempt [hdr: construct/with :hdr system/standard/header][return 'bad-header]
135135
word? :hdr/options [hdr/options: to block! :hdr/options]
@@ -138,10 +138,10 @@ load-header: function/with [
138138
not tuple? :hdr/version [hdr/version: none]
139139
find hdr/options 'content [repend hdr ['content data]] ; as of start of header
140140
13 = rest/1 [rest: next rest] ; skip CR
141-
10 = rest/1 [rest: next rest] ; skip LF
141+
10 = rest/1 [rest: next rest ++ line] ; skip LF
142142
integer? tmp: select hdr 'length [end: skip rest tmp]
143143
not end [end: tail data]
144-
only [return reduce [hdr rest end]] ; decompress and checksum not done
144+
only [return reduce [hdr rest end line]] ; decompress and checksum not done
145145
sum: hdr/checksum none ;[print sum] ; none saved to simplify later code
146146
:key = 'rebol [ ; regular script, binary or script encoded compression supported
147147
case [
@@ -172,7 +172,7 @@ load-header: function/with [
172172
]
173173
;assert/type [hdr object! rest [binary! block!] end binary!]
174174
;assert/type [hdr/checksum [binary! none!] hdr/options [block! none!]]
175-
reduce [hdr rest end]
175+
reduce [hdr rest end line]
176176
][
177177
non-ws: make bitset! [not 1 - 32]
178178
]
@@ -270,7 +270,7 @@ read-decode: function [
270270
; Try to load it (will fail if source is a url)
271271
data: load-extension source ; returns an object or throws an error
272272
][
273-
data: read source ; can be string, binary, block
273+
data: read/binary source ; can be string, binary, block
274274
if find system/options/file-types type [data: decode type :data] ; e.g. not 'unbound
275275
]
276276
data
@@ -312,29 +312,32 @@ load: function [
312312
any [file? source url? source] [
313313
stype: file-type? source
314314
type: case [
315-
lib/all ['unbound = as 'extension = stype] [stype]
315+
lib/all ['unbound = type 'extension = stype] [stype]
316316
as [type]
317317
'else [stype]
318318
]
319319
data: read-decode source type
320+
if not find [0 extension unbound] any [type 0] [return data]
320321
]
321322
none? data [data: source]
322323

323324
;-- Is it not source code? Then return it now:
324325
any [block? data not find [0 extension unbound] any [type 0]][ ; due to make-boot issue with #[none]
325-
return data ; directory, image, txt, markup, etc.
326+
unless type [return data]
327+
try [return decode type to binary! data]
328+
cause-error 'access 'no-codec type
326329
]
327330

328331
;-- Try to load the header, handle error:
329332
not all [
330-
set [hdr: data: end:] either object? data [load-ext-module data] [load-header data]
333+
set [hdr: data: end: line:] either object? data [load-ext-module data] [load-header data]
331334
if word? hdr [cause-error 'syntax hdr source]
332335
unless tail? end [data: copy/part data end]
333336
]
334337
; data is binary or block now, hdr is object or none
335338

336339
;-- Convert code to block, insert header if requested:
337-
not block? data [data: make block! data]
340+
not block? data [data: transcode/line data any [line 1]]
338341
header [insert data hdr]
339342

340343
;-- Bind code to user context:
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Rebol [
2+
Title: {title is on line 2}
3+
]
4+
4line

src/tests/units/load-test.r3

+6
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ Rebol [
8888
error? e: try [load #{789DE3}] ;- no crash!
8989
e/id = 'invalid-chars
9090
]
91+
--test-- "issue-2302"
92+
;@@ https://github.com/Oldes/Rebol-issues/issues/2302
93+
--assert all [
94+
error? e: try [load %units/files/invalid-decimal.r]
95+
e/near = "(line 4) 4line"
96+
]
9197

9298
===end-group===
9399

0 commit comments

Comments
 (0)