73 lines
3 KiB
Text
73 lines
3 KiB
Text
|
|
// SPDX-License-Identifier: GPL-3.0-only
|
||
|
|
// SPDX-FileCopyrightText: Copyright (C) 2026 Catcrafts®
|
||
|
|
|
||
|
|
export module Nostro.App:Errors;
|
||
|
|
|
||
|
|
import std;
|
||
|
|
import Nostro;
|
||
|
|
|
||
|
|
// What went wrong, said so that the user knows what happened to their money and what to do next. nostrod's errors
|
||
|
|
// are told apart by their names and by what was being done: a payment that got no clear answer may have been made,
|
||
|
|
// which a listing that got none never is.
|
||
|
|
|
||
|
|
export namespace Nostro::App {
|
||
|
|
// What nostrod is asked to do, as far as that decides whether it asks for a password and what an error to it means.
|
||
|
|
enum class Operation : std::uint8_t {
|
||
|
|
Load, // any reading: accounts, payments, cards
|
||
|
|
Send,
|
||
|
|
Schedule,
|
||
|
|
Draft,
|
||
|
|
Request,
|
||
|
|
RevokeRequest,
|
||
|
|
PayRequest,
|
||
|
|
RejectRequest,
|
||
|
|
CancelSchedule,
|
||
|
|
AcceptDraft,
|
||
|
|
RejectDraft,
|
||
|
|
FreezeCard,
|
||
|
|
UnfreezeCard,
|
||
|
|
BlockCard,
|
||
|
|
AddConnection,
|
||
|
|
RemoveConnection,
|
||
|
|
SetCheckoutAccount
|
||
|
|
};
|
||
|
|
|
||
|
|
// The polkit action nostrod checks before it does that (Bus::action…).
|
||
|
|
std::string_view ActionOf(Operation operation) noexcept;
|
||
|
|
// Whether the system asks for the user's password before it, by the policy nostro installs: in the user's own
|
||
|
|
// session only what moves money, unfreezes or blocks a card, or changes the connections. An administrator's rules
|
||
|
|
// may ask for more or less; this decides nothing but what the user is told to expect.
|
||
|
|
bool AsksPassword(Operation operation) noexcept;
|
||
|
|
// Whether money leaves an account by it.
|
||
|
|
bool MovesMoney(Operation operation) noexcept;
|
||
|
|
|
||
|
|
enum class Problem : std::uint8_t {
|
||
|
|
Input, // refused before anything was sent
|
||
|
|
NotConfirmed, // no password was given, or nothing could ask for one
|
||
|
|
NotAllowed, // the system's policy refused
|
||
|
|
CannotAsk, // nostrod was not allowed to show a password dialog
|
||
|
|
OwnAccountsOnly, // the bank lets this connection pay between the user's own accounts only
|
||
|
|
Bank, // the bank refused
|
||
|
|
Unknown, // no clear answer: it may have been carried out
|
||
|
|
NoService, // nostrod is not there and cannot be started
|
||
|
|
Late, // a reading that got no answer in time
|
||
|
|
Failed // anything else
|
||
|
|
};
|
||
|
|
|
||
|
|
// There is no connecting to the system bus, which nostrod is talked to over: what the app's host threw when asked
|
||
|
|
// for a client.
|
||
|
|
struct NoSystemBus : std::runtime_error {
|
||
|
|
using std::runtime_error::runtime_error;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct Guidance {
|
||
|
|
Problem problem = Problem::Failed;
|
||
|
|
std::string title;
|
||
|
|
std::string detail;
|
||
|
|
bool mayHaveHappened = false; // look before asking again
|
||
|
|
bool retry = false; // asking again is safe, and may work
|
||
|
|
};
|
||
|
|
|
||
|
|
// What an answer's error means for what was asked.
|
||
|
|
Guidance Explain(const std::exception_ptr& error, Operation operation);
|
||
|
|
}
|