(transformed: Record<string, unknown>)
| 210 | } |
| 211 | |
| 212 | function salvageConfigData(transformed: Record<string, unknown>): SalvageResult { |
| 213 | const dropped: string[] = []; |
| 214 | for (;;) { |
| 215 | const result = KimiConfigSchema.safeParse(transformed); |
| 216 | if (result.success) { |
| 217 | return { config: result.data, dropped }; |
| 218 | } |
| 219 | let deletedAny = false; |
| 220 | for (const issue of result.error.issues) { |
| 221 | const [section, entry] = issue.path; |
| 222 | if (typeof section !== 'string' || !(section in transformed)) continue; |
| 223 | const sectionValue = transformed[section]; |
| 224 | if ( |
| 225 | ENTRY_KEYED_SECTIONS.has(section) && |
| 226 | typeof entry === 'string' && |
| 227 | isPlainObject(sectionValue) |
| 228 | ) { |
| 229 | // Issues on entry-keyed sections only ever drop that entry. An entry |
| 230 | // with several issues is deleted by the first one; later issues are |
| 231 | // no-ops and must not escalate to deleting the whole section. |
| 232 | if (entry in sectionValue) { |
| 233 | delete sectionValue[entry]; |
| 234 | dropped.push(`${camelToSnake(section)}.${entry}`); |
| 235 | deletedAny = true; |
| 236 | } |
| 237 | continue; |
| 238 | } |
| 239 | delete transformed[section]; |
| 240 | dropped.push(camelToSnake(section)); |
| 241 | deletedAny = true; |
| 242 | } |
| 243 | if (!deletedAny) { |
| 244 | return { config: undefined, dropped, error: result.error }; |
| 245 | } |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | function describeUnknownError(error: unknown): string { |
| 250 | return error instanceof Error ? error.message : String(error); |
no test coverage detected