Skip to content

Commit

Permalink
chore: match every case in switch statements
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdecaf committed Nov 28, 2023
1 parent 642af40 commit 22ef465
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 5 additions & 1 deletion file.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (f File) buildTransactions(recordHeader RecordHeader, currentLine *int) (st
ReturnCreditRecord: make([]Transaction, 0),
ReturnDebitRecord: make([]Transaction, 0),
}
for _, t := range f.Txns {
for idx, t := range f.Txns {
switch t.GetType() {
case DebitRecord:
recTypeToTxs[DebitRecord] = append(recTypeToTxs[DebitRecord], t)
Expand All @@ -188,6 +188,8 @@ func (f File) buildTransactions(recordHeader RecordHeader, currentLine *int) (st
recTypeToTxs[ReturnCreditRecord] = append(recTypeToTxs[ReturnCreditRecord], t)
case ReturnDebitRecord:
recTypeToTxs[ReturnDebitRecord] = append(recTypeToTxs[ReturnDebitRecord], t)
case HeaderRecord, NoticeOfChangeRecord, NoticeOfChangeHeader, NoticeOfChangeFooter, FooterRecord:
return "", fmt.Errorf("transaction[%d] has unexpected record type: %v", idx, t.GetType())
}
}
var sb strings.Builder
Expand Down Expand Up @@ -299,6 +301,8 @@ func NewTransaction(
txn = lo.ToPtr(NewCreditReverse(txnType, amount, date, institutionID, payorPayeeAccountNo, itemTraceNo, originatorShortName, payorPayeeName, originatorLongName, originalOrReturnInstitutionID, originalOrReturnAccountNo, originalItemTraceNo, opts...))
case DebitReverseRecord:
txn = lo.ToPtr(NewDebitReverse(txnType, amount, date, institutionID, payorPayeeAccountNo, itemTraceNo, originatorShortName, payorPayeeName, originatorLongName, originalOrReturnInstitutionID, originalOrReturnAccountNo, originalItemTraceNo, opts...))
case HeaderRecord, NoticeOfChangeRecord, NoticeOfChangeHeader, NoticeOfChangeFooter, FooterRecord:
return nil
}
return txn
}
Expand Down
3 changes: 3 additions & 0 deletions file_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cadeft

import (
"bufio"
"fmt"
"io"
"strings"

Expand Down Expand Up @@ -180,6 +181,8 @@ func (fs *FileStreamer) ScanTxn() (Transaction, error) {
if err := dr.Parse(txnsSegment[startIdx:endIdx]); err != nil {
return nil, newStreamParseError(err, string(DebitReverseRecord), fs.currentTxn, fs.currentLine)
}
case HeaderRecord, NoticeOfChangeRecord, NoticeOfChangeHeader, NoticeOfChangeFooter, FooterRecord:
return nil, fmt.Errorf("invalid record type: %v", recordType)
}
return txn, nil
}
Expand Down
3 changes: 3 additions & 0 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cadeft

import (
"bufio"
"fmt"
"io"

"github.com/pkg/errors"
Expand Down Expand Up @@ -97,6 +98,8 @@ func (r *Reader) parseTxnRecord(data string) error {
return errors.Wrap(err, "failed to parse credit return transaction")
}
r.File.Txns = append(r.File.Txns, &creditReturns)
case HeaderRecord, FooterRecord, CreditReverseRecord, DebitReverseRecord, NoticeOfChangeRecord, NoticeOfChangeHeader, NoticeOfChangeFooter:
return fmt.Errorf("unexpected %s record", recType)
}
startIdx = endIdx
endIdx += segmentLength
Expand Down

0 comments on commit 22ef465

Please sign in to comment.