mirror of
https://github.com/safing/portbase
synced 2025-09-02 10:40:39 +00:00
Improve dsd errors
This commit is contained in:
parent
17fcefb403
commit
92169d826d
1 changed files with 4 additions and 3 deletions
|
@ -11,6 +11,7 @@ import (
|
||||||
// "github.com/pkg/bson"
|
// "github.com/pkg/bson"
|
||||||
|
|
||||||
"github.com/safing/portbase/formats/varint"
|
"github.com/safing/portbase/formats/varint"
|
||||||
|
"github.com/safing/portbase/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
// define types
|
// define types
|
||||||
|
@ -64,7 +65,7 @@ func LoadAsFormat(data []byte, format uint8, t interface{}) (interface{}, error)
|
||||||
case JSON:
|
case JSON:
|
||||||
err := json.Unmarshal(data, t)
|
err := json.Unmarshal(data, t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("dsd: failed to unpack json data: %s", data)
|
return nil, fmt.Errorf("dsd: failed to unpack json: %s, data: %s", err, utils.SafeFirst16Bytes(data))
|
||||||
}
|
}
|
||||||
return t, nil
|
return t, nil
|
||||||
case BSON:
|
case BSON:
|
||||||
|
@ -81,11 +82,11 @@ func LoadAsFormat(data []byte, format uint8, t interface{}) (interface{}, error)
|
||||||
}
|
}
|
||||||
_, err := genCodeStruct.GenCodeUnmarshal(data)
|
_, err := genCodeStruct.GenCodeUnmarshal(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("dsd: failed to unpack gencode data: %s", err)
|
return nil, fmt.Errorf("dsd: failed to unpack gencode: %s, data: %s", err, utils.SafeFirst16Bytes(data))
|
||||||
}
|
}
|
||||||
return t, nil
|
return t, nil
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("dsd: tried to load unknown type %d, data: %v", format, data)
|
return nil, fmt.Errorf("dsd: tried to load unknown type %d, data: %s", format, utils.SafeFirst16Bytes(data))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue