Skip to content
Snippets Groups Projects
Commit f5d87011 authored by Jono Wenger's avatar Jono Wenger
Browse files

Fix progress callback error reporting

parent 0ec3de42
No related branches found
No related tags found
1 merge request!430XX-4277 / Fix file transfer crashes
......@@ -203,6 +203,7 @@ func (f *FileTransfer) Send(payload, recipientID []byte, retry float32,
base64.StdEncoding.EncodeToString(recipientID))
// Unmarshal recipient ID
jww.INFO.Printf("** FileTransfer.Send before id.Unmarshal")
recipient, err := id.Unmarshal(recipientID)
if err != nil {
return nil, err
......@@ -219,7 +220,11 @@ func (f *FileTransfer) Send(payload, recipientID []byte, retry float32,
Transmitted: int(arrived),
Total: int(total),
}
pm, err := json.Marshal(progress)
pm, err2 := json.Marshal(progress)
if err2 != nil {
jww.FATAL.Panicf(
"[FT] Failed to JSON marshal sent Progress object: %+v", err)
}
callback.Callback(pm, &FilePartTracker{t}, err)
}
......@@ -295,7 +300,11 @@ func (f *FileTransfer) RegisterSentProgressCallback(tidBytes []byte,
Transmitted: int(arrived),
Total: int(total),
}
pm, err := json.Marshal(progress)
pm, err2 := json.Marshal(progress)
if err2 != nil {
jww.FATAL.Panicf(
"[FT] Failed to JSON marshal sent Progress object: %+v", err)
}
callback.Callback(pm, &FilePartTracker{t}, err)
}
p := time.Millisecond * time.Duration(period)
......@@ -325,7 +334,11 @@ func (f *FileTransfer) RegisterReceivedProgressCallback(tidBytes []byte,
Transmitted: int(received),
Total: int(total),
}
pm, err := json.Marshal(progress)
pm, err2 := json.Marshal(progress)
if err2 != nil {
jww.FATAL.Panicf(
"[FT] Failed to JSON marshal received Progress object: %+v", err)
}
callback.Callback(pm, &FilePartTracker{t}, err)
}
p := time.Millisecond * time.Duration(period)
......@@ -392,10 +405,10 @@ func (fpt FilePartTracker) GetNumParts() int {
//
// Example JSON:
// {
// "Priority":1,
// "Category":"Test Events",
// "EventType":"Ping",
// "Details":"This is an example of an event report"
// "Priority": 1,
// "Category": "Test Events",
// "EventType": "Ping",
// "Details": "This is an example of an event report"
// }
type EventReport struct {
Priority int
......
......@@ -17,7 +17,9 @@ import (
"gitlab.com/xx_network/primitives/id"
)
// Creates example JSON outputs used in documentation.
func TestFileTransfer_inputs(t *testing.T) {
// FileSend
fs := &FileSend{
Name: "testfile.txt",
Type: "text file",
......@@ -28,6 +30,7 @@ func TestFileTransfer_inputs(t *testing.T) {
t.Log("FileSend example JSON:")
fmt.Printf("%s\n\n", fsm)
// ReceivedFile
tid, _ := fileTransfer.NewTransferID(csprng.NewSystemRNG())
sid, _ := id.NewRandomID(csprng.NewSystemRNG(), id.User)
rf := &ReceivedFile{
......@@ -42,6 +45,7 @@ func TestFileTransfer_inputs(t *testing.T) {
t.Log("ReceivedFile example JSON:")
fmt.Printf("%s\n\n", rfm)
// Progress
p := &Progress{
TransferID: &tid,
Completed: false,
......@@ -52,6 +56,7 @@ func TestFileTransfer_inputs(t *testing.T) {
t.Log("Progress example JSON:")
fmt.Printf("%s\n\n", pm)
// EventReport
er := &EventReport{
Priority: 1,
Category: "Test Events",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment