-
Notifications
You must be signed in to change notification settings - Fork 3.2k
/
errors.coffee
82 lines (62 loc) · 2 KB
/
errors.coffee
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
$dom = require("../dom")
$utils = require("../cypress/utils")
crossOriginScriptRe = /^script error/i
create = (state, config, log) ->
commandErr = (err) ->
current = state("current")
log({
end: true
snapshot: true
error: err
consoleProps: ->
obj = {}
## if type isnt parent then we know its dual or child
## and we can add Applied To if there is a prev command
## and it is a parent
if current.get("type") isnt "parent" and prev = current.get("prev")
ret = if $dom.isElement(prev.get("subject"))
$dom.getElements(prev.get("subject"))
else
prev.get("subject")
obj["Applied To"] = ret
obj
})
createUncaughtException = (type, args) ->
[msg, source, lineno, colno, err] = args
current = state("current")
## reset the msg on a cross origin script error
## since no details are accessible
if crossOriginScriptRe.test(msg)
msg = $utils.errMessageByPath("uncaught.cross_origin_script")
createErrFromMsg = ->
new Error $utils.errMessageByPath("uncaught.error", { msg, source, lineno })
## if we have the 5th argument it means we're in a super
## modern browser making this super simple to work with.
err ?= createErrFromMsg()
err.name = "Uncaught " + err.name
suffixMsg = switch type
when "app" then "uncaught.fromApp"
when "spec" then "uncaught.fromSpec"
err = $utils.appendErrMsg(err, $utils.errMessageByPath(suffixMsg))
err.onFail = ->
if l = current and current.getLastLog()
l.error(err)
return err
commandRunningFailed = (err) ->
## allow for our own custom onFail function
if err.onFail
err.onFail(err)
## clean up this onFail callback
## after its been called
delete err.onFail
else
commandErr(err)
return {
## submit a generic command error
commandErr
commandRunningFailed
createUncaughtException
}
module.exports = {
create
}