mirror of
https://github.com/open-policy-agent/opa.git
synced 2026-08-12 19:32:48 -06:00
e03ac2f200
- Bump golangci-lint -> 2.6.2 - Fix all `deprecatedComment` "notices should be in a dedicated paragraph, separated from the rest" reports - Enable `appendCombine` and fix all "appendCombine: can combine chain of X appends into one" notices - Enable `preferFprint` and fix the few reported issues - Fix various issues reported only once or twice, like `zeroByteRepeat` Signed-off-by: Anders Eknert <anders.eknert@apple.com>
55 lines
1000 B
Go
55 lines
1000 B
Go
// Copyright 2024 The OPA Authors. All rights reserved.
|
|
// Use of this source code is governed by an Apache2
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package debug
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/open-policy-agent/opa/v1/topdown"
|
|
)
|
|
|
|
type EventType string
|
|
|
|
const (
|
|
ExceptionEventType = "exception"
|
|
StdoutEventType = "stdout"
|
|
StoppedEventType = "stopped"
|
|
TerminatedEventType = "terminated"
|
|
ThreadEventType = "thread"
|
|
)
|
|
|
|
type Event struct {
|
|
Type EventType
|
|
Thread ThreadID
|
|
Message string
|
|
stackIndex int
|
|
stackEvent *topdown.Event
|
|
}
|
|
|
|
func (d Event) String() string {
|
|
buf := new(strings.Builder)
|
|
|
|
fmt.Fprintf(buf, "%s{thread=%d", d.Type, d.Thread)
|
|
|
|
if d.Message != "" {
|
|
fmt.Fprintf(buf, ", message=%q", d.Message)
|
|
}
|
|
|
|
if d.stackEvent != nil {
|
|
fmt.Fprintf(buf, ", stackIndex=%d", d.stackIndex)
|
|
}
|
|
|
|
buf.WriteString("}")
|
|
|
|
return buf.String()
|
|
}
|
|
|
|
type EventHandler func(Event)
|
|
|
|
func newNopEventHandler() EventHandler {
|
|
return func(_ Event) {}
|
|
}
|