-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrors.go
More file actions
66 lines (56 loc) · 1.91 KB
/
Copy patherrors.go
File metadata and controls
66 lines (56 loc) · 1.91 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
package hl7
import (
"errors"
"fmt"
"reflect"
)
var (
ErrSegmentInvalid = errors.New("hl7: invalid segment")
ErrSegmentTypeInvalid = errors.New("hl7: invalid segment type, expected a struct")
ErrTagInvalidFormat = errors.New("hl7: tag is not in the correct format, expected `hl7:\"segment:<name>\"`")
)
// InvalidMessageParserError describes an invalid argument passed to the parser.
type InvalidMessageParserError struct {
Type reflect.Type
}
func (e InvalidMessageParserError) Error() string {
if e.Type == nil {
return "hl7: Unmarshal(nil)"
}
if e.Type.Kind() != reflect.Pointer {
return "hl7: Unmarshal(non-pointer " + e.Type.String() + ")"
}
return "hl7: Unmarshal(nil " + e.Type.String() + ")"
}
// FieldError represents an error that occurred while processing a specific HL7 field.
// It provides context about which segment and field caused the error, making debugging
// in production healthcare systems significantly easier.
type FieldError struct {
Segment string // The segment name (e.g., "PID", "MSH")
Field int // The 1-based field index
Component int // The 1-based component index (0 if not applicable)
Value string // The raw value that caused the error
Err error // The underlying error
}
func (e *FieldError) Error() string {
if e.Component > 0 {
return fmt.Sprintf("hl7: %s.%d.%d: %v (value=%q)",
e.Segment, e.Field, e.Component, e.Err, e.Value)
}
return fmt.Sprintf("hl7: %s.%d: %v (value=%q)",
e.Segment, e.Field, e.Err, e.Value)
}
func (e *FieldError) Unwrap() error {
return e.Err
}
// SchemaError represents an error in schema definition or validation.
type SchemaError struct {
Path string // The schema path that caused the error (e.g., "segments.PID.fields.3")
Err error // The underlying error
}
func (e *SchemaError) Error() string {
return fmt.Sprintf("hl7: schema %s: %v", e.Path, e.Err)
}
func (e *SchemaError) Unwrap() error {
return e.Err
}