forked from dullgiulio/pingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.go
46 lines (35 loc) · 1.02 KB
/
errors.go
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
// Copyright 2015 Giulio Iotti. All rights reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package pingo
import (
"errors"
"strings"
)
const (
errorCodeConnFailed = "err-connection-failed"
errorCodeHttpServe = "err-http-serve"
)
// Error reported when connection to the external plugin has failed.
type ErrConnectionFailed error
// Error reported when the external plugin cannot start listening for calls.
type ErrHttpServe error
// Error reported when an invalid message is printed by the external plugin.
type ErrInvalidMessage error
// Error reported when the plugin fails to register before the registration
// timeout expires.
type ErrRegistrationTimeout error
func parseError(line string) error {
parts := strings.SplitN(line, ": ", 2)
if parts[0] == "" {
return nil
}
err := errors.New(parts[1])
switch parts[0] {
case errorCodeConnFailed:
return ErrConnectionFailed(err)
case errorCodeHttpServe:
return ErrHttpServe(err)
}
return err
}