forked from Liquipedia/Lua-Modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror_display.lua
More file actions
81 lines (67 loc) · 2.22 KB
/
Copy patherror_display.lua
File metadata and controls
81 lines (67 loc) · 2.22 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
---
-- @Liquipedia
-- wiki=commons
-- page=Module:Error/Display
--
-- Please see https://github.com/Liquipedia/Lua-Modules to contribute
--
local ErrorExt = require('Module:Error/Ext')
local TypeUtil = require('Module:TypeUtil')
local ErrorDisplay = {types = {}, propTypes = {}}
-- Error instance
ErrorDisplay.types.Error = TypeUtil.struct{
childErrors = TypeUtil.optional(TypeUtil.array(ErrorDisplay.types.Error)),
header = 'string?',
innerError = 'any',
message = 'string',
originalErrors = TypeUtil.optional(TypeUtil.array(ErrorDisplay.types.Error)),
stacks = TypeUtil.optional(TypeUtil.array('string')),
}
ErrorDisplay.propTypes.Box = {
hasDetails = 'boolean?',
loggedInOnly = 'boolean?',
text = 'string',
}
function ErrorDisplay.Box(props)
local div = mw.html.create('div'):addClass('navigation-not-searchable ambox-wrapper')
:addClass('ambox wiki-bordercolor-dark wiki-backgroundcolor-light')
:addClass(props.loggedInOnly ~= false and 'show-when-logged-in' or nil)
:addClass('ambox-red')
local tbl = mw.html.create('table')
local tr = tbl:tag('tr')
tr:tag('td'):addClass('ambox-image')
:wikitext('[[File:Emblem-important.svg|40px|link=]]')
tr:tag('td'):addClass('ambox-text')
:wikitext(props.text)
:wikitext(props.hasDetails and ' (stack trace logged)' or nil)
return div:node(tbl)
end
function ErrorDisplay.ErrorBox(error)
return ErrorDisplay.Box({
hasDetails = error.stacks ~= nil,
text = tostring(error),
})
end
--[[
Shows the message and stack trace of a lua error. Suitable for use in a popup.
]]
function ErrorDisplay.ErrorDetails(error)
local errorDetailsNode = mw.html.create('div'):addClass('error-details')
errorDetailsNode:tag('div'):addClass('error-details-text')
:addClass('error')
:css('font-weight', 'bold')
:wikitext(error.header)
:wikitext(error.message)
local stackTraceString = ErrorExt.makeFullStackTrace(error)
if stackTraceString ~= '' then
errorDetailsNode:tag('div'):addClass('error-details-stacks')
:wikitext(stackTraceString)
end
local extraPropsString = ErrorExt.printExtraProps(error)
if extraPropsString then
errorDetailsNode:tag('div'):addClass('error-details-additional-props')
:wikitext(extraPropsString)
end
return errorDetailsNode
end
return ErrorDisplay