Fossil SCM

fossil-scm / tools / cvs2fossil / lib / trouble.tcl
Blame History Raw 125 lines
1
## -*- tcl -*-
2
# # ## ### ##### ######## ############# #####################
3
## Copyright (c) 2007 Andreas Kupries.
4
#
5
# This software is licensed as described in the file LICENSE, which
6
# you should have received as part of this distribution.
7
#
8
# This software consists of voluntary contributions made by many
9
# individuals. For exact contribution history, see the revision
10
# history and logs, available at http://fossil-scm.hwaci.com/fossil
11
# # ## ### ##### ######## ############# #####################
12
13
## Utility package, error reporting on top of the log package.
14
15
# # ## ### ##### ######## ############# #####################
16
## Requirements
17
18
package require Tcl 8.4 ; # Required runtime.
19
package require vc::tools::log ; # Basic log generation.
20
package require snit ; # OO system.
21
22
# # ## ### ##### ######## ############# #####################
23
##
24
25
snit::type ::vc::tools::trouble {
26
# # ## ### ##### ######## #############
27
## Public API, Methods
28
29
typemethod internal {text} {
30
foreach line [split $text \n] { $type fatal "INTERNAL ERROR! $line" }
31
exit 1
32
}
33
34
typemethod fatal {text} {
35
lappend myfatal $text
36
return
37
}
38
39
typemethod warn {text} {
40
lappend mywarn $text
41
log write 0 trouble $text
42
return
43
}
44
45
typemethod info {text} {
46
lappend myinfo $text
47
return
48
}
49
50
typemethod show {} {
51
foreach m $myinfo { log write 0 "" $m }
52
foreach m $mywarn { log write 0 warning $m }
53
foreach m $myfatal { log write 0 fatal $m }
54
return
55
}
56
57
typemethod ? {} {
58
return [expr {
59
[llength $myinfo] ||
60
[llength $mywarn] ||
61
[llength $myfatal]
62
}]
63
}
64
65
typemethod abort? {} {
66
if {
67
![llength $myinfo] &&
68
![llength $mywarn] &&
69
![llength $myfatal]
70
} return
71
72
# Frame the pending messages to make them more clear as the
73
# cause of the abort.
74
75
set myinfo [linsert $myinfo 0 "" "Encountered problems." ""]
76
lappend myfatal "Stopped due to problems."
77
78
# We have error messages to print, so stop now.
79
exit 1
80
}
81
82
# # ## ### ##### ######## #############
83
## Internal, state
84
85
typevariable myinfo {}
86
typevariable mywarn {}
87
typevariable myfatal {}
88
89
# # ## ### ##### ######## #############
90
## Configuration
91
92
pragma -hasinstances no ; # singleton
93
pragma -hastypeinfo no ; # no introspection
94
pragma -hastypedestroy no ; # immortal
95
96
# # ## ### ##### ######## #############
97
}
98
99
# # ## ### ##### ######## ############# #####################
100
## Internal. Special. Set up a hook into the application exit, to show
101
## the remembered messages, before passing through the regular command.
102
103
rename ::exit ::vc::tools::trouble::EXIT
104
proc ::exit {{status 0}} {
105
::vc::tools::trouble show
106
::vc::tools::trouble::EXIT $status
107
# Not reached.
108
return
109
}
110
111
namespace eval ::vc::tools {
112
namespace eval trouble {namespace import ::vc::tools::log }
113
trouble::log register ""
114
trouble::log register fatal
115
trouble::log register trouble
116
trouble::log register warning
117
namespace export trouble
118
}
119
120
# # ## ### ##### ######## ############# #####################
121
## Ready
122
123
package provide vc::tools::trouble 1.0
124
return
125

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button