From a4a7fb43ce083dc533a19c644f5126164268caea Mon Sep 17 00:00:00 2001 From: Palapeli <26661008+mkwcat@users.noreply.github.com> Date: Mon, 6 Apr 2026 07:08:36 -0400 Subject: [PATCH] Sake: Apply lint suggestions --- sake/mario_kart_wii.go | 21 +++++++++++++-------- sake/storage.go | 4 +++- sake/tables.go | 2 +- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/sake/mario_kart_wii.go b/sake/mario_kart_wii.go index efdca5f..fb18568 100644 --- a/sake/mario_kart_wii.go +++ b/sake/mario_kart_wii.go @@ -209,7 +209,9 @@ func handleMarioKartWiiFileDownloadRequest(moduleName string, responseWriter htt responseWriter.Header().Set(SakeFileResultHeader, strconv.Itoa(SakeFileResultSuccess)) responseWriter.Header().Set("Content-Length", strconv.Itoa(len(file))) - responseWriter.Write(file) + if _, err := responseWriter.Write(file); err != nil { + logging.Error(moduleName, "Failed to write response:", err) + } } func handleMarioKartWiiGhostDownloadRequest(moduleName string, responseWriter http.ResponseWriter, request *http.Request) { @@ -274,7 +276,9 @@ func handleMarioKartWiiGhostDownloadRequest(moduleName string, responseWriter ht responseWriter.Header().Set(SakeFileResultHeader, strconv.Itoa(SakeFileResultSuccess)) responseWriter.Header().Set("Content-Length", strconv.Itoa(len(responseBody))) - responseWriter.Write(responseBody) + if _, err := responseWriter.Write(responseBody); err != nil { + logging.Error(moduleName, "Failed to write response:", err) + } } func handleMarioKartWiiFileUploadRequest(moduleName string, responseWriter http.ResponseWriter, request *http.Request) { @@ -365,7 +369,9 @@ func handleMarioKartWiiGhostUploadRequest(moduleName string, responseWriter http responseWriter.Header().Set(SakeFileResultHeader, strconv.Itoa(SakeFileResultFileNotFound)) return } - defer file.Close() + defer func() { + common.ShouldNotError(file.Close()) + }() if fileHeader.Size < common.RKGDFileMinSize || fileHeader.Size > common.RKGDFileMaxSize { logging.Error(moduleName, "The size of the ghost file is invalid:", aurora.Cyan(fileHeader.Size)) @@ -392,7 +398,7 @@ func handleMarioKartWiiGhostUploadRequest(moduleName string, responseWriter http ghostData.RecalculateCRC() if isContest { - ghostFile = nil + ghostData = nil } err = db.InsertMarioKartWiiGhostFile(regionId, courseId, score, pid, playerInfo, []byte(ghostData)) @@ -462,10 +468,9 @@ func filterMarioKartWiiFriendInfo(value string, isOwner bool) (string, Result) { } binaryData, err := base64.StdEncoding.DecodeString(value) - if err != nil { - // Shouldn't happen after validation - panic(err) - } + // Shouldn't error after validation + common.ShouldNotError(err) + // Only change if the Mii checksum is valid if len(binaryData) < 0x4C { return value, ResultSuccess diff --git a/sake/storage.go b/sake/storage.go index dff35be..765e162 100644 --- a/sake/storage.go +++ b/sake/storage.go @@ -232,7 +232,9 @@ func handleStorageRequest(moduleName string, w http.ResponseWriter, r *http.Requ w.Header().Set("Content-Type", "text/xml") w.Header().Set("Content-Length", strconv.Itoa(len(payload))) - w.Write(payload) + if _, err := w.Write(payload); err != nil { + logging.Error(moduleName, "Failed to write response:", err) + } } func getRequestIdentity(moduleName string, request StorageRequestCommon) (uint32, common.GameInfo, Result) { diff --git a/sake/tables.go b/sake/tables.go index eb58be5..5ba1b1d 100644 --- a/sake/tables.go +++ b/sake/tables.go @@ -127,7 +127,7 @@ var TableDefinitions = map[string]SakeTable{ OwnerPermDelete: PermissionAllowed, Hardened: true, Reserved: true, - SearchForRecordsHandler: getMarioKartWiiStoredGhostDataRecord, + SearchForRecordsHandler: getMarioKartWiiGhostDataRecord, Fields: map[string]SakeFieldDefinition{ "fileid": { Type: database.SakeFieldTypeInt,