-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringify.js
133 lines (118 loc) · 2.91 KB
/
stringify.js
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
const util = require('./util');
/*
* Stringify objects from the Twitter Fabric (Crashlytics) API.
*/
const stringify = module.exports = {
session(obj) {
const {issue, session} = obj;
function header() {
return [
stringify.app(obj),
stringify.issue(issue),
].join('\n');
}
function details() {
return [
`System: ${[
stringify.os(session.os),
stringify.device(session.device),
].join(' on ')}`,
`Storage: ${[
`disk ${stringify.storage(session.storage)}`,
`memory ${stringify.storage(session.memory)}`,
].join(' and ')}`,
`Orientation: ${stringify.orientation(session.orientation)}`,
`Session: ${session.session_id}`,
`Timestamp: ${session.created_at}`,
].join('\n');
}
function footer() {
return [
'Exported from Twitter Fabric in plaintext',
'by Unravel (https://github.com/jamesreggio/unravel)',
].join(' ');
}
return [
header(),
details(),
stringify.stacktrace(session.stacktraces),
footer(),
].join('\n\n');
},
app(obj) {
return [
obj.app.name,
obj.session.host_app.version.build,
`(${obj.app.bundle_identifier})`,
].join(' ');
},
os(obj) {
return [
(obj.name === 'ios') ? 'iOS' : obj.name,
obj.display,
`(${obj.build})`,
].join(' ');
},
device(obj) {
return [
obj.manufacturer,
obj.name,
`(${obj.architecture})`,
].join(' ');
},
issue(obj) {
return `Issue #${obj.display_id} (Level ${obj.impact_level})`;
},
storage(obj) {
return [
`${Math.round(obj.free / (obj.free + obj.used) * 100)}% free`,
`(${Math.round(obj.free / (1024 * 1024))} MB)`,
].join(' ');
},
orientation(obj) {
if (obj.device === 'unknown' && obj.ui === 'unknown') {
return 'unknown';
}
return `device is ${obj.device} and UI is ${obj.ui}`;
},
stacktrace(obj) {
return obj
.exceptions.concat(obj.errors)
.filter((obj) => obj.frames && obj.frames.length)
.concat(obj.threads)
.map(stringify.thread)
.join('\n\n');
},
thread(obj, i) {
function header() {
let str = `[Thread ${i}]`;
if (obj.caption.title !== 'Thread') {
str = `${str} ${obj.caption.title}`;
}
if (obj.caption.subtitle) {
str = `${str}\n${obj.caption.subtitle}`;
}
return str;
}
return [
header(),
obj.frames
.map(stringify.frame)
.join('\n') || 'No frames recorded.',
].join('\n');
},
frame(obj, i) {
return [
[
obj.blamed ? '>' : ' ',
util.alignr(i, 2),
].join(''),
util.alignl(obj.library, 30),
util.alignl(obj.address, 10),
obj.symbol,
obj.file ?
`(${obj.file.split('/').pop()}:${obj.line})` :
`+ ${obj.offset}`,
].join(' ');
},
};