mirror of
https://github.com/Mezeporta/Erupe.git
synced 2026-03-23 08:03:51 +01:00
fix: log SJIS decoding errors instead of silently discarding them
Add SJISToUTF8Lossy() that wraps SJISToUTF8() and logs decode errors at slog.Debug level. Replace all 31 call sites across 17 files that previously discarded the error with `_, _ =`. This makes garbled text from malformed SJIS client data debuggable without adding noise at default log levels.
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io"
|
||||
"log/slog"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@@ -40,6 +41,16 @@ func SJISToUTF8(b []byte) (string, error) {
|
||||
return string(result), nil
|
||||
}
|
||||
|
||||
// SJISToUTF8Lossy decodes Shift-JIS bytes to a UTF-8 string, logging
|
||||
// any decoding error at debug level instead of returning it.
|
||||
func SJISToUTF8Lossy(b []byte) string {
|
||||
s, err := SJISToUTF8(b)
|
||||
if err != nil {
|
||||
slog.Debug("SJIS decode failed", "error", err, "raw_len", len(b))
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// ToNGWord converts a UTF-8 string into a slice of uint16 values in the
|
||||
// Shift-JIS byte-swapped format used by the MHF NG-word (chat filter) system.
|
||||
func ToNGWord(x string) []uint16 {
|
||||
|
||||
Reference in New Issue
Block a user