Skip to content

Commit

Permalink
Add additional regex pattern for HostDown error code (#308)
Browse files Browse the repository at this point in the history
* Added new regex pattern to detect HostDown errors

An error in GitHub Desktop was being thrown that was not being appropriately parsed.

In order to properly catch it a new regular expression pattern has been added.

* Added test to check parsing for could not resolve host error

An exra regular expression pattern was added to detect a Git.HostDown error.

In order to make sure it is parsing correctly a test has been added.

* Updated New HostDown regex & test with new line characters

Previously the test and regex were missing the "↵" newline characters where appropriate. They have been added to match the original error's placement of new line characters.

* Updated HostDown regex and test string to use correct escape character newline

Previously a commit was added to properly handle newline characters. The characters used however are not newline escape characters. They have been updated to fix the previous issue.

* Simplify HostDown Regex by ignoring final newline character

Detecting the final newline character is not essential for the match to be made, therefore we can safely remove it.

Co-Authored-By: Daniel-McCarthy <[email protected]>
  • Loading branch information
Daniel-McCarthy authored and shiftkey committed Mar 4, 2019
1 parent b6f08de commit 6f3971f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export const GitErrorRegexes = {
'The requested URL returned error: 403': GitError.HTTPSAuthenticationFailed,
'fatal: The remote end hung up unexpectedly': GitError.RemoteDisconnection,
"fatal: unable to access '(.+)': Failed to connect to (.+): Host is down": GitError.HostDown,
"Cloning into '(.+)'...\nfatal: unable to access '(.+)': Could not resolve host: (.+)":
GitError.HostDown,
'Failed to merge in the changes.': GitError.RebaseConflicts,
'(Merge conflict|Automatic merge failed; fix conflicts and then commit the result)':
GitError.MergeConflicts,
Expand Down
7 changes: 7 additions & 0 deletions test/fast/git-process-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,5 +423,12 @@ mark them as resolved using git add`
const error = GitProcess.parseError(stderr)
expect(error).toBe(GitError.UnresolvedConflicts)
})

it('can parse the could not resolve host error', () => {
const stderr = `"Cloning into '/cloneablepath/'...\nfatal: unable to access 'https://github.com/Daniel-McCarthy/dugite.git/': Could not resolve host: github.com\n"`

const error = GitProcess.parseError(stderr)
expect(error).toBe(GitError.HostDown)
})
})
})

0 comments on commit 6f3971f

Please sign in to comment.