~hkdb/geary/bionic

« back to all changes in this revision

Viewing changes to src/engine/api/geary-problem-report.vala

  • Committer: hkdb
  • Date: 2019-09-26 18:29:27 UTC
  • Revision ID: hkdb@3df.io-20190926182927-5371bd6xoib95isx
Tags: upstream-3.32.2-bionic
ImportĀ upstreamĀ versionĀ 3.32.2-bionic

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2016 Software Freedom Conservancy Inc.
 
3
 * Copyright 2017-2018 Michael Gratton <mike@vee.net>
 
4
 *
 
5
 * This software is licensed under the GNU Lesser General Public License
 
6
 * (version 2.1 or later).  See the COPYING file in this distribution.
 
7
 */
 
8
 
 
9
/** Describes available problem types. */
 
10
public enum Geary.ProblemType {
 
11
 
 
12
 
 
13
    /** Indicates an engine problem not covered by one of the other types. */
 
14
    GENERIC_ERROR,
 
15
 
 
16
    /** Indicates an error opening, using or closing the account database. */
 
17
    DATABASE_FAILURE,
 
18
 
 
19
    /** Indicates a problem establishing a connection. */
 
20
    CONNECTION_ERROR,
 
21
 
 
22
    /** Indicates a problem caused by a network operation. */
 
23
    NETWORK_ERROR,
 
24
 
 
25
    /** Indicates a non-network related server error. */
 
26
    SERVER_ERROR,
 
27
 
 
28
    /** Indicates credentials supplied for authentication were rejected. */
 
29
    AUTHENTICATION,
 
30
 
 
31
    /** Indicates a remote TLS certificate failed validation. */
 
32
    UNTRUSTED,
 
33
 
 
34
    /** Indicates an outgoing message was sent, but not saved. */
 
35
    SEND_EMAIL_SAVE_FAILED;
 
36
 
 
37
 
 
38
    /** Determines the appropriate problem type for an IOError. */
 
39
    public static ProblemType for_ioerror(IOError error) {
 
40
        if (error is IOError.CONNECTION_REFUSED ||
 
41
            error is IOError.HOST_NOT_FOUND ||
 
42
            error is IOError.HOST_UNREACHABLE ||
 
43
            error is IOError.NETWORK_UNREACHABLE) {
 
44
            return ProblemType.CONNECTION_ERROR;
 
45
        }
 
46
 
 
47
        if (error is IOError.CONNECTION_CLOSED ||
 
48
            error is IOError.NOT_CONNECTED) {
 
49
            return ProblemType.NETWORK_ERROR;
 
50
        }
 
51
 
 
52
        return ProblemType.GENERIC_ERROR;
 
53
    }
 
54
 
 
55
}
 
56
 
 
57
/**
 
58
 * Describes a error that the engine encountered, for reporting to the client.
 
59
 */
 
60
public class Geary.ProblemReport : Object {
 
61
 
 
62
 
 
63
    /** Describes the type of being reported. */
 
64
    public ProblemType problem_type { get; private set; }
 
65
 
 
66
    /** The exception caused the problem, if any. */
 
67
    public ErrorContext? error { get; private set; default = null; }
 
68
 
 
69
 
 
70
    public ProblemReport(ProblemType type, Error? error) {
 
71
        this.problem_type = type;
 
72
        if (error != null) {
 
73
            this.error = new ErrorContext(error);
 
74
        }
 
75
    }
 
76
 
 
77
    /** Returns a string representation of the report, for debugging only. */
 
78
    public string to_string() {
 
79
        return "%s: %s".printf(
 
80
            this.problem_type.to_string(),
 
81
            this.error != null
 
82
                ? this.error.format_full_error()
 
83
                : "no error reported"
 
84
        );
 
85
    }
 
86
 
 
87
}
 
88
 
 
89
/**
 
90
 * Describes an account-related error that the engine encountered.
 
91
 */
 
92
public class Geary.AccountProblemReport : ProblemReport {
 
93
 
 
94
 
 
95
    /** The account related to the problem report. */
 
96
    public AccountInformation account { get; private set; }
 
97
 
 
98
 
 
99
    public AccountProblemReport(ProblemType type, AccountInformation account, Error? error) {
 
100
        base(type, error);
 
101
        this.account = account;
 
102
    }
 
103
 
 
104
    /** Returns a string representation of the report, for debugging only. */
 
105
    public new string to_string() {
 
106
        return "%s: %s".printf(this.account.id, base.to_string());
 
107
    }
 
108
 
 
109
}
 
110
 
 
111
/**
 
112
 * Describes a service-related error that the engine encountered.
 
113
 */
 
114
public class Geary.ServiceProblemReport : AccountProblemReport {
 
115
 
 
116
 
 
117
    /** The service related to the problem report. */
 
118
    public ServiceInformation service { get; private set; }
 
119
 
 
120
 
 
121
    public ServiceProblemReport(ProblemType type,
 
122
                                AccountInformation account,
 
123
                                ServiceInformation service,
 
124
                                Error? error) {
 
125
        base(type, account, error);
 
126
        this.service = service;
 
127
    }
 
128
 
 
129
    /** Returns a string representation of the report, for debugging only. */
 
130
    public new string to_string() {
 
131
        return "%s: %s: %s: %s".printf(
 
132
            this.account.id,
 
133
            this.service.protocol.to_string(),
 
134
            this.problem_type.to_string(),
 
135
            this.error != null
 
136
                ? this.error.format_full_error()
 
137
                : "no error reported"
 
138
        );
 
139
    }
 
140
 
 
141
}