Skip to content

Commit

Permalink
clean up error messages to have consistent format
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuahannan committed Sep 25, 2024
1 parent 782f154 commit cdaf280
Show file tree
Hide file tree
Showing 27 changed files with 156 additions and 366 deletions.
6 changes: 3 additions & 3 deletions contracts/ExampleNFT.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ access(all) contract ExampleNFT: NonFungibleToken {
/// withdraw removes an NFT from the collection and moves it to the caller
access(NonFungibleToken.Withdraw) fun withdraw(withdrawID: UInt64): @{NonFungibleToken.NFT} {
let token <- self.ownedNFTs.remove(key: withdrawID)
?? panic("ExampleNFT.Collection.withdraw: Could not withdraw an NFT with the ID="
?? panic("ExampleNFT.Collection.withdraw: Could not withdraw an NFT with ID "
.concat(withdrawID.toString())
.concat(". Check the submitted ID to make sure it is one that this collection owns"))
.concat(". Check the submitted ID to make sure it is one that this collection owns."))

return <-token
}
Expand Down Expand Up @@ -223,7 +223,7 @@ access(all) contract ExampleNFT: NonFungibleToken {
}

access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
return (&self.ownedNFTs[id] as &{NonFungibleToken.NFT}?)
return &self.ownedNFTs[id]
}

/// Borrow the view resolver for the specified NFT ID
Expand Down
26 changes: 15 additions & 11 deletions contracts/MetadataViews.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,10 @@ access(all) contract MetadataViews {
view init(receiver: Capability<&{FungibleToken.Receiver}>, cut: UFix64, description: String) {
pre {
cut >= 0.0 && cut <= 1.0 :
"MetadataViews.Royalty.init: The provided royalty cut value ("
.concat(cut.toString())
.concat(") is invalid.")
.concat(" It should be within the valid range between 0 and 1. i.e [0,1]")
"MetadataViews.Royalty.init: Cannot initialize the Royalty Metadata View! "
.concat("The provided royalty cut value of ").concat(cut.toString())
.concat(" is invalid. ")
.concat("It should be within the valid range between 0 and 1. i.e [0,1]")
}
self.receiver = receiver
self.cut = cut
Expand All @@ -308,9 +308,10 @@ access(all) contract MetadataViews {
assert(
totalCut <= 1.0,
message:
"MetadataViews.Royalties.init: Sum of cutInfos multipliers ("
"MetadataViews.Royalties.init: Cannot initialize Royalties Metadata View! "
.concat(" The sum of cutInfos multipliers is ")
.concat(totalCut.toString())
.concat(") should not be greater than 1.0")
.concat(" but it should not be greater than 1.0")
)
// Assign the cutInfos
self.cutInfos = cutInfos
Expand Down Expand Up @@ -467,11 +468,12 @@ access(all) contract MetadataViews {
assert(
number <= max!,
message:
"MetadataViews.Edition.init: The provided edition number for the NFT ("
"MetadataViews.Edition.init: Cannot intialize the Edition Metadata View! "
.concat("The provided edition number of ")
.concat(number.toString())
.concat(") cannot be greater than the max edition number (")
.concat(" cannot be greater than the max edition number of ")
.concat(max!.toString())
.concat(")!")
.concat(".")
)
}
self.name = name
Expand Down Expand Up @@ -553,7 +555,8 @@ access(all) contract MetadataViews {

view init(score: UFix64?, max: UFix64?, description: String?) {
if score == nil && description == nil {
panic("MetadataViews.Rarity.init: The provided score and description are both `nil`."
panic("MetadataViews.Rarity.init: Cannot initialize the Rarity Metadata View! "
.concat("The provided score and description are both `nil`. ")
.concat(" A Rarity needs to set score, description, or both"))
}

Expand Down Expand Up @@ -668,7 +671,8 @@ access(all) contract MetadataViews {
) {
pre {
publicLinkedType.isSubtype(of: Type<&{NonFungibleToken.Collection}>()):
"MetadataViews.NFTCollectionData.init: The Public linked type <"
"MetadataViews.NFTCollectionData.init: Cannot initialize the NFTCollectionData Metadata View! "
.concat("The Public linked type <")
.concat(publicLinkedType.identifier)
.concat("> is incorrect. It must be a subtype of the NonFungibleToken.Collection interface.")
}
Expand Down
30 changes: 18 additions & 12 deletions contracts/NonFungibleToken.cdc
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,15 @@ access(all) contract interface NonFungibleToken: ViewResolver {
access(all) fun createEmptyCollection(): @{Collection} {
post {
result.getLength() == 0:
"NonFungibleToken.NFT.createEmptyCollection: The created collection has a non-zero length."
"NonFungibleToken.NFT.createEmptyCollection: Cannot create an empty collection! "
.concat("The created NonFungibleToken Collection has a non-zero length. ")
.concat(" A newly created collection must be empty!")
result.isSupportedNFTType(type: self.getType()):
"NonFungibleToken.NFT.createEmptyCollection: The created collection does not support NFTs of type="
.concat(self.getType().identifier)
.concat(" The collection must support NFTs of type=")
"NonFungibleToken.NFT.createEmptyCollection: Cannot create an empty collection! "
.concat("The created NonFungibleToken Collection does not support NFTs of type <")
.concat(self.getType().identifier)
.concat(">. The collection must support NFTs of type <")
.concat(self.getType().identifier).concat(">.")
}
}

Expand Down Expand Up @@ -163,11 +165,12 @@ access(all) contract interface NonFungibleToken: ViewResolver {
access(Withdraw) fun withdraw(withdrawID: UInt64): @{NFT} {
post {
result.id == withdrawID:
"NonFungibleToken.Provider.withdraw: The ID of the withdrawn token ("
"NonFungibleToken.Provider.withdraw: Cannot withdraw NFT! "
.concat("The ID of the withdrawn NFT (")
.concat(result.id.toString())
.concat(") must be the same as the requested ID (")
.concat(withdrawID.toString())
.concat(")")
.concat(").")
emit Withdrawn(type: result.getType().identifier, id: result.id, uuid: result.uuid, from: self.owner?.address, providerUUID: self.uuid)
}
}
Expand Down Expand Up @@ -246,7 +249,7 @@ access(all) contract interface NonFungibleToken: ViewResolver {
access(all) view fun borrowNFT(_ id: UInt64): &{NonFungibleToken.NFT}? {
post {
(result == nil) || (result?.id == id):
"NonFungibleToken.Collection.borrowNFT: Cannot borrow NFT reference: "
"NonFungibleToken.Collection.borrowNFT: Cannot borrow NFT reference! "
.concat("The ID of the returned reference (")
.concat(result!.id.toString())
.concat(") does not match the ID that was specified (")
Expand All @@ -261,13 +264,15 @@ access(all) contract interface NonFungibleToken: ViewResolver {
access(all) fun createEmptyCollection(): @{Collection} {
post {
result.getType() == self.getType():
"NonFungibleToken.Collection.createEmptyCollection: The created collection type <"
"NonFungibleToken.Collection.createEmptyCollection: Cannot create empty collection! "
.concat("The created collection type <")
.concat(result.getType().identifier)
.concat("> does not have the same type as the collection that was used to create it <")
.concat(self.getType().identifier)
.concat(">")
.concat(">.")
result.getLength() == 0:
"NonFungibleToken.Collection.createEmptyCollection: The created collection has a non-zero length."
"NonFungibleToken.Collection.createEmptyCollection: Cannot create empty collection! "
.concat("The created collection has a non-zero length.")
.concat(" A newly created collection must be empty!")
}
}
Expand All @@ -280,8 +285,9 @@ access(all) contract interface NonFungibleToken: ViewResolver {
access(all) fun createEmptyCollection(nftType: Type): @{NonFungibleToken.Collection} {
post {
result.getIDs().length == 0:
"NonFungibleToken.createEmptyCollection: The created collection has a non-zero length."
.concat(" A newly created collection must be empty!")
"NonFungibleToken.createEmptyCollection: Cannot create empty collection! "
.concat("The created collection has a non-zero length. ")
.concat("A newly created collection must be empty!")
}
}
}
229 changes: 0 additions & 229 deletions contracts/utility/FungibleToken.cdc

This file was deleted.

Loading

0 comments on commit cdaf280

Please sign in to comment.