make-error.js 859 B

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