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
Text values can be used as shorthand for error values. For example:
27
+
The _expression_ being raised must evaluate to an _error value_.
28
+
29
+
In canonical form, an _error value_ is a record with the following structure:
28
30
29
31
```powerquery-m
30
-
error "Hello, world" // error with message "Hello, world"
32
+
[
33
+
ErrorCode = ...,
34
+
Reason = ...,
35
+
Message = ...,
36
+
Detail = ...,
37
+
Message.Format = ...,
38
+
Message.Parameters = ...
39
+
]
31
40
```
32
41
33
-
Full error values are records and can be constructed using the `Error.Record` function:
42
+
All of the above record fields are optional, and so may be omitted or set to null. When not null, _Reason_, _Message_, and _Message.Format_ must be text, and _Message.Parameters_ must be a list.
43
+
44
+
Any additional fields included in the record will be ignored and so not included in the error that is raised.
45
+
46
+
_Message.Format_ may contain string interpolation placeholders in the form of `#{x}`, where `x` is a zero-based index. When an error is raised with a non-null _Message.Foramt_, interpolation will be performed using _Message.Format_ as the format string and _Message.Parameters_ as the values to be positionally applied. The resulting output will become the raised error's _Message_.
47
+
48
+
For example:
34
49
35
50
```powerquery-m
36
-
error Error.Record("FileNotFound", "File my.txt not found",
37
-
"my.txt")
51
+
error [
52
+
Message.Format = "Unexpected value '#{0}' in field #{1}",
53
+
Message.Parameters = {"???", "Customer"}
54
+
]
38
55
```
39
56
40
-
The above expression is equivalent to:
57
+
Will result in the following error being raised:
41
58
42
59
```powerquery-m
43
-
error [
44
-
Reason = "FileNotFound",
45
-
Message = "File my.txt not found",
46
-
Detail = "my.txt"
60
+
[
61
+
ErrorCode = null,
62
+
Reason = null,
63
+
Message = "Unexpected value '???' in field Customer",
64
+
Detail = null,
65
+
Message.Format = "Unexpected value '#{0}' in field #{1}",
66
+
Message.Parameters = {"???", "Customer"}
47
67
]
48
68
```
49
69
70
+
Text values can be used as shorthand for error values. For example:
71
+
72
+
```powerquery-m
73
+
error "Hello, world" // error with message "Hello, world"
74
+
```
75
+
76
+
50
77
Raising an error will cause the current expression evaluation to stop, and the expression evaluation stack will unwind until one of the following occurs:
51
78
52
79
* A record field, section member, or let variable—collectively: an _entry_—is reached. The entry is marked as having an error, the error value is saved with that entry, and then propagated. Any subsequent access to that entry will cause an identical error to be raised. Other entries of the record, section, or let expression are not necessarily affected (unless they access an entry previously marked as having an error).
0 commit comments