forked from sbarex/SourceCodeSyntaxHighlight
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSCSHError.swift
More file actions
68 lines (62 loc) · 2.09 KB
/
Copy pathSCSHError.swift
File metadata and controls
68 lines (62 loc) · 2.09 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// SCSHError.swift
// SCSHXPCService
//
// Created by sbarex on 16/10/2019.
// Copyright © 2019 sbarex. All rights reserved.
//
//
// This file is part of SyntaxHighlight.
// SyntaxHighlight is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// SyntaxHighlight is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with SyntaxHighlight. If not, see <http://www.gnu.org/licenses/>.
import Foundation
enum SCSHError: Error, LocalizedError {
case xpcGenericError(error: Error?)
case missingHighlight
case shellError(cmd: String, exitCode: Int, stdOut: String, stdErr: String, message: String?)
var errorDescription: String? {
get {
return self.description
}
}
var localizedDescription: String {
return self.description
}
var description: String {
switch self {
case .xpcGenericError(let error):
var s = "Error communicating with XPC service!"
if let e = error {
s += "\n\(e.localizedDescription)"
}
return s
case .shellError(let cmd, let exitCode, let stdOut, let stdErr, let message):
var s = ""
if let m = message, m.count > 0 {
s += "\(m)\n"
} else {
s += "Shell error!\n"
}
s += "command: \(cmd)\nexitCode: \(exitCode)"
if stdOut.count > 0 {
s += "\n\(stdOut)"
}
if stdErr.count > 0 {
s += "\n\(stdErr)"
}
return s
case .missingHighlight:
return "highlight not available!"
}
}
}