-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathepref.go
More file actions
982 lines (889 loc) · 29.2 KB
/
epref.go
File metadata and controls
982 lines (889 loc) · 29.2 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
package errpref
import (
"sync"
)
// ErrPref - This type is provides methods useful in formatting
// error prefix and error context strings.
//
// The error prefix text is designed to be configured at the
// beginning of error messages and is most often used to
// document the thread of code execution by listing the calling
// sequence for specific functions and methods.
//
// The error context string is designed to provide additional
// error context information associated with the currently
// executing function or method. Typical context information
// might include variable names, variable values and additional
// details on function execution.
//
// Note that there are no 'pointer' methods provided for this
// type. This is because the type is not designed to store
// information. Its only function is to receive process and
// return strings of error prefix information.
//
// ------------------------------------------------------------------------
//
// - IMPORTANT -
// None of the error prefix strings returned by the methods on this
// type are terminated with a new line character ('\n'). That means
// that none of the strings end with a new line character.
//
// If you prefer that error prefix strings be terminated with a new
// line character, you have two options:
//
// 1. Add the terminating new line character in your code.
//
// OR
//
// 2. Use the Error Prefix Data Transfer Object type
// 'ErrPrefixDto'.
//
// ------------------------------------------------------------------------
//
// Recommended Usage Examples
//
// ePrefix = ErrPref{}.EPrefCtx(
// ePrefix,
// "Tx7.TrySomethingNew()",
// "")
//
// ePrefix = ErrPref{}.EPref(
// ePrefix,
// "Tx14.SomeFabulousAndComplexStuff()")
//
// actualStr := ErrPref{}.SetCtxt(
// initialStr,
// "A!=B")
//
// Example Error Prefix String with Context information.
//
// "Tx1.AVeryVeryLongMethodNameCalledSomething()\\n" +
// " : A->B\\n" +
// "Tx2.SomethingElse() : A==B\\n" +
// "Tx3.DoSomething() : A==10\\n" +
// "Tx4() : A/10==4 - Tx5() : A!=B"
//
//
type ErrPref struct {
maxErrPrefixTextLineLength uint
lock *sync.Mutex
}
// ConvertNonPrintableChars - Receives a string containing
// non-printable characters and converts them to 'printable'
// characters returned in a string.
//
// This method is primarily used for testing an evaluation.
//
// Examples of non-printable characters are '\n', '\t' or 0x06
// (Acknowledge). These example characters would be translated into
// printable string characters as: "\\n", "\\t" and "[ACK]".
//
// Space characters are typically translated as " ". However, if
// the input parameter 'convertSpace' is set to 'true' then all
// spaces are converted to "[SPACE]" in the returned string.
//
// Reference:
// https://www.juniper.net/documentation/en_US/idp5.1/topics/reference/general/intrusion-detection-prevention-custom-attack-object-extended-ascii.html
//
// This method is useful for verifying error prefix strings which
// are routinely populated with non-printable characters.
//
//
// ------------------------------------------------------------------------
//
// Input Parameters
//
// nonPrintableChars []rune
// - An array of runes containing non-printable characters.
// The non-printable characters will be converted to
// printable characters.
//
// convertSpace bool
// - Space or white space characters (0x20) are by default
// translated as " ". However, if this parameter is set to
// 'true', space characters will be converted to "[SPACE]".
//
//
// ------------------------------------------------------------------------
//
// Return Values
//
// printableChars string
// - This returned string is identical to input parameter
// 'nonPrintableChars' with the exception that non-printable
// characters are translated into printable characters.
//
//
// ------------------------------------------------------------------------
//
// Example Usage
//
// testStr := "Hello world!\n"
// testRunes := []rune(testStr)
// ePrefix := "theCallingFunction()"
//
// ePrefQuark := errPrefQuark{}
//
// actualStr :=
// ePrefQuark.
// convertNonPrintableChars(
// testRunes,
// true,
// ePrefix)
//
// ----------------------------------------------------
// 'actualStr' is now equal to:
// "Hello[SPACE]world!\\n"
//
//
func (ePref ErrPref) ConvertNonPrintableChars(
nonPrintableChars []rune,
convertSpace bool) (
printableChars string) {
if ePref.lock == nil {
ePref.lock = new(sync.Mutex)
}
ePref.lock.Lock()
defer ePref.lock.Unlock()
ePrefQuark := errPrefQuark{}
printableChars,
_ = ePrefQuark.convertNonPrintableChars(
nonPrintableChars,
convertSpace,
"")
return printableChars
}
// ConvertPrintableChars - Converts printable characters to their
// non-printable or native equivalent. For example, instances of
// '\\n' in a string will be converted to '\n'.
//
// Additional examples of converted printable string characters
// are: "\\n", "\\t" and "[ACK]". These printable characters be
// converted into their native, non-printable state: '\n', '\t' or
// 0x06 (Acknowledge).
//
//
// Reference:
// https://www.juniper.net/documentation/en_US/idp5.1/topics/reference/general/intrusion-detection-prevention-custom-attack-object-extended-ascii.html
//
//
// ------------------------------------------------------------------------
//
// Input Parameters
//
// printableChars string
// - A string which may contain non-printable characters converted
// to their printable equivalents. These printable characters will
// be converted back to their native, non-printable values.
//
//
// ePrefix string
// - This is an error prefix which is included in all returned
// error messages. Usually, it contains the names of the calling
// method or methods. Note: Be sure to leave a space at the end
// of 'ePrefix'. This parameter is optional.
//
//
// ------------------------------------------------------------------------
//
// Return Values
//
// nonPrintableChars []rune
// - An array of runes containing non-printable characters.
// The non-printable characters were be converted from the
// printable characters contained in input parameter
// 'printableChars'.
//
//
// err error
// - If this method completes successfully, the returned error
// Type is set equal to 'nil'. If errors are encountered during
// processing, the returned error Type will encapsulate an error
// message. Note that this error message will incorporate the
// method chain and text passed by input parameter, 'ePrefix'.
// The 'ePrefix' text will be prefixed to the beginning of the
// error message.
//
//
// ------------------------------------------------------------------------
//
// Example Usage
//
// testStr := "Hello[SPACE]world!\\n"
// ePrefix := "theCallingFunction()"
//
// ePrefQuark := errPrefQuark{}
//
// actualRuneArray :=
// ePrefQuark.
// convertPrintableChars(
// testStr,
// ePrefix)
//
// ----------------------------------------------------
// 'actualRuneArray' is now equal to:
// "Hello world!\n"
//
func (ePref ErrPref) ConvertPrintableChars(
printableChars string,
ePrefix string) (
nonPrintableChars []rune,
err error) {
if ePref.lock == nil {
ePref.lock = new(sync.Mutex)
}
ePref.lock.Lock()
defer ePref.lock.Unlock()
if len(ePrefix) > 0 {
ePrefix += "\n"
}
ePrefix += "ErrPref.ConvertPrintableChars() "
nonPrintableChars,
err = errPrefQuark{}.ptr().convertPrintableChars(
printableChars,
ePrefix)
return nonPrintableChars, err
}
// FmtStr - Returns a formatted text representation of all error
// prefix and error context information contained in the input
// parameter string, 'errPref'.
//
// Error prefix text is designed to be configured at the beginning
// of error messages and is most often used to document the thread
// of code execution by listing the calling sequence for a specific
// list of functions and methods.
//
// The error context descriptive text provides additional
// information about the function or method identified in the
// associated error prefix string. Typical context information
// might include variable names, variable values and further
// details on function execution.
//
// The returned formatted text is generated using system default
// string delimiters.
//
// The system default string delimiters are listed as follows:
//
// New Line Error Prefix Delimiter = "\n"
// In-Line Error Prefix Delimiter = " - "
// New Line Error Context Delimiter = "\n : "
// In-Line Error Context Delimiter = " : "
//
//
// ------------------------------------------------------------------------
//
// Input Parameters
//
// errPref string
// - This string holds a series of error prefix and error
// context text elements. Each element must be separated by
// either a new line character '\n' or the string " - ". This
// will format these elements and return them in a properly
// configured error prefix string for text presentation.
//
//
// ------------------------------------------------------------------------
//
// Return Values
//
// string
// - A string containing properly formatted error prefix and
// error context pairs configured for configuration in an
// error message.
//
func (ePref ErrPref) FmtStr(
errPref string) string {
if ePref.lock == nil {
ePref.lock = new(sync.Mutex)
}
ePref.lock.Lock()
defer ePref.lock.Unlock()
ePref.maxErrPrefixTextLineLength =
errPrefQuark{}.ptr().getErrPrefDisplayLineLength()
delimiters := ErrPrefixDelimiters{}.NewDefaults()
return errPrefMechanics{}.ptr().formatErrPrefix(
ePref.maxErrPrefixTextLineLength,
delimiters,
errPref)
}
// GetDelimiters - Returns an ErrPrefixDelimiters object containing
// the string delimiters used to delimit error prefix and error
// context elements with strings.
//
// The ErrPref type uses the system default string delimiters for
// parsing both input and output error prefix and context strings.
//
// The system default string delimiters are listed as follows:
//
// New Line Error Prefix Delimiter = "\n"
// In-Line Error Prefix Delimiter = " - "
// New Line Error Context Delimiter = "\n : "
// In-Line Error Context Delimiter = " : "
//
func (ePref ErrPref) GetDelimiters() ErrPrefixDelimiters {
if ePref.lock == nil {
ePref.lock = new(sync.Mutex)
}
ePref.lock.Lock()
defer ePref.lock.Unlock()
delimiters := ErrPrefixDelimiters{}.NewDefaults()
return delimiters
}
// GetLastEPref - Returns the last error prefix, error context pair
// from a string consisting of a series of error prefix, error
// context pairs.
//
// The input parameter 'oldErrPrefix' will be parsed and the last
// error prefix and error context pair will be identified using
// system default string delimiters.
//
// The system default string delimiters are listed as follows:
//
// New Line Error Prefix Delimiter = "\n"
// In-Line Error Prefix Delimiter = " - "
// New Line Error Context Delimiter = "\n : "
// In-Line Error Context Delimiter = " : "
//
func (ePref ErrPref) GetLastEPref(
oldErrPrefix string) string {
if ePref.lock == nil {
ePref.lock = new(sync.Mutex)
}
ePref.lock.Lock()
defer ePref.lock.Unlock()
ePref.maxErrPrefixTextLineLength =
errPrefQuark{}.ptr().getErrPrefDisplayLineLength()
delimiters := ErrPrefixDelimiters{}.NewDefaults()
return errPrefMechanics{}.ptr().
extractLastErrPrefCtxPair(
ePref.maxErrPrefixTextLineLength,
oldErrPrefix,
delimiters)
}
// GetMaxErrPrefTextLineLength - Returns the current maximum number
// of characters allowed in an error prefix text line output
// display.
//
// To change or reset this maximum limit value, see method:
// ErrPref.SetMaxErrPrefTextLineLength().
//
//
// ------------------------------------------------------------------------
//
// Input Parameters
//
// --- NONE ---
//
//
// ------------------------------------------------------------------------
//
// Return Values
//
// maxErrPrefixStringLength uint
// - This method will return an unsigned integer value
// specifying the maximum number of characters allowed
// in an error prefix text display line.
//
func (ePref ErrPref) GetMaxErrPrefTextLineLength() (
maxErrPrefixStringLength uint) {
if ePref.lock == nil {
ePref.lock = new(sync.Mutex)
}
ePref.lock.Lock()
defer ePref.lock.Unlock()
ePrefQuark := errPrefQuark{}
maxErrPrefixStringLength =
ePrefQuark.getErrPrefDisplayLineLength()
return maxErrPrefixStringLength
}
// EPref - Returns a string concatenating the old error prefix the
// new custom, user-defined error prefix. The new error prefix is
// typically used to document method or function chains in error
// messages.
//
// The old error prefix contains the function chain or series which
// led to the function next in line for execution.
//
// The error prefix text is designed to be configured at the
// beginning of error messages and is most often used to document
// the thread of code execution by listing the calling sequence for
// specific functions and methods.
//
// - IMPORTANT -
//
// The last line of error prefix strings returned by the methods on
// this type are NOT terminated with a new line character ('\n').
// That means that the last line of error prefix strings will never
// end with a new line character ('\n').
//
// If you prefer that the last line of error prefix strings be
// terminated with a new line character ('\n'), you have two
// options:
//
// 1. Add the terminating new line character in your code.
//
// OR
//
// 2. Use the Error Prefix Data Transfer Object type
// 'ErrPrefixDto'.
//
//
// ----------------------------------------------------------------
//
// Input Parameters
//
// oldErrPref string
// - This includes the previous or preexisting error prefix
// string. This string will be parsed into error prefix
// and error context components before being converted into
// a single, formatted string containing error prefix and
// error context information.
//
// This string should consist of a series of error prefix
// strings. Error prefixes should be delimited using system
// default string delimiters.
//
// The system default string delimiters for error prefix
// elements are listed as follows:
// New Line Error Prefix Delimiter = "\n"
// In-Line Error Prefix Delimiter = " - "
//
// If this string contains associated error context strings
// as well, they should be delimited using the same system
// default string delimiters for error context elements:
// New Line Error Context Delimiter = "\n : "
// In-Line Error Context Delimiter = " : "
//
//
// newErrPref string
// - The new error prefix represents typically identifies
// the function or method which is currently executing. This
// information is used to document source code execution flow
// in error messages.
//
// If 'newErrPref' equates to an empty string, this method will
// return the formatted version of 'oldErrPref' and no new error
// prefix information will be added.
//
//
// -----------------------------------------------------------------
//
// Return Values
//
// string
// - This method will return the consolidated error prefix text.
//
// The error prefix text is designed to be configured at the
// beginning of error messages and is most often used to
// document the thread of code execution by listing the calling
// sequence for specific functions and methods.
//
//
func (ePref ErrPref) EPref(
oldErrPref string,
newErrPref string) string {
if ePref.lock == nil {
ePref.lock = new(sync.Mutex)
}
ePref.lock.Lock()
defer ePref.lock.Unlock()
ePrefQuark := errPrefQuark{}
ePref.maxErrPrefixTextLineLength =
ePrefQuark.getErrPrefDisplayLineLength()
delimiters := ErrPrefixDelimiters{}.NewDefaults()
ePrefMech := errPrefMechanics{}
return ePrefMech.assembleErrPrefix(
oldErrPref,
newErrPref,
"",
ePref.maxErrPrefixTextLineLength,
delimiters)
}
// EPrefCtx - Receives an old error prefix, new error prefix and
// a new context string which are concatenated and returned as a
// combined string.
//
// Error prefix text is designed to be configured at the beginning
// of error messages and is most often used to document the thread
// of code execution by listing the calling sequence for a specific
// list of functions and methods.
//
// The error context string is designed to provide additional
// information about the function or method identified by the
// associated error prefix string. Typical context information
// might include variable names, variable values and additional
// details on function execution.
//
// - IMPORTANT -
//
// The last line of error prefix strings returned by the methods on
// this type are NOT terminated with a new line character ('\n').
// That means that the last line of error prefix strings will never
// end with a new line character ('\n').
//
// If you prefer that the last line of error prefix strings be
// terminated with a new line character ('\n'), you have two
// options:
//
// 1. Add the terminating new line character in your code.
//
// OR
//
// 2. Use the Error Prefix Data Transfer Object type
// 'ErrPrefixDto'.
//
//
// ----------------------------------------------------------------
//
// Input Parameters
//
// oldErrPref string
// - This includes the previous or preexisting error prefix
// string. This string will be parsed into error prefix
// and error context components before being converted into
// a single, formatted string containing error prefix and
// error context information.
//
//
// This string should consist of a series of error prefix
// strings. Error prefixes should be delimited using system
// default string delimiters.
//
// The system default string delimiters for error prefix
// elements are listed as follows:
// New Line Error Prefix Delimiter = "\n"
// In-Line Error Prefix Delimiter = " - "
//
// If this string contains associated error context strings
// as well, they should be delimited using the same system
// default string delimiters for error context elements:
// New Line Error Context Delimiter = "\n : "
// In-Line Error Context Delimiter = " : "
//
//
// newErrPref string
// - The new error prefix represents the error prefix string
// associated with the function or method which is currently
// executing. This parameter is optional and will accept an
// empty string, but there isn't much point in calling this
// method without a substantive value for 'newErrPref'.
//
//
// newContext string
// - This is the error context information associated with the
// new error prefix ('newErrPref'). This parameter is
// optional and will accept an empty string.
//
//
// -----------------------------------------------------------------
//
// Return Values
//
// string
// - This method will return the consolidated error prefix text.
//
// The error prefix text is designed to be configured at the
// beginning of error messages and is most often used to
// document the thread of code execution by listing the calling
// sequence for specific functions and methods.
//
//
//
// -----------------------------------------------------------------
//
// Usage Examples
//
// errorPrefix = ErrPref{}.EPrefCtx(
// oldErrPref, // Assuming this is the old
// // error prefix
// newErrPref,
// newContext)
//
//
func (ePref ErrPref) EPrefCtx(
oldErrPref string,
newErrPref string,
newContext string) string {
if ePref.lock == nil {
ePref.lock = new(sync.Mutex)
}
ePref.lock.Lock()
defer ePref.lock.Unlock()
ePrefQuark := errPrefQuark{}
ePref.maxErrPrefixTextLineLength =
ePrefQuark.getErrPrefDisplayLineLength()
ePrefMech := errPrefMechanics{}
delimiters := ErrPrefixDelimiters{}.NewDefaults()
return ePrefMech.assembleErrPrefix(
oldErrPref,
newErrPref,
newContext,
ePref.maxErrPrefixTextLineLength,
delimiters)
}
// EPrefOld - Receives an old or preexisting error prefix string
// which is parsed into error prefix and error context components
// and returned as a properly formatted error prefix string.
//
// Error prefix text is designed to be configured at the beginning
// of error messages and is most often used to document the thread
// of code execution by listing the calling sequence for a specific
// list of functions and methods.
//
// The error context string is designed to provide additional
// information about the function or method identified by the
// associated error prefix string. Typical context information
// might include variable names, variable values and additional
// details on function execution.
//
// - IMPORTANT -
//
// The last line of error prefix strings returned by the methods on
// this type are NOT terminated with a new line character ('\n').
// That means that the last line of error prefix strings will never
// end with a new line character ('\n').
//
// If you prefer that the last line of error prefix strings be
// terminated with a new line character ('\n'), you have two
// options:
//
// 1. Add the terminating new line character in your code.
//
// OR
//
// 2. Use the Error Prefix Data Transfer Object type
// 'ErrPrefixDto'.
//
//
// ----------------------------------------------------------------
//
// Input Parameters
//
// oldErrPref string
// - This includes the previous or preexisting error prefix
// string. This string will be parsed into error prefix
// and error context components before being converted into
// a single, formatted string containing error prefix and
// error context information.
//
// This string should consist of a series of error prefix
// strings. Error prefixes should be delimited using system
// default string delimiters.
//
// The system default string delimiters for error prefix
// elements are listed as follows:
// New Line Error Prefix Delimiter = "\n"
// In-Line Error Prefix Delimiter = " - "
//
// If this string contains associated error context strings
// as well, they should be delimited using the same system
// default string delimiters for error context elements:
// New Line Error Context Delimiter = "\n : "
// In-Line Error Context Delimiter = " : "
//
//
// -----------------------------------------------------------------
//
// Return Values
//
// string
// - This method will return the consolidated error prefix text.
//
// The error prefix text is designed to be configured at the
// beginning of error messages and is most often used to
// document the thread of code execution by listing the calling
// sequence for specific functions and methods.
//
//
//
// -----------------------------------------------------------------
//
// Usage Examples
//
// errorPrefix = ErrPref{}.EPrefOld(
// oldErrPref) // Assuming this is the old
// // or preexisting error
// // prefix
//
//
func (ePref ErrPref) EPrefOld(
oldErrPref string) string {
if ePref.lock == nil {
ePref.lock = new(sync.Mutex)
}
ePref.lock.Lock()
defer ePref.lock.Unlock()
ePrefQuark := errPrefQuark{}
ePref.maxErrPrefixTextLineLength =
ePrefQuark.getErrPrefDisplayLineLength()
ePrefMech := errPrefMechanics{}
delimiters := ErrPrefixDelimiters{}.NewDefaults()
return ePrefMech.assembleErrPrefix(
oldErrPref,
"",
"",
ePref.maxErrPrefixTextLineLength,
delimiters)
}
// SetCtxt - Sets or resets the error context for the last error
// prefix. This operation either adds, or replaces, the error
// context string associated with the last error prefix in input
// parameter, 'oldErrPref'.
//
// If the last error prefix already has an error context string, it
// will be replaced by input parameter, 'newErrContext'.
//
// If the last error prefix does NOT have an associated error
// context, this new error context string will be associated
// with that error prefix.
//
// - IMPORTANT -
//
// The last line of error prefix strings returned by the methods on
// this type are NOT terminated with a new line character ('\n').
// That means that the last line of error prefix strings will never
// end with a new line character ('\n').
//
// If you prefer that the last line of error prefix strings be
// terminated with a new line character ('\n'), you have two
// options:
//
// 1. Add the terminating new line character in your code.
//
// OR
//
// 2. Use the Error Prefix Data Transfer Object type
// 'ErrPrefixDto'.
//
//
// ----------------------------------------------------------------
//
// Input Parameters
//
// oldErrPref string
// - This includes the previous or preexisting error prefix
// string. This string will be parsed into error prefix
// and error context components before being converted into
// a single, formatted string containing error prefix and
// error context information.
//
// This string should consist of a series of error prefix
// strings. Error prefixes should be delimited using system
// default string delimiters.
//
// The system default string delimiters for error prefix
// elements are listed as follows:
// New Line Error Prefix Delimiter = "\n"
// In-Line Error Prefix Delimiter = " - "
//
// If this string contains associated error context strings
// as well, they should be delimited using the same system
// default string delimiters for error context elements:
// New Line Error Context Delimiter = "\n : "
// In-Line Error Context Delimiter = " : "
//
//
// newErrContext string
// - This string holds the new error context information. If
// the last error prefix in 'oldErrPref' already has an
// associated error context, that context will be deleted and
// replaced by 'newErrContext'. If, however, the last error
// prefix in 'oldErrPref' does NOT have an associated error
// context, this 'newErrContext' string will be added and
// associated with the last error prefix in 'oldErrPref'.
//
//
// -----------------------------------------------------------------
//
// Return Values
//
// string
// - This method will return the consolidated error prefix text.
//
// The error prefix text is designed to be configured at the
// beginning of error messages and is most often used to
// document the thread of code execution by listing the calling
// sequence for specific functions and methods.
//
func (ePref ErrPref) SetCtxt(
oldErrPref string,
newErrContext string) string {
if ePref.lock == nil {
ePref.lock = new(sync.Mutex)
}
ePref.lock.Lock()
defer ePref.lock.Unlock()
ePref.maxErrPrefixTextLineLength =
errPrefQuark{}.ptr().
getErrPrefDisplayLineLength()
// Must have at least one error prefix
// before you can add an error context
if len(oldErrPref) == 0 {
return oldErrPref
}
if len(newErrContext) == 0 {
return oldErrPref
}
delimiters := ErrPrefixDelimiters{}.NewDefaults()
return errPrefMechanics{}.ptr().setErrorContext(
oldErrPref,
newErrContext,
ePref.maxErrPrefixTextLineLength,
delimiters)
}
// SetMaxErrPrefTextLineLength - Sets the maximum limit on the
// number of characters allowed in an error prefix text line output
// display.
//
// -IMPORTANT -
// Setting this value will control the maximum character limit not
// only for this ErrPref instance, but will also control all that
// limit for all other instances of ErrPref created in this session.
//
//
// ----------------------------------------------------------------
//
// Input Parameters
//
// maxErrPrefixTextLineLength uint
// - This unsigned integer value will be used to set the
// maximum number of characters allowed in a text display
// line for error prefix information.
//
// If 'maxErrPrefixTextLineLength' is set to a value of zero
// (0), this method will take no action and return.
//
//
// -----------------------------------------------------------------
//
// Return Values
//
// --- NONE ---
//
//
func (ePref ErrPref) SetMaxErrPrefTextLineLength(
maxErrPrefixTextLineLength uint) {
if ePref.lock == nil {
ePref.lock = new(sync.Mutex)
}
ePref.lock.Lock()
defer ePref.lock.Unlock()
errPrefQuark{}.ptr().setErrPrefDisplayLineLength(
maxErrPrefixTextLineLength)
return
}
// SetMaxErrPrefTextLineLengthToDefault - Maximum Error Prefix Line
// Length is the maximum limit on the number of characters allowed
// in a single error prefix text line.
//
// This method resets that maximum limit to its default value of
// 40-characters.
//
func (ePref ErrPref) SetMaxErrPrefTextLineLengthToDefault() {
if ePref.lock == nil {
ePref.lock = new(sync.Mutex)
}
ePref.lock.Lock()
defer ePref.lock.Unlock()
errPrefQuark{}.ptr().resetErrPrefDisplayLineLengthToDefault()
}