forked from dansmith65/FileMaker-Error-Handling
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorIfSetCustomElement.fmfn
More file actions
82 lines (81 loc) · 2.97 KB
/
Copy pathErrorIfSetCustomElement.fmfn
File metadata and controls
82 lines (81 loc) · 2.97 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/**
* =====================================
* ErrorIfSetCustomElement ( keyOrPath ; value ; jsonType )
*
* PURPOSE:
* Set a custom value in the error object stored in a private local variable.
*
*
* RETURNS: (boolean)
* True if an error was stored, which also means it added data to the error.
* False if an error was NOT stored, wich also means it did NOT add data to the error.
*
* PARAMETERS:
* keyOrPath = (text) the key or path to the JSON element to get
* SHOULD NOT start with "_invalidKeys",
* which is a reserved key where values with invalid keys are stored.
* value = the value to set
* jsonType = should be one of the valid types like JSONString
*
* NOTE:
* It is recommended to document values that are commonly set by this function in your
* system. For example, I use these values:
* dialog.title = (string) If set, will override the default custom dialog title.
* dialog.message = (string) If set, will override the default custom dialog message.
* dialog.shown = (boolean) If true, dialog has been shown to the user.
* logLevel = (int) If set, this log level will be used instead of the default.
*
* DEPENDENCIES:
* ErrorFound, ErrorGetAsJSON, ErrorIfSetFromJSON
*
* REFERENCES:
* Full documentation can be found at https://github.com/dansmith65/FileMaker-Error-Handling.
* Either [the entire license](https://github.com/dansmith65/FileMaker-Error-Handling/blob/master/LICENSE)
* or this sentence shall be included in all copies or substantial portions of the Software.
*
* HISTORY:
* 2024-JUL-08 Daniel Smith dan@filemaker.consulting
* - created based on code by Joshua Willing josh@willingapps.com
* =====================================
*/
If ( not ErrorFound ; False ;
Let ( [
~keyOrPathIsInvalid =
IsEmpty ( keyOrPath )
/* Array's are not supported at the root level. */
or (
Position ( keyOrPath ; "[" ; 1 ; 1 ) = 1
and
Position ( keyOrPath ; "['" ; 1 ; 1 ) ≠ 1
)
/* Chose not to support new array syntax, which helps with backwards compatibility
and will hopefully make it easier to transition the underlying data structure,
in case that ever needs to be done. */
or PatternCount ( keyOrPath ; "[:]" )
or PatternCount ( keyOrPath ; "[+]" )
/* Bracket notation could also be more difficult to transition to a new data structure. */
or PatternCount ( keyOrPath ; "['" )
;
~invalidKeyCount = If ( ~keyOrPathIsInvalid ;
ValueCount ( JSONListKeys ( ErrorGetAsJSON ; "custom._invalidKeys" ) )
) ;
~ = If ( ~keyOrPathIsInvalid ;
/* save keyOrPath in _invalidKeys */
ErrorIfSetFromJSON (
JSONSetElement ( ErrorGetAsJSON ;
"custom._invalidKeys[" & ~invalidKeyCount & "]keyOrPath" ;
keyOrPath ;
JSONString
)
)
) ;
~modifiedKeyOrPath = If ( ~keyOrPathIsInvalid ;
"_invalidKeys[" & ~invalidKeyCount & "]value" ;
keyOrPath
)
] ;
ErrorIfSetFromJSON (
JSONSetElement ( ErrorGetAsJSON ; "custom." & ~modifiedKeyOrPath ; value ; jsonType )
)
)
)