Skip to content

Commit db39439

Browse files
committed
DM Lua: Add all error messages to msgs table
1 parent 3a5c697 commit db39439

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

threaded-libcurl/DownloadManager.moon

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,12 @@ class DownloadManager
182182
getMissingArg: "Required argument (filename) was either absent or the wrong type. Expected string, got '%s'.",
183183
checkMissingArgs: "Required arguments #1 (filename/string) and #2 (expected) or the wrong type. Expected string, got '%s' and '%s'.",
184184
outNoFullPath: "Argument #2 (outfile) must contain a full path (relative paths not supported), got %s.",
185-
outNoFile: "Argument #2 (outfile) must contain a full path with file name, got %s."
185+
outNoFile: "Argument #2 (outfile) must contain a full path with file name, got %s.",
186+
failedToOpen: "Could not open file %s.",
187+
hashMismatch: "Hash mismatch. Got %s, expected %s.",
188+
horriblyWrong: "Something has gone horribly wrong???",
189+
cacheFailure: "Couldn't use cache. Message: %s",
190+
failedToAdd: "Could not add download for some reason."
186191
}
187192

188193
freeManager = ( manager ) ->
@@ -227,7 +232,7 @@ class DownloadManager
227232

228233
id = DM.CDlM_addDownload @manager, url, outfile, sha1, etag
229234
if id == 0
230-
return nil, "Could not add download for some reason."
235+
return nil, msgs.failedToAdd
231236

232237
download = { :id, :url, :outfile, :sha1, :etag }
233238
table.insert @downloads, download
@@ -274,7 +279,7 @@ class DownloadManager
274279
if DM.CDlM_fileWasCached @manager, download.id
275280
err, msg = @cache\useCache download
276281
if err == nil
277-
pushFailed download, "Couldn't use cache. Message: " .. msg
282+
pushFailed download, msgs.cacheFailure\format msg
278283

279284
else
280285
newETag = DM.CDlM_getETag @manager, download.id
@@ -297,7 +302,7 @@ class DownloadManager
297302

298303
result = DM.CDlM_getFileSHA1 filename
299304
if result == nil
300-
return nil, "Could not open file #{filename}."
305+
return nil, msgs.failedToOpen\format filename
301306
else
302307
result = ffi.string result
303308

@@ -314,7 +319,7 @@ class DownloadManager
314319
elseif result == expected\lower!
315320
return true
316321
else
317-
return false, "Hash mismatch. Got #{result}, expected #{expected}."
322+
return false, msgs.hashMismatch\format result, expected
318323

319324
checkStringSHA1: ( string, expected ) =>
320325
stringType, expectedType = type( string ), type expected
@@ -323,14 +328,14 @@ class DownloadManager
323328

324329
result = DM.CDlM_getStringSHA1 string
325330
if result == nil
326-
return nil, "Something has gone horribly wrong???"
331+
return nil, msgs.horriblyWrong
327332
else
328333
result = ffi.string result
329334

330335
if result == expected\lower!
331336
return true
332337
else
333-
return false, "Hash mismatch. Got #{result}, expected #{expected}."
338+
return false, msgs.hashMismatch\format result, expected
334339

335340
isInternetConnected: =>
336341
return DM.CDlM_isInternetConnected!

0 commit comments

Comments
 (0)