@@ -3,6 +3,7 @@ package asherah
33import (
44 "context"
55 "errors"
6+ "fmt"
67 "sync/atomic"
78
89 "github.com/aws/aws-sdk-go/aws"
@@ -132,16 +133,16 @@ func NewMetastore(opts *Options) appencryption.Metastore {
132133 }
133134 db , err := newConnection (dbType , opts .ConnectionString )
134135 if err != nil {
135- log .ErrorLogf ("PANIC: Failed to connect to database: %v" , err .Error ())
136- panic (err )
136+ log .ErrorLogf ("PANIC: Failed to connect to %s database with connection string : %v" , dbType , err .Error ())
137+ panic (fmt . Errorf ( "failed to connect to %s database: %w" , dbType , err ) )
137138 }
138139
139140 // set optional replica read consistency
140141 if len (opts .ReplicaReadConsistency ) > 0 {
141142 err := setRdbmsReplicaReadConsistencyValue (opts .ReplicaReadConsistency )
142143 if err != nil {
143- log .ErrorLogf ("PANIC: Failed to set replica read consistency: %v" , err .Error ())
144- panic (err )
144+ log .ErrorLogf ("PANIC: Failed to set replica read consistency to '%s' : %v" , opts . ReplicaReadConsistency , err .Error ())
145+ panic (fmt . Errorf ( "failed to set replica read consistency to '%s': %w" , opts . ReplicaReadConsistency , err ) )
145146 }
146147 }
147148
@@ -171,8 +172,8 @@ func NewMetastore(opts *Options) appencryption.Metastore {
171172 log .ErrorLog ("*** WARNING WARNING WARNING USING MEMORY METASTORE - THIS IS FOR TEST/DEBUG ONLY ***" )
172173 return persistence .NewMemoryMetastore ()
173174 default :
174- log .ErrorLogf ("PANIC: Unknown metastore type: %v" , opts .Metastore )
175- panic ("Unknown metastore type" )
175+ log .ErrorLogf ("PANIC: Unknown metastore type: %v (valid options: rdbms, dynamodb, memory) " , opts .Metastore )
176+ panic (fmt . Errorf ( "unknown metastore type '%s' (valid options: rdbms, dynamodb, memory)" , opts . Metastore ) )
176177 }
177178}
178179
@@ -182,26 +183,26 @@ func NewKMS(opts *Options, crypto appencryption.AEAD) appencryption.KeyManagemen
182183
183184 m , err := kms .NewStatic ("thisIsAStaticMasterKeyForTesting" , aead .NewAES256GCM ())
184185 if err != nil {
185- log .ErrorLogf ("PANIC: Failed to create static master key: %v" , err .Error ())
186- panic (err )
186+ log .ErrorLogf ("PANIC: Failed to create static master key for KMS type 'static' : %v" , err .Error ())
187+ panic (fmt . Errorf ( "failed to create static master key for KMS type 'static': %w" , err ) )
187188 }
188189
189190 return m
190191 } else if opts .KMS == "test-debug-static" {
191192 // We don't warn if the user specifically asks for test-debug-static
192193 m , err := kms .NewStatic ("thisIsAStaticMasterKeyForTesting" , crypto )
193194 if err != nil {
194- log .ErrorLogf ("PANIC: Failed to create static master key: %v" , err .Error ())
195- panic (err )
195+ log .ErrorLogf ("PANIC: Failed to create static master key for KMS type 'test-debug-static' : %v" , err .Error ())
196+ panic (fmt . Errorf ( "failed to create static master key for KMS type 'test-debug-static': %w" , err ) )
196197 }
197198
198199 return m
199200 }
200201
201202 m , err := kms .NewAWS (crypto , opts .PreferredRegion , opts .RegionMap )
202203 if err != nil {
203- log .ErrorLogf ("PANIC: Failed to create AWS KMS: %v" , err .Error ())
204- panic (err )
204+ log .ErrorLogf ("PANIC: Failed to create AWS KMS with preferred region '%s' : %v" , opts . PreferredRegion , err .Error ())
205+ panic (fmt . Errorf ( "failed to create AWS KMS with preferred region '%s': %w" , opts . PreferredRegion , err ) )
205206 }
206207
207208 return m
0 commit comments