From 041971d0dc60dd57628d3de47e35fec35d411516 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Tue, 26 Feb 2019 16:08:36 +0200 Subject: [PATCH] Fix version inference by throwing on http 404 again (#69) Also, make all tests fail on errors --- feature_tests/basic/run.sh | 2 ++ feature_tests/existing_installation/run.sh | 2 ++ feature_tests/matching-dotfiles/run.sh | 2 ++ feature_tests/node-version/run.sh | 2 ++ feature_tests/node_mirror_installation/run.sh | 2 ++ feature_tests/nvmrc/run.sh | 2 ++ feature_tests/partial_semver/run.sh | 2 ++ library/Http.re | 11 +++++++---- library/Versions.re | 3 ++- 9 files changed, 23 insertions(+), 5 deletions(-) diff --git a/feature_tests/basic/run.sh b/feature_tests/basic/run.sh index f21db10..737f669 100644 --- a/feature_tests/basic/run.sh +++ b/feature_tests/basic/run.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + eval $(fnm env) fnm install v8.11.3 fnm use v8.11.3 diff --git a/feature_tests/existing_installation/run.sh b/feature_tests/existing_installation/run.sh index dc4b0ff..c8308e7 100644 --- a/feature_tests/existing_installation/run.sh +++ b/feature_tests/existing_installation/run.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + eval `fnm env` echo "> Installing for the first time..." diff --git a/feature_tests/matching-dotfiles/run.sh b/feature_tests/matching-dotfiles/run.sh index 61248e9..fa58c8a 100755 --- a/feature_tests/matching-dotfiles/run.sh +++ b/feature_tests/matching-dotfiles/run.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + eval $(fnm env) fnm install fnm use diff --git a/feature_tests/node-version/run.sh b/feature_tests/node-version/run.sh index 77b33b1..6c017ea 100644 --- a/feature_tests/node-version/run.sh +++ b/feature_tests/node-version/run.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + eval $(fnm env) fnm install fnm use diff --git a/feature_tests/node_mirror_installation/run.sh b/feature_tests/node_mirror_installation/run.sh index 1a895a0..b2afdf9 100644 --- a/feature_tests/node_mirror_installation/run.sh +++ b/feature_tests/node_mirror_installation/run.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + eval `fnm env --node-dist-mirror="https://cnpmjs.org/dist"` fnm install v8.11.3 diff --git a/feature_tests/nvmrc/run.sh b/feature_tests/nvmrc/run.sh index 4940e73..a4941a9 100644 --- a/feature_tests/nvmrc/run.sh +++ b/feature_tests/nvmrc/run.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + eval $(fnm env) fnm install fnm use diff --git a/feature_tests/partial_semver/run.sh b/feature_tests/partial_semver/run.sh index 5b4b7ad..857979b 100644 --- a/feature_tests/partial_semver/run.sh +++ b/feature_tests/partial_semver/run.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -e + eval `fnm env --multi` fnm install 6 # no new versions would be issued for this unsupported version diff --git a/library/Http.re b/library/Http.re index 3465c8b..6bb5b56 100644 --- a/library/Http.re +++ b/library/Http.re @@ -11,9 +11,12 @@ type response = { let body = response => response.body; let status = response => response.status; -exception Unknown_status_code(int, response); exception Not_found(response); -exception Internal_server_error(response); + +let throwOnKnownErrors = + fun + | {status: 404} as r => Lwt.fail(Not_found(r)) + | r => Lwt.return(r); let rec makeRequest = url => Uri.of_string(url) @@ -28,7 +31,7 @@ let rec makeRequest = url => | (true, Some(uri)) => makeRequest(Uri.to_string(uri)) | _ => let%lwt body = body |> Cohttp_lwt.Body.to_string; - Lwt.return({status: code_of_status, body}); + throwOnKnownErrors({status: code_of_status, body}); }; } ); @@ -36,4 +39,4 @@ let rec makeRequest = url => let download = (url, ~into) => { let%lwt _ = makeRequest(url) >>= (({body}) => Fs.writeFile(into, body)); Lwt.return(); -}; \ No newline at end of file +}; diff --git a/library/Versions.re b/library/Versions.re index 5153e40..8065e01 100644 --- a/library/Versions.re +++ b/library/Versions.re @@ -221,6 +221,7 @@ let getRemoteLatestVersionByPrefix = prefix => { open Lwt; let%lwt remoteVersions = getRemoteVersions(); + let compatibleVersions = remoteVersions |> List.map(x => x.name) @@ -314,4 +315,4 @@ let throwIfInstalled = versionName => { } else { Lwt.return(); }; -}; \ No newline at end of file +};