-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patherrsys.prg
276 lines (216 loc) · 8.22 KB
/
errsys.prg
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
// Error handler system adapted to FiveWeb
#include "FiveWeb.ch"
#include "common.ch"
#include "error.ch"
#define CRLF HB_OsNewLine()
#define NTRIM(n) ( LTrim( Str( n ) ) )
#define DLG_TITLE "FiveWeb for Harbour"
static aInitInfo
procedure ErrorSys
ErrorBlock( { | oError | ErrorDialog( oError ) } )
return
procedure ErrorLink
return
static function ErrorDialog( oError )
local cErrorLog := "", cMessage, n := 2, j, nButtons := 1
local oDlg, oLbx, aStack := {}, oOldError, lRet, aRDDs
// By default, division by zero results in zero
if oError:genCode == EG_ZERODIV
return 0
endif
// Set NetErr() of there was a database open error
if oError:genCode == EG_OPEN .and. ;
oError:osCode == 32 .and. ;
oError:canDefault
NetErr( .t. )
return .f.
endif
// Set NetErr() if there was a lock error on dbAppend()
if oError:genCode == EG_APPENDLOCK .and. oError:canDefault
NetErr( .t. )
return .f.
endif
if ProcName( 7 ) == "ERRORDIALOG" // recursive error !!!
ErrorLevel( 1 )
QUIT
endif
cErrorLog += "Application" + CRLF
cErrorLog += "===========" + CRLF
cErrorLog += " Path and name: " + HB_ArgV( 0 ) + " (32 bits)" + HB_OsNewLine()
// + GetModuleFileName( GetInstance() )
cErrorLog += " Time from start: " + TimeFromStart() + CRLF
cErrorLog += " Error occurred at: " + ;
DToC( Date() ) + ", " + Time() + CRLF
// Error object analysis
cMessage = "Error description: " + ErrorMessage( oError ) + CRLF
cErrorLog += " " + cMessage
if ValType( oError:Args ) == "A"
cErrorLog += " Args:" + CRLF
for n = 1 to Len( oError:Args )
cErrorLog += " [" + Str( n, 4 ) + "] = " + ;
ValType( oError:Args[ n ] ) + " " + ;
cValToChar( oError:Args[ n ] ) + CRLF
next
endif
cErrorLog += CRLF + "Stack Calls" + CRLF
cErrorLog += "===========" + CRLF
n = 2
while ( n < 74 )
if ! Empty( ProcName( n ) )
AAdd( aStack, " Called from " + Trim( ProcName( n ) ) + ;
"(" + NTRIM( ProcLine( n ) ) + ")" )
cErrorLog += ATail( aStack ) + CRLF
endif
n++
end
cErrorLog += CRLF + "Variables in use" + CRLF + "================" + CRLF
cErrorLog += " Procedure Type Value" + CRLF
cErrorLog += " ==========================" + CRLF
n = 2
while ( n < 74 )
if ! Empty( ProcName( n ) )
cErrorLog += " " + Trim( ProcName( n ) ) + CRLF
for j = 1 to ParamCount( n )
cErrorLog += " Param " + Str( j, 3 ) + ": " + ;
ValType( GetParam( n, j ) ) + ;
" " + cGetInfo( GetParam( n, j ) ) + CRLF
next
for j = 1 to LocalCount( n )
cErrorLog += " Local " + Str( j, 3 ) + ": " + ;
ValType( GetLocal( n, j ) ) + ;
" " + cGetInfo( GetLocal( n, j ) ) + CRLF
next
endif
n++
end
cErrorLog += CRLF + "Linked RDDs" + CRLF + "===========" + CRLF
aRDDs = RddList( 1 )
for n = 1 to Len( aRDDs )
cErrorLog += " " + aRDDs[ n ] + CRLF
next
cErrorLog += CRLF + "DataBases in use" + CRLF + "================" + CRLF
for n = 1 to 255
if ! Empty( Alias( n ) )
cErrorLog += CRLF + Str( n, 3 ) + ": " + If( Select() == n,"=> ", " " ) + ;
PadR( Alias( n ), 15 ) + Space( 20 ) + "RddName: " + ;
( Alias( n ) )->( RddName() ) + CRLF
cErrorLog += " ==============================" + CRLF
cErrorLog += " RecNo RecCount BOF EOF" + CRLF
cErrorLog += " " + Transform( ( Alias( n ) )->( RecNo() ), "99999" ) + ;
" " + Transform( ( Alias( n ) )->( RecCount() ), "99999" ) + ;
" " + cValToChar( ( Alias( n ) )->( BoF() ) ) + ;
" " + cValToChar( ( Alias( n ) )->( EoF() ) ) + CRLF + CRLF
cErrorLog += " Indexes in use " + Space( 23 ) + "TagName" + CRLF
for j = 1 to 15
if ! Empty( ( Alias( n ) )->( IndexKey( j ) ) )
cErrorLog += Space( 8 ) + ;
If( ( Alias( n ) )->( IndexOrd() ) == j, "=> ", " " ) + ;
PadR( ( Alias( n ) )->( IndexKey( j ) ), 35 ) + ;
( Alias( n ) )->( OrdName( j ) ) + ;
CRLF
endif
next
cErrorLog += CRLF + " Relations in use" + CRLF
for j = 1 to 8
if ! Empty( ( nTarget := ( Alias( n ) )->( DbRSelect( j ) ) ) )
cErrorLog += Space( 8 ) + Str( j ) + ": " + ;
"TO " + ( Alias( n ) )->( DbRelation( j ) ) + ;
" INTO " + Alias( nTarget ) + CRLF
// uValue = ( Alias( n ) )->( DbRelation( j ) )
// cErrorLog += cValToChar( &( uValue ) ) + CRLF
endif
next
endif
next
n = 1
cErrorLog += CRLF + "Classes in use:" + CRLF
cErrorLog += "===============" + CRLF
while ! Empty( __ClassName( n ) )
cErrorLog += " " + Str( n, 3 ) + " " + __ClassName( n++ ) + CRLF
end
cErrorLog += CRLF + "Memory Analysis" + CRLF
cErrorLog += "===============" + CRLF
cErrorLog += " " + LTrim( Str( nStatics() ) ) + " Static variables" + ;
CRLF + CRLF
cErrorLog += " Dynamic memory consume:" + CRLF
cErrorLog += " Actual Value: " + Str( MemUsed() ) + " bytes" + CRLF
cErrorLog += " Highest Value: " + Str( MemMax() ) + " bytes" + CRLF
BEGIN SEQUENCE
oOldError = ErrorBlock( { || DoBreak() } )
MemoWrit( "error.log", cErrorLog )
END SEQUENCE
ErrorBlock( oOldError )
if oError:canRetry
nButtons++
endif
if oError:canDefault
nButtons++
endif
? "FiveWeb error<br><br>"
for n = 1 to MLCount( cErrorLog )
? MemoLine( cErrorLog,, n ) + "<br>"
next
QUIT
return .F.
static func ErrorMessage( e )
// start error message
local cMessage := if( empty( e:OsCode ), ;
if( e:severity > ES_WARNING, "Error ", "Warning " ),;
"(DOS Error " + NTRIM(e:osCode) + ") " )
// add subsystem name if available
cMessage += if( ValType( e:SubSystem ) == "C",;
e:SubSystem() ,;
"???" )
// add subsystem's error code if available
cMessage += if( ValType( e:SubCode ) == "N",;
"/" + NTRIM( e:SubCode ) ,;
"/???" )
// add error description if available
if ( ValType( e:Description ) == "C" )
cMessage += CRLF + " " + e:Description
end
// add either filename or operation
cMessage += if( ! Empty( e:FileName ),;
": " + e:FileName ,;
if( !Empty( e:Operation ),;
": " + e:Operation ,;
"" ) )
return cMessage
static function DoBreak()
BREAK
return nil
static function cGetInfo( uVal )
local cType := ValType( uVal )
do case
case cType == "C"
return '"' + cValToChar( uVal ) + '"'
case cType == "O"
return "Class: " + uVal:ClassName()
case cType == "A"
return "Len: " + Str( Len( uVal ), 4 )
otherwise
return cValToChar( uVal )
endcase
return nil
init procedure InitTime()
aInitInfo = { Date(), Seconds() }
return
function TimeFromStart()
local nSeconds := SecsFromStart( aInitInfo[ 1 ], aInitInfo[ 2 ] )
local nHours := Int( nSeconds / 3600 )
local nMins := Int( ( nSeconds - ( nHours * 3600 ) ) / 60 )
local nSecs := Int( nSeconds - ( nHours * 3600 ) - ( nMins * 60 ) )
return AllTrim( Str( nHours ) ) + " hours " + ;
AllTrim( Str( nMins ) ) + " mins " + ;
AllTrim( Str( nSecs ) ) + " secs "
static function SecsFromStart( dInitDate, nInitSecs )
local nSeconds:= Seconds()
local nDays := Date() - dInitDate
if nDays < 0 // Surely you change the date after the beginning of the system
return 0
endif
if nDays > 0
nDays--
return ( 86399 - nInitSecs ) + ( nDays * 86399 ) + nSeconds
endif
return nSeconds - nInitSecs