From a166dfb9154ef8b7d5356738b5a4f448c8d5a749 Mon Sep 17 00:00:00 2001 From: Dimasik Kolezhniuk Date: Wed, 6 Dec 2023 18:13:45 +0100 Subject: [PATCH] Fix error messages --- chain.go | 2 +- did.go | 10 +++++----- did_test.go | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/chain.go b/chain.go index 7b54981..4a4e61b 100644 --- a/chain.go +++ b/chain.go @@ -51,7 +51,7 @@ func RegisterChainID(blockchain Blockchain, network NetworkID, chainID int) erro k := fmt.Sprintf("%s:%s", blockchain, network) existingChainID, ok := chainIDs[k] if ok && existingChainID != ChainID(chainID) { - return fmt.Errorf("chainID %s:%s already registered", blockchain, network) + return fmt.Errorf("chainID '%s:%s' already registered with value %d", blockchain, network, existingChainID) } chainIDs[k] = ChainID(chainID) diff --git a/did.go b/did.go index a09875b..adf3008 100644 --- a/did.go +++ b/did.go @@ -152,7 +152,7 @@ var DIDMethodByte = map[DIDMethod]byte{ func RegisterDIDMethod(m DIDMethod, b byte) error { existingByte, ok := DIDMethodByte[m] if ok && existingByte != b { - return fmt.Errorf("DID method %s already registered", m) + return fmt.Errorf("DID method '%s' already registered with byte %b", m, existingByte) } max := DIDMethodByte[DIDMethodOther] @@ -276,10 +276,10 @@ func RegisterDIDMethodNetwork(params DIDMethodNetworkParams, opts ...Registratio return err } } - - if existed, ok := DIDMethodNetwork[m][flg]; ok && existed != params.NetworkFlag { - return fmt.Errorf("DID method network '%s' with blockchain '%s' and network '%s' already registered", - m, b, n) + existedFlag, ok := DIDMethodNetwork[m][flg] + if ok && existedFlag != params.NetworkFlag { + return fmt.Errorf("DID method network '%s' with blockchain '%s' and network '%s' already registered with another flag '%b'", + m, b, n, existedFlag) } DIDMethodNetwork[m][flg] = params.NetworkFlag diff --git a/did_test.go b/did_test.go index 221a3c6..51e26b5 100644 --- a/did_test.go +++ b/did_test.go @@ -506,7 +506,7 @@ func TestCustomDIDRegistration_Negative(t *testing.T) { NetworkFlag: 0b0001_0001, }, opts: []RegistrationOptions{WithChainID(1)}, - err: "chainID polygon:mumbai already registered", + err: "chainID 'polygon:mumbai' already registered with value 80001", }, { Description: "try to overwrite existing DID method byte", @@ -517,7 +517,7 @@ func TestCustomDIDRegistration_Negative(t *testing.T) { NetworkFlag: 0b00100000 | 0b00000001, }, opts: []RegistrationOptions{WithChainID(1), WithDIDMethodByte(0b00000010)}, - err: "DID method iden3 already registered", + err: "DID method 'iden3' already registered with byte 1", }, { Description: "try to write max did method byte", @@ -539,7 +539,7 @@ func TestCustomDIDRegistration_Negative(t *testing.T) { NetworkFlag: 0b00100000 | 0b00000011, }, opts: nil, - err: "DID method network 'iden3' with blockchain 'eth' and network 'main' already registered", + err: "DID method network 'iden3' with blockchain 'eth' and network 'main' already registered with another flag '100001'", }, }