Merge pull request #140 from ensan-hcl/refactor/ergonomic_error_message

refactor: ファイルが読み込めなかった際のエラーメッセージを改善し、深刻であるのかをわかりやすくした
This commit is contained in:
Miwa
2024-09-29 16:32:02 +09:00
committed by GitHub
4 changed files with 12 additions and 10 deletions

View File

@ -54,7 +54,7 @@ public final class DicdataStore {
let string = try String(contentsOf: self.requestOptions.dictionaryResourceURL.appendingPathComponent("louds/charID.chid", isDirectory: false), encoding: String.Encoding.utf8) let string = try String(contentsOf: self.requestOptions.dictionaryResourceURL.appendingPathComponent("louds/charID.chid", isDirectory: false), encoding: String.Encoding.utf8)
charsID = [Character: UInt8].init(uniqueKeysWithValues: string.enumerated().map {($0.element, UInt8($0.offset))}) charsID = [Character: UInt8].init(uniqueKeysWithValues: string.enumerated().map {($0.element, UInt8($0.offset))})
} catch { } catch {
debug("ファイルが存在しません: \(error)") debug("Error: louds/charID.chidが存在しません。このエラーは深刻ですが、テスト時には無視できる場合があります。Description: \(error)")
} }
do { do {
let url = requestOptions.dictionaryResourceURL.appendingPathComponent("mm.binary", isDirectory: false) let url = requestOptions.dictionaryResourceURL.appendingPathComponent("mm.binary", isDirectory: false)
@ -62,7 +62,7 @@ public final class DicdataStore {
let binaryData = try Data(contentsOf: url, options: [.uncached]) let binaryData = try Data(contentsOf: url, options: [.uncached])
self.mmValue = binaryData.toArray(of: Float.self).map {PValue($0)} self.mmValue = binaryData.toArray(of: Float.self).map {PValue($0)}
} catch { } catch {
debug("Failed to read the file.") debug("Error: mm.binaryが存在しません。このエラーは深刻ですが、テスト時には無視できる場合があります。Description: \(error)")
self.mmValue = [PValue].init(repeating: .zero, count: self.midCount * self.midCount) self.mmValue = [PValue].init(repeating: .zero, count: self.midCount * self.midCount)
} }
} }
@ -180,7 +180,11 @@ public final class DicdataStore {
self.loudses[query] = louds self.loudses[query] = louds
return louds return louds
} else { } else {
debug("loudsの読み込みに失敗identifierは\(query)(id: \(identifier))") if identifier == "user" || identifier == "memory" {
debug("Error: IDが\(identifier) (query: \(query))loudsファイルの読み込みに失敗しましたが")
} else {
debug("Error: IDが\(identifier) (query: \(query))loudsファイルの読み込みに失敗しましたIDに対する辞書データが存在しないことが想定される場合はこのエラーは深刻ではありませんが")
}
return nil return nil
} }
} }
@ -209,7 +213,6 @@ public final class DicdataStore {
} }
package func getDicdataFromLoudstxt3(identifier: String, indices: some Sequence<Int>) -> [DicdataElement] { package func getDicdataFromLoudstxt3(identifier: String, indices: some Sequence<Int>) -> [DicdataElement] {
debug("getDicdataFromLoudstxt3", identifier, indices)
// split = 2048 // split = 2048
let dict = [Int: [Int]].init(grouping: indices, by: {$0 >> 11}) let dict = [Int: [Int]].init(grouping: indices, by: {$0 >> 11})
var data: [DicdataElement] = [] var data: [DicdataElement] = []
@ -240,7 +243,6 @@ public final class DicdataStore {
} }
let toIndexLeft = toIndexRange?.startIndex ?? fromIndex let toIndexLeft = toIndexRange?.startIndex ?? fromIndex
let toIndexRight = min(toIndexRange?.endIndex ?? inputData.input.count, fromIndex + self.maxlength) let toIndexRight = min(toIndexRange?.endIndex ?? inputData.input.count, fromIndex + self.maxlength)
debug("getLOUDSDataInRange", fromIndex, toIndexRange?.description ?? "nil", toIndexLeft, toIndexRight)
if fromIndex > toIndexLeft || toIndexLeft >= toIndexRight { if fromIndex > toIndexLeft || toIndexLeft >= toIndexRight {
debug("getLOUDSDataInRange: index is wrong") debug("getLOUDSDataInRange: index is wrong")
return [] return []
@ -514,7 +516,7 @@ public final class DicdataStore {
let dicdata: [DicdataElement] = csvData.map {self.parseLoudstxt2FormattedEntry(from: $0)} let dicdata: [DicdataElement] = csvData.map {self.parseLoudstxt2FormattedEntry(from: $0)}
return dicdata return dicdata
} catch { } catch {
debug(error) debug("Error: ID\(lastRcid)Zero Hint Predictionのためのデータの読み込みに失敗しました Description: \(error.localizedDescription)")
return [] return []
} }
} }
@ -708,7 +710,7 @@ public final class DicdataStore {
let binaryData = try Data(contentsOf: url, options: [.uncached]) let binaryData = try Data(contentsOf: url, options: [.uncached])
return binaryData.toArray(of: (Int32, Float).self) return binaryData.toArray(of: (Int32, Float).self)
} catch { } catch {
debug("Failed to read the file.", error) debug("Error: Description: \(error.localizedDescription)")
return [] return []
} }
} }

View File

@ -623,7 +623,7 @@ final class LearningManager {
let string = try String(contentsOf: chidURL, encoding: .utf8) let string = try String(contentsOf: chidURL, encoding: .utf8)
target = [Character: UInt8].init(uniqueKeysWithValues: string.enumerated().map {($0.element, UInt8($0.offset))}) target = [Character: UInt8].init(uniqueKeysWithValues: string.enumerated().map {($0.element, UInt8($0.offset))})
} catch { } catch {
debug("ファイルが存在しません: \(error)") debug("Error: louds/charID.chidが存在しません。このエラーは深刻ですが、テスト時には無視できる場合があります。Description: \(error)")
} }
} }
private var char2UInt8: [Character: UInt8] = [:] private var char2UInt8: [Character: UInt8] = [:]

View File

@ -60,7 +60,7 @@ extension LOUDS {
do { do {
nodeIndex2ID = try Array(Data(contentsOf: charsURL, options: [.uncached])) // 2 nodeIndex2ID = try Array(Data(contentsOf: charsURL, options: [.uncached])) // 2
} catch { } catch {
debug("ファイルが存在しません: \(error)") debug("Error: \(identifier)に対するLOUDSファイルが存在しません。このエラーは無視できる可能性があります。 Description: \(error)")
return nil return nil
} }

View File

@ -46,7 +46,7 @@ public struct TextReplacer: Sendable {
self.emojiGroups = emojiGroups self.emojiGroups = emojiGroups
self.emojiSearchDict = emojiSearchDict self.emojiSearchDict = emojiSearchDict
} catch { } catch {
debug(error) debug("Error: 絵文字データを読み込めませんでした。このエラーは深刻ではありません。 Description: \(error.localizedDescription)")
self.emojiSearchDict = emojiSearchDict self.emojiSearchDict = emojiSearchDict
self.emojiGroups = emojiGroups self.emojiGroups = emojiGroups
return return