-
Notifications
You must be signed in to change notification settings - Fork 4
/
Error.Summarize.pq
62 lines (53 loc) · 2.47 KB
/
Error.Summarize.pq
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
let
fullPath = ..., // # try func to ensure naming
bytes = File.Contents( fullPath ),
raw_text = Text.FromBinary( bytes, TextEncoding.Utf8 ),
final_evaluation = try Expression.Evaluate( raw_text , #shared ),
FormatError = (source as any) as any =>
error "NYI: refactor the formatting logic",
error_ast = final_evaluation[Error],
error_json = Text.FromBinary( Json.FromValue( final_evaluation[Error] ), TextEncoding.Utf8 ),
summary_message = Text.Replace( error_ast[Message], "] ", "]#(cr,lf)"),
// converts strings "[171-18-171-28]" to structured location data
error_location
= let
rawText = Text.AfterDelimiter( Text.BeforeDelimiter( error_ast[Message], "]"), "["),
pairs = Text.Split( rawText, "-"),
return = [
StartLine = Number.From( Text.BeforeDelimiter( pairs{0}, "," )),
StartColumn = Number.From( Text.AfterDelimiter( pairs{0}, "," )),
EndLine = Number.From( Text.BeforeDelimiter( pairs{1}, "," )),
EndColumn = Number.From( Text.AfterDelimiter( pairs{1}, "," ))
]
in
return,
actual_lines = Lines.FromText(raw_text),
code_at_location = Lines.ToText( List.Range( actual_lines,
error_location[StartLine] - 1, error_location[EndLine] + 1) ),
formatted_errors = Table.FromRecords(
{[
Message = summary_message,
Location = error_location,
Code = code_at_location,
json = error_json
]},
type table [
Message = text,
Code = text,
json = text,
Location = Record.Type
],
MissingField.Error
),
return
=
/* note: read error of 'try bytes' still returns HasError = False, when file does not exist, so I test for 'DataSource.Error'
*/
if #"PQLib Version" = "" then table_listSourceFilesInDirectory
else if (final_evaluation[HasError] and final_evaluation[Error][Reason] = "DataSource.Error")
then table_listSourceFilesInDirectory
else if not final_evaluation[HasError]
then final_evaluation[Value]
else formatted_errors
in
return