From d4ee96138774e8bc469f172bbb6276af89d6f240 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Fri, 30 Jun 2023 16:14:58 +0200 Subject: wallet-core: rename OperationAttempt->TaskRun, do not allow task result values anymore --- .../taler-wallet-core/src/operations/common.ts | 86 +++++++++------------- 1 file changed, 33 insertions(+), 53 deletions(-) (limited to 'packages/taler-wallet-core/src/operations/common.ts') diff --git a/packages/taler-wallet-core/src/operations/common.ts b/packages/taler-wallet-core/src/operations/common.ts index 620054cae..cc16a4704 100644 --- a/packages/taler-wallet-core/src/operations/common.ts +++ b/packages/taler-wallet-core/src/operations/common.ts @@ -433,25 +433,25 @@ async function storePendingTaskFinished( }); } -export async function runTaskWithErrorReporting( +export async function runTaskWithErrorReporting( ws: InternalWalletState, opId: TaskId, - f: () => Promise>, -): Promise> { + f: () => Promise, +): Promise { let maybeError: TalerErrorDetail | undefined; try { const resp = await f(); switch (resp.type) { - case OperationAttemptResultType.Error: + case TaskRunResultType.Error: await storePendingTaskError(ws, opId, resp.errorDetail); return resp; - case OperationAttemptResultType.Finished: + case TaskRunResultType.Finished: await storePendingTaskFinished(ws, opId); return resp; - case OperationAttemptResultType.Pending: + case TaskRunResultType.Pending: await storePendingTaskPending(ws, opId); return resp; - case OperationAttemptResultType.Longpoll: + case TaskRunResultType.Longpoll: return resp; } } catch (e) { @@ -459,7 +459,7 @@ export async function runTaskWithErrorReporting( if (ws.stopped) { logger.warn("crypto API stopped during shutdown, ignoring error"); return { - type: OperationAttemptResultType.Error, + type: TaskRunResultType.Error, errorDetail: makeErrorDetail( TalerErrorCode.WALLET_UNEXPECTED_EXCEPTION, {}, @@ -474,7 +474,7 @@ export async function runTaskWithErrorReporting( maybeError = e.errorDetail; await storePendingTaskError(ws, opId, maybeError!); return { - type: OperationAttemptResultType.Error, + type: TaskRunResultType.Error, errorDetail: e.errorDetail, }; } else if (e instanceof Error) { @@ -492,7 +492,7 @@ export async function runTaskWithErrorReporting( ); await storePendingTaskError(ws, opId, maybeError); return { - type: OperationAttemptResultType.Error, + type: TaskRunResultType.Error, errorDetail: maybeError, }; } else { @@ -504,7 +504,7 @@ export async function runTaskWithErrorReporting( ); await storePendingTaskError(ws, opId, maybeError); return { - type: OperationAttemptResultType.Error, + type: TaskRunResultType.Error, errorDetail: maybeError, }; } @@ -654,59 +654,55 @@ export interface TransactionManager { abort(): Promise; suspend(): Promise; resume(): Promise; - process(): Promise; + process(): Promise; } -export enum OperationAttemptResultType { +export enum TaskRunResultType { Finished = "finished", Pending = "pending", Error = "error", Longpoll = "longpoll", } -export type OperationAttemptResult = - | OperationAttemptFinishedResult - | OperationAttemptErrorResult - | OperationAttemptLongpollResult - | OperationAttemptPendingResult; +export type TaskRunResult = + | TaskRunFinishedResult + | TaskRunErrorResult + | TaskRunLongpollResult + | TaskRunPendingResult; -export namespace OperationAttemptResult { - export function finishedEmpty(): OperationAttemptResult { +export namespace TaskRunResult { + export function finished(): TaskRunResult { return { - type: OperationAttemptResultType.Finished, - result: undefined, + type: TaskRunResultType.Finished, }; } - export function pendingEmpty(): OperationAttemptResult { + export function pending(): TaskRunResult { return { - type: OperationAttemptResultType.Pending, - result: undefined, + type: TaskRunResultType.Pending, }; } - export function longpoll(): OperationAttemptResult { + export function longpoll(): TaskRunResult { return { - type: OperationAttemptResultType.Longpoll, + type: TaskRunResultType.Longpoll, }; } } -export interface OperationAttemptFinishedResult { - type: OperationAttemptResultType.Finished; - result: T; +export interface TaskRunFinishedResult { + type: TaskRunResultType.Finished; } -export interface OperationAttemptPendingResult { - type: OperationAttemptResultType.Pending; - result: T; +export interface TaskRunPendingResult { + type: TaskRunResultType.Pending; } -export interface OperationAttemptErrorResult { - type: OperationAttemptResultType.Error; +export interface TaskRunErrorResult { + type: TaskRunResultType.Error; errorDetail: TalerErrorDetail; } -export interface OperationAttemptLongpollResult { - type: OperationAttemptResultType.Longpoll; +export interface TaskRunLongpollResult { + type: TaskRunResultType.Longpoll; } export interface RetryInfo { @@ -942,19 +938,3 @@ export namespace TaskIdentifiers { return `${PendingTaskType.PeerPushCredit}:${ppi.peerPushPaymentIncomingId}` as TaskId; } } - -/** - * Run an operation handler, expect a success result and extract the success value. - */ -export async function unwrapOperationHandlerResultOrThrow( - res: OperationAttemptResult, -): Promise { - switch (res.type) { - case OperationAttemptResultType.Finished: - return res.result; - case OperationAttemptResultType.Error: - throw TalerError.fromUncheckedDetail(res.errorDetail); - default: - throw Error(`unexpected operation result (${res.type})`); - } -} -- cgit v1.2.3