@@ -238,7 +238,10 @@ func StartFunc(service, user string, handler func(Style, string) (string, error)
238
238
// transaction provides an interface to the remainder of the API.
239
239
func StartConfDir (service , user string , handler ConversationHandler , confDir string ) (* Transaction , error ) {
240
240
if ! CheckPamHasStartConfdir () {
241
- return nil , errors .New ("StartConfDir() was used, but the pam version on the system is not recent enough" )
241
+ return nil , & TransactionError {
242
+ errors .New ("StartConfDir() was used, but the pam version on the system is not recent enough" ),
243
+ SystemErr ,
244
+ }
242
245
}
243
246
244
247
return start (service , user , handler , confDir )
@@ -248,7 +251,10 @@ func start(service, user string, handler ConversationHandler, confDir string) (*
248
251
switch handler .(type ) {
249
252
case BinaryConversationHandler :
250
253
if ! CheckPamHasBinaryProtocol () {
251
- return nil , errors .New ("BinaryConversationHandler() was used, but it is not supported by this platform" )
254
+ return nil , & TransactionError {
255
+ errors .New ("BinaryConversationHandler() was used, but it is not supported by this platform" ),
256
+ SystemErr ,
257
+ }
252
258
}
253
259
}
254
260
t := & Transaction {
@@ -272,11 +278,34 @@ func start(service, user string, handler ConversationHandler, confDir string) (*
272
278
t .status = C .pam_start_confdir (s , u , t .conv , c , & t .handle )
273
279
}
274
280
if t .status != Success {
275
- return nil , t
281
+ return nil , & TransactionError { t , ReturnType ( t . status )}
276
282
}
277
283
return t , nil
278
284
}
279
285
286
+ // transactionError is a private interface that is implemented by both
287
+ // TransactionError and Transaction
288
+ type transactionError interface {
289
+ error
290
+ Status () ReturnType
291
+ }
292
+
293
+ // TransactionError extends error to provide more detailed information
294
+ type TransactionError struct {
295
+ error
296
+ status ReturnType
297
+ }
298
+
299
+ // Status exposes the ReturnType for the error
300
+ func (e * TransactionError ) Status () ReturnType {
301
+ return ReturnType (e .status )
302
+ }
303
+
304
+ // Error pretty prints the error from the status message
305
+ func (e * TransactionError ) Error () string {
306
+ return errors .Join (e .error , ReturnType (e .status )).Error ()
307
+ }
308
+
280
309
func (t * Transaction ) Error () string {
281
310
return t .Status ().Error ()
282
311
}
0 commit comments