(rawConfig, context = {})
| 210 | } |
| 211 | |
| 212 | export function validateGuildConfigOrThrow(rawConfig, context = {}) { |
| 213 | const normalized = normalizeGuildConfig(rawConfig); |
| 214 | const parsed = GuildConfigSchema.safeParse(normalized); |
| 215 | |
| 216 | if (parsed.success) { |
| 217 | return stripLegacyLoggingFields({ |
| 218 | ...normalized, |
| 219 | logging: migrateLoggingConfig(normalized.logging, {}), |
| 220 | }); |
| 221 | } |
| 222 | |
| 223 | throw createError( |
| 224 | 'Invalid guild configuration payload', |
| 225 | ErrorTypes.VALIDATION, |
| 226 | 'Configuration payload is invalid. Please review provided values and try again.', |
| 227 | { |
| 228 | ...context, |
| 229 | errorCode: 'VALIDATION_FAILED', |
| 230 | issues: parsed.error.issues.map((issue) => ({ |
| 231 | path: issue.path.join('.'), |
| 232 | message: issue.message, |
| 233 | code: issue.code |
| 234 | })) |
| 235 | } |
| 236 | ); |
| 237 | } |
no test coverage detected