spl_governance/
error.rs

1//! Error types
2
3use {
4    num_derive::FromPrimitive,
5    solana_program::{
6        decode_error::DecodeError,
7        msg,
8        program_error::{PrintProgramError, ProgramError},
9    },
10    thiserror::Error,
11};
12
13/// Errors that may be returned by the Governance program
14// Start Governance custom errors from 500 to avoid conflicts with programs
15// invoked via CPI
16#[derive(Clone, Debug, Eq, Error, FromPrimitive, PartialEq)]
17pub enum GovernanceError {
18    /// Invalid instruction passed to program
19    #[error("Invalid instruction passed to program")]
20    InvalidInstruction = 500,
21
22    /// Realm with the given name and governing mints already exists
23    #[error("Realm with the given name and governing mints already exists")]
24    RealmAlreadyExists,
25
26    /// Invalid Realm
27    #[error("Invalid realm")]
28    InvalidRealm,
29
30    /// Invalid Governing Token Mint
31    #[error("Invalid Governing Token Mint")]
32    InvalidGoverningTokenMint, // 503
33
34    /// Governing Token Owner must sign transaction
35    #[error("Governing Token Owner must sign transaction")]
36    GoverningTokenOwnerMustSign,
37
38    /// Governing Token Owner or Delegate  must sign transaction
39    #[error("Governing Token Owner or Delegate  must sign transaction")]
40    GoverningTokenOwnerOrDelegateMustSign, // 505
41
42    /// All votes must be relinquished to withdraw governing tokens
43    #[error("All votes must be relinquished to withdraw governing tokens")]
44    AllVotesMustBeRelinquishedToWithdrawGoverningTokens,
45
46    /// Invalid Token Owner Record account address
47    #[error("Invalid Token Owner Record account address")]
48    InvalidTokenOwnerRecordAccountAddress,
49
50    /// Invalid GoverningMint for TokenOwnerRecord
51    #[error("Invalid GoverningMint for TokenOwnerRecord")]
52    InvalidGoverningMintForTokenOwnerRecord, // 508
53
54    /// Invalid Realm for TokenOwnerRecord
55    #[error("Invalid Realm for TokenOwnerRecord")]
56    InvalidRealmForTokenOwnerRecord, // 509
57
58    /// Invalid Proposal for ProposalTransaction,
59    #[error("Invalid Proposal for ProposalTransaction,")]
60    InvalidProposalForProposalTransaction, // 510
61
62    /// Invalid Signatory account address
63    #[error("Invalid Signatory account address")]
64    InvalidSignatoryAddress, // 511
65
66    /// Signatory already signed off
67    #[error("Signatory already signed off")]
68    SignatoryAlreadySignedOff, // 512
69
70    /// Signatory must sign
71    #[error("Signatory must sign")]
72    SignatoryMustSign, // 513
73
74    /// Invalid Proposal Owner
75    #[error("Invalid Proposal Owner")]
76    InvalidProposalOwnerAccount, // 514
77
78    /// Invalid Proposal for VoterRecord
79    #[error("Invalid Proposal for VoterRecord")]
80    InvalidProposalForVoterRecord, // 515
81
82    /// Invalid GoverningTokenOwner  for VoteRecord
83    #[error("Invalid GoverningTokenOwner for VoteRecord")]
84    InvalidGoverningTokenOwnerForVoteRecord, // 516
85
86    /// Invalid Governance config: Vote threshold percentage out of range"
87    #[error("Invalid Governance config: Vote threshold percentage out of range")]
88    InvalidVoteThresholdPercentage, // 517
89
90    /// Proposal for the given Governance, Governing Token Mint and index
91    /// already exists
92    #[error("Proposal for the given Governance, Governing Token Mint and index already exists")]
93    ProposalAlreadyExists, // 518
94
95    /// Token Owner already voted on the Proposal
96    #[error("Token Owner already voted on the Proposal")]
97    VoteAlreadyExists, // 519
98
99    /// Owner doesn't have enough governing tokens to create Proposal
100    #[error("Owner doesn't have enough governing tokens to create Proposal")]
101    NotEnoughTokensToCreateProposal, // 520
102
103    /// Invalid State: Can't edit Signatories
104    #[error("Invalid State: Can't edit Signatories")]
105    InvalidStateCannotEditSignatories, // 521
106
107    /// Invalid Proposal state
108    #[error("Invalid Proposal state")]
109    InvalidProposalState, // 522
110
111    /// Invalid State: Can't edit transactions
112    #[error("Invalid State: Can't edit transactions")]
113    InvalidStateCannotEditTransactions, // 523
114
115    /// Invalid State: Can't execute transaction
116    #[error("Invalid State: Can't execute transaction")]
117    InvalidStateCannotExecuteTransaction, // 524
118
119    /// Can't execute transaction within its hold up time
120    #[error("Can't execute transaction within its hold up time")]
121    CannotExecuteTransactionWithinHoldUpTime, // 525
122
123    /// Transaction already executed
124    #[error("Transaction already executed")]
125    TransactionAlreadyExecuted, // 526
126
127    /// Invalid Transaction index
128    #[error("Invalid Transaction index")]
129    InvalidTransactionIndex, // 527
130
131    /// Transaction hold up time is below the min specified by Governance
132    #[error("Transaction hold up time is below the min specified by Governance")]
133    TransactionHoldUpTimeBelowRequiredMin, // 528
134
135    /// Transaction at the given index for the Proposal already exists
136    #[error("Transaction at the given index for the Proposal already exists")]
137    TransactionAlreadyExists, // 529
138
139    /// Invalid State: Can't sign off
140    #[error("Invalid State: Can't sign off")]
141    InvalidStateCannotSignOff, // 530
142
143    /// Invalid State: Can't vote
144    #[error("Invalid State: Can't vote")]
145    InvalidStateCannotVote, // 531
146
147    /// Invalid State: Can't finalize vote
148    #[error("Invalid State: Can't finalize vote")]
149    InvalidStateCannotFinalize, // 532
150
151    /// Invalid State: Can't cancel Proposal
152    #[error("Invalid State: Can't cancel Proposal")]
153    InvalidStateCannotCancelProposal, // 533
154
155    /// Vote already relinquished
156    #[error("Vote already relinquished")]
157    VoteAlreadyRelinquished, // 534
158
159    /// Can't finalize vote. Voting still in progress
160    #[error("Can't finalize vote. Voting still in progress")]
161    CannotFinalizeVotingInProgress, // 535
162
163    /// Proposal voting time expired
164    #[error("Proposal voting time expired")]
165    ProposalVotingTimeExpired, // 536
166
167    /// Invalid Signatory Mint
168    #[error("Invalid Signatory Mint")]
169    InvalidSignatoryMint, // 537
170
171    /// Proposal does not belong to the given Governance
172    #[error("Proposal does not belong to the given Governance")]
173    InvalidGovernanceForProposal, // 538
174
175    /// Proposal does not belong to given Governing Mint"
176    #[error("Proposal does not belong to given Governing Mint")]
177    InvalidGoverningMintForProposal, // 539
178
179    /// Current mint authority must sign transaction
180    #[error("Current mint authority must sign transaction")]
181    MintAuthorityMustSign, // 540
182
183    /// Invalid mint authority
184    #[error("Invalid mint authority")]
185    InvalidMintAuthority, // 542
186
187    /// Mint has no authority
188    #[error("Mint has no authority")]
189    MintHasNoAuthority, // 542
190
191    /// ---- SPL Token Tools Errors ----
192
193    /// Invalid Token account owner
194    #[error("Invalid Token account owner")]
195    SplTokenAccountWithInvalidOwner, // 543
196
197    /// Invalid Mint account owner
198    #[error("Invalid Mint account owner")]
199    SplTokenMintWithInvalidOwner, // 544
200
201    /// Token Account is not initialized
202    #[error("Token Account is not initialized")]
203    SplTokenAccountNotInitialized, // 545
204
205    /// Token Account doesn't exist
206    #[error("Token Account doesn't exist")]
207    SplTokenAccountDoesNotExist, // 546
208
209    /// Token account data is invalid
210    #[error("Token account data is invalid")]
211    SplTokenInvalidTokenAccountData, // 547
212
213    /// Token mint account data is invalid
214    #[error("Token mint account data is invalid")]
215    SplTokenInvalidMintAccountData, // 548
216
217    /// Token Mint is not initialized
218    #[error("Token Mint account is not initialized")]
219    SplTokenMintNotInitialized, // 549
220
221    /// Token Mint account doesn't exist
222    #[error("Token Mint account doesn't exist")]
223    SplTokenMintDoesNotExist, // 550
224
225    /// ---- Bpf Upgradable Loader Tools Errors ----
226
227    /// Invalid ProgramData account Address
228    #[error("Invalid ProgramData account address")]
229    InvalidProgramDataAccountAddress, // 551
230
231    /// Invalid ProgramData account data
232    #[error("Invalid ProgramData account Data")]
233    InvalidProgramDataAccountData, // 552
234
235    /// Provided upgrade authority doesn't match current program upgrade
236    /// authority
237    #[error("Provided upgrade authority doesn't match current program upgrade authority")]
238    InvalidUpgradeAuthority, // 553
239
240    /// Current program upgrade authority must sign transaction
241    #[error("Current program upgrade authority must sign transaction")]
242    UpgradeAuthorityMustSign, // 554
243
244    /// Given program is not upgradable
245    #[error("Given program is not upgradable")]
246    ProgramNotUpgradable, // 555
247
248    /// Invalid token owner
249    #[error("Invalid token owner")]
250    InvalidTokenOwner, // 556
251
252    /// Current token owner must sign transaction
253    #[error("Current token owner must sign transaction")]
254    TokenOwnerMustSign, // 557
255
256    /// Given VoteThresholdType is not supported
257    #[error("Given VoteThresholdType is not supported")]
258    VoteThresholdTypeNotSupported, // 558
259
260    /// Given VoteWeightSource is not supported
261    #[error("Given VoteWeightSource is not supported")]
262    VoteWeightSourceNotSupported, // 559
263
264    /// Legacy1
265    #[error("Legacy1")]
266    Legacy1, // 560
267
268    /// Governance PDA must sign
269    #[error("Governance PDA must sign")]
270    GovernancePdaMustSign, // 561
271
272    /// Transaction already flagged with error
273    #[error("Transaction already flagged with error")]
274    TransactionAlreadyFlaggedWithError, // 562
275
276    /// Invalid Realm for Governance
277    #[error("Invalid Realm for Governance")]
278    InvalidRealmForGovernance, // 563
279
280    /// Invalid Authority for Realm
281    #[error("Invalid Authority for Realm")]
282    InvalidAuthorityForRealm, // 564
283
284    /// Realm has no authority
285    #[error("Realm has no authority")]
286    RealmHasNoAuthority, // 565
287
288    /// Realm authority must sign
289    #[error("Realm authority must sign")]
290    RealmAuthorityMustSign, // 566
291
292    /// Invalid governing token holding account
293    #[error("Invalid governing token holding account")]
294    InvalidGoverningTokenHoldingAccount, // 567
295
296    /// Realm council mint change is not supported
297    #[error("Realm council mint change is not supported")]
298    RealmCouncilMintChangeIsNotSupported, // 568
299
300    /// Invalid max voter weight absolute value
301    #[error("Invalid max voter weight absolute value")]
302    InvalidMaxVoterWeightAbsoluteValue, // 569
303
304    /// Invalid max voter weight supply fraction
305    #[error("Invalid max voter weight supply fraction")]
306    InvalidMaxVoterWeightSupplyFraction, // 570
307
308    /// Owner doesn't have enough governing tokens to create Governance
309    #[error("Owner doesn't have enough governing tokens to create Governance")]
310    NotEnoughTokensToCreateGovernance, // 571
311
312    /// Too many outstanding proposals
313    #[error("Too many outstanding proposals")]
314    TooManyOutstandingProposals, // 572
315
316    /// All proposals must be finalized to withdraw governing tokens
317    #[error("All proposals must be finalized to withdraw governing tokens")]
318    AllProposalsMustBeFinalisedToWithdrawGoverningTokens, // 573
319
320    /// Invalid VoterWeightRecord for Realm
321    #[error("Invalid VoterWeightRecord for Realm")]
322    InvalidVoterWeightRecordForRealm, // 574
323
324    /// Invalid VoterWeightRecord for GoverningTokenMint
325    #[error("Invalid VoterWeightRecord for GoverningTokenMint")]
326    InvalidVoterWeightRecordForGoverningTokenMint, // 575
327
328    /// Invalid VoterWeightRecord for TokenOwner
329    #[error("Invalid VoterWeightRecord for TokenOwner")]
330    InvalidVoterWeightRecordForTokenOwner, // 576
331
332    /// VoterWeightRecord expired
333    #[error("VoterWeightRecord expired")]
334    VoterWeightRecordExpired, // 577
335
336    /// Invalid RealmConfig for Realm
337    #[error("Invalid RealmConfig for Realm")]
338    InvalidRealmConfigForRealm, // 578
339
340    /// TokenOwnerRecord already exists
341    #[error("TokenOwnerRecord already exists")]
342    TokenOwnerRecordAlreadyExists, // 579
343
344    /// Governing token deposits not allowed
345    #[error("Governing token deposits not allowed")]
346    GoverningTokenDepositsNotAllowed, // 580
347
348    /// Invalid vote choice weight percentage
349    #[error("Invalid vote choice weight percentage")]
350    InvalidVoteChoiceWeightPercentage, // 581
351
352    /// Vote type not supported
353    #[error("Vote type not supported")]
354    VoteTypeNotSupported, // 582
355
356    /// InvalidProposalOptions
357    #[error("Invalid proposal options")]
358    InvalidProposalOptions, // 583
359
360    /// Proposal is not not executable
361    #[error("Proposal is not not executable")]
362    ProposalIsNotExecutable, // 584
363
364    /// Deny vote is not allowed
365    #[error("Deny vote is not allowed")]
366    DenyVoteIsNotAllowed, // 585
367
368    /// Cannot execute defeated option
369    #[error("Cannot execute defeated option")]
370    CannotExecuteDefeatedOption, // 586
371
372    /// VoterWeightRecord invalid action
373    #[error("VoterWeightRecord invalid action")]
374    VoterWeightRecordInvalidAction, // 587
375
376    /// VoterWeightRecord invalid action target
377    #[error("VoterWeightRecord invalid action target")]
378    VoterWeightRecordInvalidActionTarget, // 588
379
380    /// Invalid MaxVoterWeightRecord for Realm
381    #[error("Invalid MaxVoterWeightRecord for Realm")]
382    InvalidMaxVoterWeightRecordForRealm, // 589
383
384    /// Invalid MaxVoterWeightRecord for GoverningTokenMint
385    #[error("Invalid MaxVoterWeightRecord for GoverningTokenMint")]
386    InvalidMaxVoterWeightRecordForGoverningTokenMint, // 590
387
388    /// MaxVoterWeightRecord expired
389    #[error("MaxVoterWeightRecord expired")]
390    MaxVoterWeightRecordExpired, // 591
391
392    /// Not supported VoteType
393    #[error("Not supported VoteType")]
394    NotSupportedVoteType, // 592
395
396    /// RealmConfig change not allowed
397    #[error("RealmConfig change not allowed")]
398    RealmConfigChangeNotAllowed, // 593
399
400    /// GovernanceConfig change not allowed
401    #[error("GovernanceConfig change not allowed")]
402    GovernanceConfigChangeNotAllowed, // 594
403
404    /// At least one VoteThreshold is required
405    #[error("At least one VoteThreshold is required")]
406    AtLeastOneVoteThresholdRequired, // 595
407
408    /// Reserved buffer must be empty
409    #[error("Reserved buffer must be empty")]
410    ReservedBufferMustBeEmpty, // 596
411
412    /// Cannot Relinquish in Finalizing state
413    #[error("Cannot Relinquish in Finalizing state")]
414    CannotRelinquishInFinalizingState, // 597
415
416    /// Invalid RealmConfig account address
417    #[error("Invalid RealmConfig account address")]
418    InvalidRealmConfigAddress, // 598
419
420    /// Cannot deposit dormant tokens
421    #[error("Cannot deposit dormant tokens")]
422    CannotDepositDormantTokens, // 599
423
424    /// Cannot withdraw membership tokens
425    #[error("Cannot withdraw membership tokens")]
426    CannotWithdrawMembershipTokens, // 600
427
428    /// Cannot revoke GoverningTokens
429    #[error("Cannot revoke GoverningTokens")]
430    CannotRevokeGoverningTokens, // 601
431
432    /// Invalid Revoke amount
433    #[error("Invalid Revoke amount")]
434    InvalidRevokeAmount, // 602
435
436    /// Invalid GoverningToken source
437    #[error("Invalid GoverningToken source")]
438    InvalidGoverningTokenSource, // 603
439
440    /// Cannot change community TokenType to Membership
441    #[error("Cannot change community TokenType to Membership")]
442    CannotChangeCommunityTokenTypeToMembership, // 604
443
444    /// Voter weight threshold disabled
445    #[error("Voter weight threshold disabled")]
446    VoterWeightThresholdDisabled, // 605
447
448    /// Vote not allowed in cool off time
449    #[error("Vote not allowed in cool off time")]
450    VoteNotAllowedInCoolOffTime, // 606
451
452    /// Cannot refund ProposalDeposit
453    #[error("Cannot refund ProposalDeposit")]
454    CannotRefundProposalDeposit, // 607
455
456    ///Invalid Proposal for ProposalDeposit
457    #[error("Invalid Proposal for ProposalDeposit")]
458    InvalidProposalForProposalDeposit, // 608
459
460    /// Invalid deposit_exempt_proposal_count
461    #[error("Invalid deposit_exempt_proposal_count")]
462    InvalidDepositExemptProposalCount, // 609
463
464    /// GoverningTokenMint not allowed to vote
465    #[error("GoverningTokenMint not allowed to vote")]
466    GoverningTokenMintNotAllowedToVote, // 610
467
468    ///Invalid deposit Payer for ProposalDeposit
469    #[error("Invalid deposit Payer for ProposalDeposit")]
470    InvalidDepositPayerForProposalDeposit, // 611
471
472    /// Invalid State: Proposal is not in final state
473    #[error("Invalid State: Proposal is not in final state")]
474    InvalidStateNotFinal, // 612
475
476    ///Invalid state for proposal state transition to Completed
477    #[error("Invalid state for proposal state transition to Completed")]
478    InvalidStateToCompleteProposal, // 613
479
480    /// Invalid number of vote choices
481    #[error("Invalid number of vote choices")]
482    InvalidNumberOfVoteChoices, // 614
483
484    /// Ranked vote is not supported
485    #[error("Ranked vote is not supported")]
486    RankedVoteIsNotSupported, // 615
487
488    /// Choice weight must be 100%
489    #[error("Choice weight must be 100%")]
490    ChoiceWeightMustBe100Percent, // 616
491
492    /// Single choice only is allowed
493    #[error("Single choice only is allowed")]
494    SingleChoiceOnlyIsAllowed, // 617
495
496    /// At least single choice is required
497    #[error("At least single choice is required")]
498    AtLeastSingleChoiceIsRequired, // 618
499
500    /// Total vote weight must be 100%
501    #[error("Total vote weight must be 100%")]
502    TotalVoteWeightMustBe100Percent, // 619
503
504    /// Invalid multi choice proposal parameters
505    #[error("Invalid multi choice proposal parameters")]
506    InvalidMultiChoiceProposalParameters, // 620
507
508    /// Invalid Governance for RequiredSignatory
509    #[error("Invalid Governance for RequiredSignatory")]
510    InvalidGovernanceForRequiredSignatory,
511
512    /// SignatoryRecord already exists
513    #[error("Signatory Record has already been created")]
514    SignatoryRecordAlreadyExists,
515
516    /// Instruction has been removed
517    #[error("Instruction has been removed")]
518    InstructionDeprecated,
519
520    /// Proposal is missing signatories required by its governance
521    #[error("Proposal is missing required signatories")]
522    MissingRequiredSignatories,
523}
524
525impl PrintProgramError for GovernanceError {
526    fn print<E>(&self) {
527        msg!("GOVERNANCE-ERROR: {}", &self.to_string());
528    }
529}
530
531impl From<GovernanceError> for ProgramError {
532    fn from(e: GovernanceError) -> Self {
533        ProgramError::Custom(e as u32)
534    }
535}
536
537impl<T> DecodeError<T> for GovernanceError {
538    fn type_of() -> &'static str {
539        "Governance Error"
540    }
541}