diff --git a/mdm/checkin.go b/mdm/checkin.go index 425756f..8f4e6ff 100644 --- a/mdm/checkin.go +++ b/mdm/checkin.go @@ -149,6 +149,9 @@ func (w *checkinUnmarshaller) UnmarshalPlist(f func(interface{}) error) error { func DecodeCheckin(rawMessage []byte) (message interface{}, err error) { w := &checkinUnmarshaller{raw: rawMessage} err = plist.Unmarshal(rawMessage, w) + if err != nil { + err = &ParseError{Err: err, Body: rawMessage} + } message = w.message return } diff --git a/mdm/command.go b/mdm/command.go index f7c1ea1..f10b707 100644 --- a/mdm/command.go +++ b/mdm/command.go @@ -35,6 +35,7 @@ func DecodeCommandResults(rawResults []byte) (results *CommandResults, err error results = new(CommandResults) err = plist.Unmarshal(rawResults, results) if err != nil { + err = &ParseError{Err: err, Body: rawResults} return } results.Raw = rawResults @@ -58,7 +59,7 @@ func DecodeCommand(rawCommand []byte) (command *Command, err error) { command = new(Command) err = plist.Unmarshal(rawCommand, command) if err != nil { - return + return nil, &ParseError{Err: err, Body: rawCommand} } command.Raw = rawCommand if command.CommandUUID == "" || command.Command.RequestType == "" { diff --git a/mdm/mdm.go b/mdm/mdm.go index e3ec762..23c62b7 100644 --- a/mdm/mdm.go +++ b/mdm/mdm.go @@ -5,6 +5,7 @@ import ( "context" "crypto/x509" "errors" + "fmt" ) // Enrollment represents the various enrollment-related data sent with requests. @@ -59,3 +60,16 @@ func (r *Request) Clone() *Request { *r2 = *r return r2 } + +type ParseError struct { + Err error + Body []byte +} + +func (e *ParseError) Unwrap() error { + return e.Err +} + +func (e *ParseError) Error() string { + return fmt.Sprintf("parse error: %s: raw body: %v", e.Err, string(e.Body)) +}