MCPcopy Create free account
hub / github.com/github/gh-aw / parseExperimentState

Function parseExperimentState

pkg/cli/experiments_command.go:646–656  ·  view source on GitHub ↗

parseExperimentState unmarshals raw JSON into an ExperimentState. Returns an empty state when parsing fails or the data is invalid.

(data []byte)

Source from the content-addressed store, hash-verified

644// parseExperimentState unmarshals raw JSON into an ExperimentState.
645// Returns an empty state when parsing fails or the data is invalid.
646func parseExperimentState(data []byte) *ExperimentState {
647 var state ExperimentState
648 if err := json.Unmarshal(data, &state); err != nil {
649 return emptyExperimentState()
650 }
651 // Validate: state.json must have a counts object.
652 if state.Counts == nil {
653 state.Counts = map[string]map[string]int{}
654 }
655 return &state
656}
657
658// emptyExperimentState returns a zero-value ExperimentState with an initialised Counts map.
659func emptyExperimentState() *ExperimentState {

Callers 3

readLocalExperimentStateFunction · 0.85
TestParseExperimentStateFunction · 0.85

Calls 1

emptyExperimentStateFunction · 0.85

Tested by 1

TestParseExperimentStateFunction · 0.68