codekingpro/portable-devtools
114k
1const {
2 GitConnectionError,
3 GitPathspecError,
4 GitUnknownError,
5} = require('./errors.js')
6
7const connectionErrorRe = new RegExp([
8 'remote error: Internal Server Error',
9 'The remote end hung up unexpectedly',
10 'Connection timed out',
11 'Operation timed out',
12 'Failed to connect to .* Timed out',
13 'Connection reset by peer',
14 'SSL_ERROR_SYSCALL',
15 'The requested URL returned error: 503',
16].join('|'))
17
18const missingPathspecRe = /pathspec .* did not match any file\(s\) known to git/
19
20function makeError (er) {
21 const message = er.stderr
22 let gitEr
23 if (connectionErrorRe.test(message)) {
24 gitEr = new GitConnectionError(message)
25 } else if (missingPathspecRe.test(message)) {
26 gitEr = new GitPathspecError(message)
27 } else {
28 gitEr = new GitUnknownError(message)
29 }
30 return Object.assign(gitEr, er)
31}
32
33module.exports = makeError
34 