File: err.py

package info (click to toggle)
secrets 12.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,616 kB
  • sloc: python: 6,838; xml: 7; makefile: 4
file content (32 lines) | stat: -rw-r--r-- 833 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# SPDX-License-Identifier: GPL-3.0-only
from enum import IntEnum

from gi.repository import GLib

QUARK = GLib.quark_from_string("secrets")


class ErrorType(IntEnum):
    UNSUPPORTED_FORMAT = 0
    UNKNOWN = 1
    CREDENTIALS_ERROR = 2

    def message(self):
        match self:
            case ErrorType.UNSUPPORTED_FORMAT:
                return "The kdb Format is not Supported"
            case ErrorType.UNKNOWN:
                return "Unknown error"
            case ErrorType.CREDENTIALS_ERROR:
                return "Invalid credentials"
            case _other:
                msg = "Unrecognized error"
                raise ValueError(msg)


def generic_error(msg):
    return GLib.Error.new_literal(QUARK, msg, ErrorType.UNKNOWN)


def error(type_):
    return GLib.Error.new_literal(QUARK, type_.message(), type_)