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
This commit is part of merge request !430. Comments created here will be created in the context of that merge request.
...@@ -203,6 +203,7 @@ func (f *FileTransfer) Send(payload, recipientID []byte, retry float32, ...@@ -203,6 +203,7 @@ func (f *FileTransfer) Send(payload, recipientID []byte, retry float32,
base64.StdEncoding.EncodeToString(recipientID)) base64.StdEncoding.EncodeToString(recipientID))
// Unmarshal recipient ID // Unmarshal recipient ID
jww.INFO.Printf("** FileTransfer.Send before id.Unmarshal")
recipient, err := id.Unmarshal(recipientID) recipient, err := id.Unmarshal(recipientID)
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -219,7 +220,11 @@ func (f *FileTransfer) Send(payload, recipientID []byte, retry float32, ...@@ -219,7 +220,11 @@ func (f *FileTransfer) Send(payload, recipientID []byte, retry float32,
Transmitted: int(arrived), Transmitted: int(arrived),
Total: int(total), 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) callback.Callback(pm, &FilePartTracker{t}, err)
} }
...@@ -295,7 +300,11 @@ func (f *FileTransfer) RegisterSentProgressCallback(tidBytes []byte, ...@@ -295,7 +300,11 @@ func (f *FileTransfer) RegisterSentProgressCallback(tidBytes []byte,
Transmitted: int(arrived), Transmitted: int(arrived),
Total: int(total), 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) callback.Callback(pm, &FilePartTracker{t}, err)
} }
p := time.Millisecond * time.Duration(period) p := time.Millisecond * time.Duration(period)
...@@ -325,7 +334,11 @@ func (f *FileTransfer) RegisterReceivedProgressCallback(tidBytes []byte, ...@@ -325,7 +334,11 @@ func (f *FileTransfer) RegisterReceivedProgressCallback(tidBytes []byte,
Transmitted: int(received), Transmitted: int(received),
Total: int(total), 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) callback.Callback(pm, &FilePartTracker{t}, err)
} }
p := time.Millisecond * time.Duration(period) p := time.Millisecond * time.Duration(period)
...@@ -392,10 +405,10 @@ func (fpt FilePartTracker) GetNumParts() int { ...@@ -392,10 +405,10 @@ func (fpt FilePartTracker) GetNumParts() int {
// //
// Example JSON: // Example JSON:
// { // {
// "Priority":1, // "Priority": 1,
// "Category":"Test Events", // "Category": "Test Events",
// "EventType":"Ping", // "EventType": "Ping",
// "Details":"This is an example of an event report" // "Details": "This is an example of an event report"
// } // }
type EventReport struct { type EventReport struct {
Priority int Priority int
......
...@@ -17,7 +17,9 @@ import ( ...@@ -17,7 +17,9 @@ import (
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
) )
// Creates example JSON outputs used in documentation.
func TestFileTransfer_inputs(t *testing.T) { func TestFileTransfer_inputs(t *testing.T) {
// FileSend
fs := &FileSend{ fs := &FileSend{
Name: "testfile.txt", Name: "testfile.txt",
Type: "text file", Type: "text file",
...@@ -28,6 +30,7 @@ func TestFileTransfer_inputs(t *testing.T) { ...@@ -28,6 +30,7 @@ func TestFileTransfer_inputs(t *testing.T) {
t.Log("FileSend example JSON:") t.Log("FileSend example JSON:")
fmt.Printf("%s\n\n", fsm) fmt.Printf("%s\n\n", fsm)
// ReceivedFile
tid, _ := fileTransfer.NewTransferID(csprng.NewSystemRNG()) tid, _ := fileTransfer.NewTransferID(csprng.NewSystemRNG())
sid, _ := id.NewRandomID(csprng.NewSystemRNG(), id.User) sid, _ := id.NewRandomID(csprng.NewSystemRNG(), id.User)
rf := &ReceivedFile{ rf := &ReceivedFile{
...@@ -42,6 +45,7 @@ func TestFileTransfer_inputs(t *testing.T) { ...@@ -42,6 +45,7 @@ func TestFileTransfer_inputs(t *testing.T) {
t.Log("ReceivedFile example JSON:") t.Log("ReceivedFile example JSON:")
fmt.Printf("%s\n\n", rfm) fmt.Printf("%s\n\n", rfm)
// Progress
p := &Progress{ p := &Progress{
TransferID: &tid, TransferID: &tid,
Completed: false, Completed: false,
...@@ -52,6 +56,7 @@ func TestFileTransfer_inputs(t *testing.T) { ...@@ -52,6 +56,7 @@ func TestFileTransfer_inputs(t *testing.T) {
t.Log("Progress example JSON:") t.Log("Progress example JSON:")
fmt.Printf("%s\n\n", pm) fmt.Printf("%s\n\n", pm)
// EventReport
er := &EventReport{ er := &EventReport{
Priority: 1, Priority: 1,
Category: "Test Events", 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