(name: string)
| 16 | } |
| 17 | |
| 18 | export function reportError(name: string) { |
| 19 | return Effect.fnUntraced( |
| 20 | function*( |
| 21 | cause: Cause.Cause<unknown>, |
| 22 | extras?: Record<string, unknown>, |
| 23 | level: LogLevel.Severity = "Error" |
| 24 | ) { |
| 25 | if (Cause.hasInterruptsOnly(cause)) { |
| 26 | yield* Effect.logDebug("Interrupted").pipe(Effect.annotateLogs("extras", JSON.stringify(extras ?? {}))) |
| 27 | return Cause.squash(cause) |
| 28 | } |
| 29 | |
| 30 | const error = tryCauseException(cause, name) |
| 31 | yield* reportSentry(error, extras, LogLevelToSentry(level)) |
| 32 | yield* Effect |
| 33 | .logWithLevel(level)("Reporting error", cause) |
| 34 | .pipe( |
| 35 | Effect.annotateLogs(dropUndefined({ |
| 36 | extras, |
| 37 | error: tryToReport(error), |
| 38 | cause: tryToJson(cause), |
| 39 | __error_name__: name |
| 40 | })), |
| 41 | Effect.catchCause((cause) => Effect.logWarning("Failed to log error", cause)), |
| 42 | Effect.catchCause(() => Effect.logFatal("Failed to log error cause")) |
| 43 | ) |
| 44 | |
| 45 | return error |
| 46 | }, |
| 47 | (effect) => |
| 48 | Effect.tapCause(effect, (cause) => |
| 49 | Effect.logError("Failed to report error", cause).pipe( |
| 50 | Effect.tapCause(() => Effect.logFatal("Failed to log error cause")) |
| 51 | )) |
| 52 | ) |
| 53 | } |
| 54 | |
| 55 | function reportSentry( |
| 56 | error: CauseException<unknown>, |
no test coverage detected
searching dependent graphs…