-
Notifications
You must be signed in to change notification settings - Fork 525
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve error reporting #2423
Improve error reporting #2423
Changes from all commits
117a1ea
8df0ed5
6e74c7c
d315ec9
ea32f48
a20a6c5
fa2f230
966b38e
b4f9550
bf2abbc
6d10d98
88f6b3a
ecc8be4
5e16733
c80c66a
9224d4c
07f320b
0025b85
79736fd
ee7d1ff
53c2063
73bce52
e8f3067
3cf9654
c00d52d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -545,11 +545,6 @@ open System.Diagnostics | |
open System.Threading | ||
open System.Collections.Generic | ||
|
||
let innerText (exn:Exception) = | ||
match exn.InnerException with | ||
| null -> "" | ||
| exn -> Environment.NewLine + " Details: " + exn.Message | ||
|
||
/// [omit] | ||
let downloadFromUrl (auth:Auth option, url : string) (filePath: string) = | ||
async { | ||
|
@@ -560,7 +555,7 @@ let downloadFromUrl (auth:Auth option, url : string) (filePath: string) = | |
do! task | ||
with | ||
| exn -> | ||
failwithf "Could not download from %s%s Message: %s%s" url Environment.NewLine exn.Message (innerText exn) | ||
raise <| Exception(sprintf "Could not download from '%s'" url, exn) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We almost never should do /cc @dsyme any ideas? |
||
} | ||
|
||
/// [omit] | ||
|
@@ -575,8 +570,8 @@ let getFromUrl (auth:Auth option, url : string, contentType : string) = | |
return! client.DownloadStringTaskAsync (Uri url) |> Async.AwaitTask | ||
with | ||
| exn -> | ||
failwithf "Could not retrieve data from %s%s Message: %s%s" url Environment.NewLine exn.Message (innerText exn) | ||
return "" | ||
return raise <| Exception(sprintf "Could not retrieve data from '%s'" url, exn) | ||
|
||
} | ||
|
||
let getXmlFromUrl (auth:Auth option, url : string) = | ||
|
@@ -593,8 +588,7 @@ let getXmlFromUrl (auth:Auth option, url : string) = | |
return! client.DownloadStringTaskAsync (Uri url) |> Async.AwaitTask | ||
with | ||
| exn -> | ||
failwithf "Could not retrieve data from %s%s Message: %s%s" url Environment.NewLine exn.Message (innerText exn) | ||
return "" | ||
return raise <| Exception(sprintf "Could not retrieve data from '%s'" url, exn) | ||
} | ||
|
||
/// [omit] | ||
|
@@ -612,11 +606,12 @@ let safeGetFromUrl (auth:Auth option, url : string, contentType : string) = | |
#endif | ||
use _ = Profile.startCategory Profile.Category.NuGetRequest | ||
let! raw = client.DownloadStringTaskAsync(uri) |> Async.AwaitTask | ||
return Some raw | ||
return FSharp.Core.Result.Ok raw | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I should use full-out exceptions everywhere :/ |
||
with e -> | ||
if verbose then | ||
Logging.verbosefn "Error while retrieving '%s': %O" url e | ||
return None | ||
let cap = System.Runtime.ExceptionServices.ExceptionDispatchInfo.Capture e | ||
return FSharp.Core.Result.Error cap | ||
} | ||
|
||
let mutable autoAnswer = None | ||
|
@@ -689,15 +684,15 @@ let RunInLockedAccessMode(rootFolder,action) = | |
waitForUnlocked 0 | ||
File.WriteAllText(fileName, string p.Id) | ||
with | ||
| exn when exn.Message = "timeout" -> | ||
failwithf "Could not acquire lock to %s.%sThe process timed out." fileName Environment.NewLine | ||
| exn -> | ||
| exn when exn.Message = "timeout" -> | ||
failwithf "Could not acquire lock to '%s'.%sThe process timed out." fileName Environment.NewLine | ||
| exn -> | ||
if trials > 0 then | ||
let trials = trials - 1 | ||
tracefn "Could not acquire lock to %s.%s%s%sTrials left: %d." fileName Environment.NewLine exn.Message Environment.NewLine trials | ||
acquireLock startTime timeOut trials | ||
else | ||
failwithf "Could not acquire lock to %s.%s%s" fileName Environment.NewLine exn.Message | ||
raise <| Exception(sprintf "Could not acquire lock to '%s'." fileName, exn) | ||
|
||
let rec releaseLock() = | ||
try | ||
|
@@ -840,7 +835,7 @@ let parseKeyValuePairs (s:string) : Dictionary<string,string> = | |
d | ||
with | ||
| exn -> | ||
failwithf "Could not parse %s as key/value pairs.%s%s" s Environment.NewLine exn.Message | ||
raise <| Exception(sprintf "Could not parse '%s' as key/value pairs." s, exn) | ||
|
||
let downloadStringSync (url : string) (client : WebClient) = | ||
try | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an interesting API.
It is almost like
Async.Choice
, but will return all the started tasks and an index which one matched the given function.