github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/pvl/debug.go (about)

     1  // Copyright 2016 Keybase, Inc. All rights reserved. Use of
     2  // this source code is governed by the included BSD license.
     3  
     4  package pvl
     5  
     6  import (
     7  	"fmt"
     8  
     9  	libkb "github.com/keybase/client/go/libkb"
    10  	keybase1 "github.com/keybase/client/go/protocol/keybase1"
    11  )
    12  
    13  type metaContext struct {
    14  	libkb.MetaContext
    15  	stubDNS *stubDNSEngine
    16  }
    17  
    18  func newMetaContext(m libkb.MetaContext, d *stubDNSEngine) metaContext {
    19  	return metaContext{m, d}
    20  }
    21  
    22  func (m metaContext) getStubDNS() *stubDNSEngine {
    23  	return m.stubDNS
    24  }
    25  
    26  func debugWithState(m metaContext, state scriptState, format string, arg ...interface{}) {
    27  	s := fmt.Sprintf(format, arg...)
    28  	m.Debug("PVL @(service:%v script:%v pc:%v) %v",
    29  		debugServiceToString(state.Service), state.WhichScript, state.PC, s)
    30  }
    31  
    32  func debugWithStateError(m metaContext, state scriptState, err libkb.ProofError) {
    33  	m.Debug("PVL @(service:%v script:%v pc:%v) Error code=%v: %v",
    34  		debugServiceToString(state.Service), state.WhichScript, state.PC, err.GetProofStatus(), err.GetDesc())
    35  }
    36  
    37  func debugWithPosition(m metaContext, service keybase1.ProofType, whichscript int, pc int, format string, arg ...interface{}) {
    38  	s := fmt.Sprintf(format, arg...)
    39  	m.Debug("PVL @(service:%v script:%v pc:%v) %v",
    40  		debugServiceToString(service), whichscript, pc, s)
    41  }
    42  
    43  func debug(m metaContext, format string, arg ...interface{}) {
    44  	s := fmt.Sprintf(format, arg...)
    45  	m.Debug("PVL %v", s)
    46  }
    47  
    48  // debugServiceToString returns the name of a service or number string if it is invalid.
    49  func debugServiceToString(service keybase1.ProofType) string {
    50  	s, err := serviceToString(service)
    51  	if err != nil {
    52  		return fmt.Sprint(service)
    53  	}
    54  	return s
    55  }