Skip to content

Commit e17cd73

Browse files
fix: panics in non-Must* functions
1 parent 46f9602 commit e17cd73

14 files changed

Lines changed: 66 additions & 52 deletions

File tree

message.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ var _ bin.EncoderDecoder = &Message{}
137137
// SetVersion sets the message version.
138138
// This method forces the message to be encoded in the specified version.
139139
// NOTE: if you set lookups, the version will default to V0.
140-
func (m *Message) SetVersion(version MessageVersion) *Message {
140+
func (m *Message) SetVersion(version MessageVersion) (*Message, error) {
141141
// check if the version is valid
142142
switch version {
143143
case MessageVersionV0, MessageVersionLegacy:
144144
default:
145-
panic(fmt.Errorf("invalid message version: %d", version))
145+
return nil, fmt.Errorf("invalid message version: %d", version)
146146
}
147147
m.version = version
148-
return m
148+
return m, nil
149149
}
150150

151151
// GetVersion returns the message version.

nativetypes.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,8 +329,7 @@ func (t Data) String() string {
329329
case EncodingBase64Zstd:
330330
enc, err := zstdEncoderPool.Get(nil)
331331
if err != nil {
332-
// TODO: remove panic?
333-
panic(err)
332+
return fmt.Sprintf("<zstd encoder error: %v>", err)
334333
}
335334
defer zstdEncoderPool.Put(enc)
336335
return base64.StdEncoding.EncodeToString(enc.EncodeAll(t.Content, nil))

programs/address-lookup-table/instructions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ import (
1414

1515
var ProgramID solana.PublicKey = solana.AddressLookupTableProgramID
1616

17-
func SetProgramID(pubkey solana.PublicKey) {
17+
func SetProgramID(pubkey solana.PublicKey) error {
1818
ProgramID = pubkey
19-
solana.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
19+
return solana.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
2020
}
2121

2222
const ProgramName = "AddressLookupTable"
2323

2424
func init() {
25-
solana.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
25+
solana.MustRegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
2626
}
2727

2828
const (

programs/associated-token-account/instructions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ import (
2727

2828
var ProgramID solana.PublicKey = solana.SPLAssociatedTokenAccountProgramID
2929

30-
func SetProgramID(pubkey solana.PublicKey) {
30+
func SetProgramID(pubkey solana.PublicKey) error {
3131
ProgramID = pubkey
32-
solana.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
32+
return solana.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
3333
}
3434

3535
const ProgramName = "AssociatedTokenAccount"
3636

3737
func init() {
38-
solana.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
38+
solana.MustRegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
3939
}
4040

4141
const (

programs/compute-budget/instruction.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,16 @@ import (
2727

2828
var ProgramID ag_solanago.PublicKey = ag_solanago.ComputeBudget
2929

30-
func SetProgramID(pubkey ag_solanago.PublicKey) {
30+
func SetProgramID(pubkey ag_solanago.PublicKey) error {
3131
ProgramID = pubkey
32-
ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
32+
return ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
3333
}
3434

3535
const ProgramName = "ComputeBudget"
3636

3737
func init() {
3838
if !ProgramID.IsZero() {
39-
ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
39+
ag_solanago.MustRegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
4040
}
4141
}
4242

programs/memo/instructions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ import (
2626

2727
var ProgramID = ag_solanago.MemoProgramID
2828

29-
func SetProgramID(pubkey ag_solanago.PublicKey) {
29+
func SetProgramID(pubkey ag_solanago.PublicKey) error {
3030
ProgramID = pubkey
31-
ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
31+
return ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
3232
}
3333

3434
func init() {
35-
ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
35+
ag_solanago.MustRegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
3636
}
3737

3838
type MemoInstruction struct {

programs/stake/instructions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ import (
2929

3030
var ProgramID solana.PublicKey = solana.StakeProgramID
3131

32-
func SetProgramID(pubkey solana.PublicKey) {
32+
func SetProgramID(pubkey solana.PublicKey) error {
3333
ProgramID = pubkey
34-
solana.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
34+
return solana.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
3535
}
3636

3737
const ProgramName = "Stake"
3838

3939
func init() {
40-
solana.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
40+
solana.MustRegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
4141
}
4242

4343
const (

programs/system/instructions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ import (
3131

3232
var ProgramID ag_solanago.PublicKey = ag_solanago.SystemProgramID
3333

34-
func SetProgramID(pubkey ag_solanago.PublicKey) {
34+
func SetProgramID(pubkey ag_solanago.PublicKey) error {
3535
ProgramID = pubkey
36-
ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
36+
return ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
3737
}
3838

3939
const ProgramName = "System"
4040

4141
func init() {
42-
ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
42+
ag_solanago.MustRegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
4343
}
4444

4545
const (

programs/token-2022/instructions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,16 @@ const MAX_SIGNERS = 11
3434

3535
var ProgramID ag_solanago.PublicKey = ag_solanago.Token2022ProgramID
3636

37-
func SetProgramID(pubkey ag_solanago.PublicKey) {
37+
func SetProgramID(pubkey ag_solanago.PublicKey) error {
3838
ProgramID = pubkey
39-
ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
39+
return ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
4040
}
4141

4242
const ProgramName = "Token2022"
4343

4444
func init() {
4545
if !ProgramID.IsZero() {
46-
ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
46+
ag_solanago.MustRegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
4747
}
4848
}
4949

programs/token/instructions.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ const MAX_SIGNERS = 11
3333

3434
var ProgramID ag_solanago.PublicKey = ag_solanago.TokenProgramID
3535

36-
func SetProgramID(pubkey ag_solanago.PublicKey) {
36+
func SetProgramID(pubkey ag_solanago.PublicKey) error {
3737
ProgramID = pubkey
38-
ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
38+
return ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
3939
}
4040

4141
const ProgramName = "Token"
4242

4343
func init() {
4444
if !ProgramID.IsZero() {
45-
ag_solanago.RegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
45+
ag_solanago.MustRegisterInstructionDecoder(ProgramID, registryDecodeInstruction)
4646
}
4747
}
4848

0 commit comments

Comments
 (0)