File: errors.h

package info (click to toggle)
picotool 2.1.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, trixie
  • size: 4,448 kB
  • sloc: cpp: 59,935; ansic: 2,513; python: 97; sh: 48; makefile: 27; xml: 18
file content (41 lines) | stat: -rw-r--r-- 830 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
#ifndef _ERRORS_H
#define _ERRORS_H

#ifdef _WIN32
#undef ERROR_CANCELLED
#endif

#include <string>

#define ERROR_ARGS (-1)
#define ERROR_FORMAT (-2)
#define ERROR_INCOMPATIBLE (-3)
#define ERROR_READ_FAILED (-4)
#define ERROR_WRITE_FAILED (-5)
#define ERROR_USB (-6)
#define ERROR_NO_DEVICE (-7)
#define ERROR_NOT_POSSIBLE (-8)
#define ERROR_CONNECTION (-9)
#define ERROR_CANCELLED (-10)
#define ERROR_VERIFICATION_FAILED (-11)
#define ERROR_UNKNOWN (-99)


struct command_failure : std::exception {
    command_failure(int code, std::string s) : c(code), s(std::move(s)) {}

    const char *what() const noexcept override {
        return s.c_str();
    }

    int code() const { return c; }
private:
    int c;
    std::string s;
};


void fail(int code, std::string msg);
void fail(int code, const char *format, ...);

#endif