logs and user messages: use "parse" and "serialize" instead of marshal/unmarshal (#3240)

This commit is contained in:
mmetc 2024-09-17 13:19:14 +02:00 committed by GitHub
parent 1591a0c46e
commit ce085dc4cd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
56 changed files with 87 additions and 87 deletions

View file

@ -521,14 +521,14 @@ func (cli *cliAlerts) inspect(details bool, alertIDs ...string) error {
case "json":
data, err := json.MarshalIndent(alert, "", " ")
if err != nil {
return fmt.Errorf("unable to marshal alert with id %s: %w", alertID, err)
return fmt.Errorf("unable to serialize alert with id %s: %w", alertID, err)
}
fmt.Printf("%s\n", string(data))
case "raw":
data, err := yaml.Marshal(alert)
if err != nil {
return fmt.Errorf("unable to marshal alert with id %s: %w", alertID, err)
return fmt.Errorf("unable to serialize alert with id %s: %w", alertID, err)
}
fmt.Println(string(data))

View file

@ -181,7 +181,7 @@ func (cli *cliBouncers) List(out io.Writer, db *database.Client) error {
enc.SetIndent("", " ")
if err := enc.Encode(info); err != nil {
return errors.New("failed to marshal")
return errors.New("failed to serialize")
}
return nil
@ -234,7 +234,7 @@ func (cli *cliBouncers) add(bouncerName string, key string) error {
case "json":
j, err := json.Marshal(key)
if err != nil {
return errors.New("unable to marshal api key")
return errors.New("unable to serialize api key")
}
fmt.Print(string(j))
@ -458,7 +458,7 @@ func (cli *cliBouncers) inspect(bouncer *ent.Bouncer) error {
enc.SetIndent("", " ")
if err := enc.Encode(newBouncerInfo(bouncer)); err != nil {
return errors.New("failed to marshal")
return errors.New("failed to serialize")
}
return nil

View file

@ -104,7 +104,7 @@ func (cli *cliCapi) register(ctx context.Context, capiUserPrefix string, outputF
apiConfigDump, err := yaml.Marshal(apiCfg)
if err != nil {
return fmt.Errorf("unable to marshal api credentials: %w", err)
return fmt.Errorf("unable to serialize api credentials: %w", err)
}
if dumpFile != "" {

View file

@ -280,7 +280,7 @@ func (cli *cliConsole) newStatusCmd() *cobra.Command {
}
data, err := json.MarshalIndent(out, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal configuration: %w", err)
return fmt.Errorf("failed to serialize configuration: %w", err)
}
fmt.Println(string(data))
case "raw":
@ -318,7 +318,7 @@ func (cli *cliConsole) dumpConfig() error {
out, err := yaml.Marshal(serverCfg.ConsoleConfig)
if err != nil {
return fmt.Errorf("while marshaling ConsoleConfig (for %s): %w", serverCfg.ConsoleConfigPath, err)
return fmt.Errorf("while serializing ConsoleConfig (for %s): %w", serverCfg.ConsoleConfigPath, err)
}
if serverCfg.ConsoleConfigPath == "" {
@ -361,7 +361,7 @@ func (cli *cliConsole) setConsoleOpts(args []string, wanted bool) error {
if changed {
fileContent, err := yaml.Marshal(cfg.API.Server.OnlineClient.Credentials)
if err != nil {
return fmt.Errorf("cannot marshal credentials: %w", err)
return fmt.Errorf("cannot serialize credentials: %w", err)
}
log.Infof("Updating credentials file: %s", cfg.API.Server.OnlineClient.CredentialsFilePath)

View file

@ -106,7 +106,7 @@ func ListItems(out io.Writer, wantColor string, itemTypes []string, items map[st
x, err := json.MarshalIndent(hubStatus, "", " ")
if err != nil {
return fmt.Errorf("failed to unmarshal: %w", err)
return fmt.Errorf("failed to parse: %w", err)
}
out.Write(x)
@ -158,7 +158,7 @@ func InspectItem(item *cwhub.Item, wantMetrics bool, output string, prometheusUR
case "json":
b, err := json.MarshalIndent(*item, "", " ")
if err != nil {
return fmt.Errorf("unable to marshal item: %w", err)
return fmt.Errorf("unable to serialize item: %w", err)
}
fmt.Print(string(b))

View file

@ -134,7 +134,7 @@ cscli hubtest create my-scenario-test --parsers crowdsecurity/nginx --scenarios
}
data, err := yaml.Marshal(configFileData)
if err != nil {
return fmt.Errorf("marshal: %w", err)
return fmt.Errorf("serialize: %w", err)
}
_, err = fd.Write(data)
if err != nil {

View file

@ -62,7 +62,7 @@ func NewAppsecRule(cfg configGetter) *cliItem {
}
if err := yaml.Unmarshal(yamlContent, &appsecRule); err != nil {
return fmt.Errorf("unable to unmarshal yaml file %s: %w", item.State.LocalPath, err)
return fmt.Errorf("unable to parse yaml file %s: %w", item.State.LocalPath, err)
}
for _, ruleType := range appsec_rule.SupportedTypes() {

View file

@ -147,7 +147,7 @@ func (cli *cliLapi) register(ctx context.Context, apiURL string, outputFile stri
apiConfigDump, err := yaml.Marshal(apiCfg)
if err != nil {
return fmt.Errorf("unable to marshal api credentials: %w", err)
return fmt.Errorf("unable to serialize api credentials: %w", err)
}
if dumpFile != "" {

View file

@ -232,7 +232,7 @@ func (cli *cliMachines) List(out io.Writer, db *database.Client) error {
enc.SetIndent("", " ")
if err := enc.Encode(info); err != nil {
return errors.New("failed to marshal")
return errors.New("failed to serialize")
}
return nil
@ -378,7 +378,7 @@ func (cli *cliMachines) add(args []string, machinePassword string, dumpFile stri
apiConfigDump, err := yaml.Marshal(apiCfg)
if err != nil {
return fmt.Errorf("unable to marshal api credentials: %w", err)
return fmt.Errorf("unable to serialize api credentials: %w", err)
}
if dumpFile != "" && dumpFile != "-" {
@ -626,7 +626,7 @@ func (cli *cliMachines) inspect(machine *ent.Machine) error {
enc.SetIndent("", " ")
if err := enc.Encode(newMachineInfo(machine)); err != nil {
return errors.New("failed to marshal")
return errors.New("failed to serialize")
}
return nil
@ -648,7 +648,7 @@ func (cli *cliMachines) inspectHub(machine *ent.Machine) error {
enc.SetIndent("", " ")
if err := enc.Encode(machine.Hubstate); err != nil {
return errors.New("failed to marshal")
return errors.New("failed to serialize")
}
return nil

View file

@ -68,7 +68,7 @@ func (cli *cliMetrics) list() error {
case "json":
x, err := json.MarshalIndent(allMetrics, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal metric types: %w", err)
return fmt.Errorf("failed to serialize metric types: %w", err)
}
fmt.Println(string(x))

View file

@ -260,7 +260,7 @@ func (ms metricStore) Format(out io.Writer, wantColor string, sections []string,
case "json":
x, err := json.MarshalIndent(want, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal metrics: %w", err)
return fmt.Errorf("failed to serialize metrics: %w", err)
}
out.Write(x)
default:

View file

@ -172,7 +172,7 @@ func (cli *cliNotifications) newListCmd() *cobra.Command {
} else if cfg.Cscli.Output == "json" {
x, err := json.MarshalIndent(ncfgs, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal notification configuration: %w", err)
return fmt.Errorf("failed to serialize notification configuration: %w", err)
}
fmt.Printf("%s", string(x))
} else if cfg.Cscli.Output == "raw" {
@ -231,7 +231,7 @@ func (cli *cliNotifications) newInspectCmd() *cobra.Command {
} else if cfg.Cscli.Output == "json" {
x, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal notification configuration: %w", err)
return fmt.Errorf("failed to serialize notification configuration: %w", err)
}
fmt.Printf("%s", string(x))
}
@ -331,7 +331,7 @@ func (cli cliNotifications) newTestCmd() *cobra.Command {
CreatedAt: time.Now().UTC().Format(time.RFC3339),
}
if err := yaml.Unmarshal([]byte(alertOverride), alert); err != nil {
return fmt.Errorf("failed to unmarshal alert override: %w", err)
return fmt.Errorf("failed to parse alert override: %w", err)
}
pluginBroker.PluginChannel <- csplugin.ProfileAlert{
@ -387,7 +387,7 @@ cscli notifications reinject <alert_id> -a '{"remediation": true,"scenario":"not
if alertOverride != "" {
if err := json.Unmarshal([]byte(alertOverride), alert); err != nil {
return fmt.Errorf("can't unmarshal data in the alert flag: %w", err)
return fmt.Errorf("can't parse data in the alert flag: %w", err)
}
}

View file

@ -227,7 +227,7 @@ func setupAsString(cs setup.Setup, outYaml bool) (string, error) {
)
wrap := func(err error) error {
return fmt.Errorf("while marshaling setup: %w", err)
return fmt.Errorf("while serializing setup: %w", err)
}
indentLevel := 2

View file

@ -220,7 +220,7 @@ func (cli *cliSimulation) dumpSimulationFile() error {
newConfigSim, err := yaml.Marshal(cfg.Cscli.SimulationConfig)
if err != nil {
return fmt.Errorf("unable to marshal simulation configuration: %w", err)
return fmt.Errorf("unable to serialize simulation configuration: %w", err)
}
err = os.WriteFile(cfg.ConfigPaths.SimulationFilePath, newConfigSim, 0o644)
@ -242,7 +242,7 @@ func (cli *cliSimulation) disableGlobalSimulation() error {
newConfigSim, err := yaml.Marshal(cfg.Cscli.SimulationConfig)
if err != nil {
return fmt.Errorf("unable to marshal new simulation configuration: %w", err)
return fmt.Errorf("unable to serialize new simulation configuration: %w", err)
}
err = os.WriteFile(cfg.ConfigPaths.SimulationFilePath, newConfigSim, 0o644)

View file

@ -74,7 +74,7 @@ func (cli *cliConfig) backupHub(dirPath string) error {
upstreamParsersContent, err := json.MarshalIndent(upstreamParsers, "", " ")
if err != nil {
return fmt.Errorf("failed marshaling upstream parsers: %w", err)
return fmt.Errorf("failed to serialize upstream parsers: %w", err)
}
err = os.WriteFile(upstreamParsersFname, upstreamParsersContent, 0o644)

View file

@ -40,7 +40,7 @@ func (cli *cliConfig) restoreHub(ctx context.Context, dirPath string) error {
err = json.Unmarshal(file, &upstreamList)
if err != nil {
return fmt.Errorf("error unmarshaling %s: %w", upstreamListFN, err)
return fmt.Errorf("error parsing %s: %w", upstreamListFN, err)
}
for _, toinstall := range upstreamList {

View file

@ -50,7 +50,7 @@ func (cli *cliConfig) showKey(key string) error {
case "json":
data, err := json.MarshalIndent(output, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal configuration: %w", err)
return fmt.Errorf("failed to serialize configuration: %w", err)
}
fmt.Println(string(data))
@ -212,14 +212,14 @@ func (cli *cliConfig) show() error {
case "json":
data, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return fmt.Errorf("failed to marshal configuration: %w", err)
return fmt.Errorf("failed to serialize configuration: %w", err)
}
fmt.Println(string(data))
case "raw":
data, err := yaml.Marshal(cfg)
if err != nil {
return fmt.Errorf("failed to marshal configuration: %w", err)
return fmt.Errorf("failed to serialize configuration: %w", err)
}
fmt.Println(string(data))

View file

@ -32,7 +32,7 @@ func runPour(input chan types.Event, holders []leaky.BucketFactory, buckets *lea
if parsed.MarshaledTime != "" {
z := &time.Time{}
if err := z.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil {
log.Warningf("Failed to unmarshal time from event '%s' : %s", parsed.MarshaledTime, err)
log.Warningf("Failed to parse time from event '%s' : %s", parsed.MarshaledTime, err)
} else {
log.Warning("Starting buckets garbage collection ...")
@ -61,7 +61,7 @@ func runPour(input chan types.Event, holders []leaky.BucketFactory, buckets *lea
if len(parsed.MarshaledTime) != 0 {
if err := lastProcessedItem.UnmarshalText([]byte(parsed.MarshaledTime)); err != nil {
log.Warningf("failed to unmarshal time from event : %s", err)
log.Warningf("failed to parse time from event : %s", err)
}
}
}

View file

@ -210,7 +210,7 @@ func (s *FilePlugin) Configure(ctx context.Context, config *protobufs.Config) (*
d := PluginConfig{}
err := yaml.Unmarshal(config.Config, &d)
if err != nil {
logger.Error("Failed to unmarshal config", "error", err)
logger.Error("Failed to parse config", "error", err)
return &protobufs.Empty{}, err
}
FileWriteMutex = &sync.Mutex{}

View file

@ -129,7 +129,7 @@ func DataSourceConfigure(commonConfig configuration.DataSourceCommonCfg, metrics
// once to DataSourceCommonCfg, and then later to the dedicated type of the datasource
yamlConfig, err := yaml.Marshal(commonConfig)
if err != nil {
return nil, fmt.Errorf("unable to marshal back interface: %w", err)
return nil, fmt.Errorf("unable to serialize back interface: %w", err)
}
dataSrc, err := GetDataSourceIface(commonConfig.Source)

View file

@ -393,7 +393,7 @@ func (w *AppsecSource) appsecHandler(rw http.ResponseWriter, r *http.Request) {
rw.WriteHeader(statusCode)
body, err := json.Marshal(appsecResponse)
if err != nil {
logger.Errorf("unable to marshal response: %s", err)
logger.Errorf("unable to serialize response: %s", err)
rw.WriteHeader(http.StatusInternalServerError)
} else {
rw.Write(body)

View file

@ -82,7 +82,7 @@ func (k *KafkaSource) UnmarshalConfig(yamlConfig []byte) error {
k.Config.Mode = configuration.TAIL_MODE
}
k.logger.Debugf("successfully unmarshaled kafka configuration : %+v", k.Config)
k.logger.Debugf("successfully parsed kafka configuration : %+v", k.Config)
return err
}

View file

@ -196,7 +196,7 @@ func (ka *KubernetesAuditSource) webhookHandler(w http.ResponseWriter, r *http.R
}
bytesEvent, err := json.Marshal(auditEvent)
if err != nil {
ka.logger.Errorf("Error marshaling audit event: %s", err)
ka.logger.Errorf("Error serializing audit event: %s", err)
continue
}
ka.logger.Tracef("Got audit event: %s", string(bytesEvent))

View file

@ -149,7 +149,7 @@ func (w *WinEventLogSource) buildXpathQuery() (string, error) {
queryList := QueryList{Select: Select{Path: w.config.EventChannel, Query: query}}
xpathQuery, err := xml.Marshal(queryList)
if err != nil {
w.logger.Errorf("Marshal failed: %v", err)
w.logger.Errorf("Serialize failed: %v", err)
return "", err
}
w.logger.Debugf("xpathQuery: %s", xpathQuery)

View file

@ -133,7 +133,7 @@ func LoadConsoleContext(c *csconfig.Config, hub *cwhub.Hub) error {
feedback, err := json.Marshal(c.Crowdsec.ContextToSend)
if err != nil {
return fmt.Errorf("marshaling console context: %s", err)
return fmt.Errorf("serializing console context: %s", err)
}
log.Debugf("console context to send: %s", feedback)

View file

@ -70,7 +70,7 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) {
err := json.Unmarshal([]byte(dbMetric.Payload), dbPayload)
if err != nil {
log.Errorf("unable to unmarshal bouncer metric (%s)", err)
log.Errorf("unable to parse bouncer metric (%s)", err)
continue
}
@ -132,7 +132,7 @@ func (a *apic) GetUsageMetrics() (*models.AllMetrics, []int, error) {
err := json.Unmarshal([]byte(dbMetric.Payload), dbPayload)
if err != nil {
log.Errorf("unable to unmarshal log processor metric (%s)", err)
log.Errorf("unable to parse log processor metric (%s)", err)
continue
}

View file

@ -63,7 +63,7 @@ func FormatOneAlert(alert *ent.Alert) *models.Alert {
var Metas models.Meta
if err := json.Unmarshal([]byte(eventItem.Serialized), &Metas); err != nil {
log.Errorf("unable to unmarshall events meta '%s' : %s", eventItem.Serialized, err)
log.Errorf("unable to parse events meta '%s' : %s", eventItem.Serialized, err)
}
outputAlert.Events = append(outputAlert.Events, &models.Event{

View file

@ -183,7 +183,7 @@ func (c *Controller) UsageMetrics(gctx *gin.Context) {
jsonPayload, err := json.Marshal(payload)
if err != nil {
logger.Errorf("Failed to marshal usage metrics: %s", err)
logger.Errorf("Failed to serialize usage metrics: %s", err)
c.HandleDBErrors(gctx, err)
return

View file

@ -245,7 +245,7 @@ func (p *Papi) Pull() error {
if lastTimestampStr == nil {
binTime, err := lastTimestamp.MarshalText()
if err != nil {
return fmt.Errorf("failed to marshal last timestamp: %w", err)
return fmt.Errorf("failed to serialize last timestamp: %w", err)
}
if err := p.DBClient.SetConfigItem(PapiPullKey, string(binTime)); err != nil {
@ -255,7 +255,7 @@ func (p *Papi) Pull() error {
}
} else {
if err := lastTimestamp.UnmarshalText([]byte(*lastTimestampStr)); err != nil {
return fmt.Errorf("failed to unmarshal last timestamp: %w", err)
return fmt.Errorf("failed to parse last timestamp: %w", err)
}
}
@ -268,7 +268,7 @@ func (p *Papi) Pull() error {
binTime, err := newTime.MarshalText()
if err != nil {
return fmt.Errorf("failed to marshal last timestamp: %w", err)
return fmt.Errorf("failed to serialize last timestamp: %w", err)
}
err = p.handleEvent(event, false)

View file

@ -28,7 +28,7 @@ func LoadAppsecRules(hubInstance *cwhub.Hub) error {
err = yaml.UnmarshalStrict(content, &rule)
if err != nil {
log.Warnf("unable to unmarshal file %s : %s", hubAppsecRuleItem.State.LocalPath, err)
log.Warnf("unable to parse file %s : %s", hubAppsecRuleItem.State.LocalPath, err)
continue
}

View file

@ -99,7 +99,7 @@ func (o *OnlineApiClientCfg) Load() error {
err = dec.Decode(o.Credentials)
if err != nil {
if !errors.Is(err, io.EOF) {
return fmt.Errorf("failed unmarshaling api server credentials configuration file '%s': %w", o.CredentialsFilePath, err)
return fmt.Errorf("failed to parse api server credentials configuration file '%s': %w", o.CredentialsFilePath, err)
}
}
@ -134,7 +134,7 @@ func (l *LocalApiClientCfg) Load() error {
err = dec.Decode(&l.Credentials)
if err != nil {
if !errors.Is(err, io.EOF) {
return fmt.Errorf("failed unmarshaling api client credential configuration file '%s': %w", l.CredentialsFilePath, err)
return fmt.Errorf("failed to parse api client credential configuration file '%s': %w", l.CredentialsFilePath, err)
}
}

View file

@ -101,7 +101,7 @@ func TestLoadOnlineApiClientCfg(t *testing.T) {
CredentialsFilePath: "./testdata/bad_lapi-secrets.yaml",
},
expected: &ApiCredentialsCfg{},
expectedErr: "failed unmarshaling api server credentials",
expectedErr: "failed to parse api server credentials",
},
{
name: "missing field configuration",

View file

@ -42,5 +42,5 @@ func TestNewCrowdSecConfig(t *testing.T) {
func TestDefaultConfig(t *testing.T) {
x := NewDefaultConfig()
_, err := yaml.Marshal(x)
require.NoError(t, err, "failed marshaling config: %s", err)
require.NoError(t, err, "failed to serialize config: %s", err)
}

View file

@ -95,7 +95,7 @@ func (c *LocalApiServerCfg) LoadConsoleConfig() error {
err = yaml.Unmarshal(yamlFile, c.ConsoleConfig)
if err != nil {
return fmt.Errorf("unmarshaling console config file '%s': %w", c.ConsoleConfigPath, err)
return fmt.Errorf("parsing console config file '%s': %w", c.ConsoleConfigPath, err)
}
if c.ConsoleConfig.ShareCustomScenarios == nil {

View file

@ -143,7 +143,7 @@ func (c *CrowdsecServiceCfg) DumpContextConfigFile() error {
// XXX: MakeDirs
out, err := yaml.Marshal(c.ContextToSend)
if err != nil {
return fmt.Errorf("while marshaling ConsoleConfig (for %s): %w", c.ConsoleContextPath, err)
return fmt.Errorf("while serializing ConsoleConfig (for %s): %w", c.ConsoleContextPath, err)
}
if err = os.MkdirAll(filepath.Dir(c.ConsoleContextPath), 0700); err != nil {

View file

@ -52,7 +52,7 @@ func (c *Config) LoadSimulation() error {
if err := dec.Decode(&simCfg); err != nil {
if !errors.Is(err, io.EOF) {
return fmt.Errorf("while unmarshaling simulation file '%s': %w", c.ConfigPaths.SimulationFilePath, err)
return fmt.Errorf("while parsing simulation file '%s': %w", c.ConfigPaths.SimulationFilePath, err)
}
}

View file

@ -60,7 +60,7 @@ func TestSimulationLoading(t *testing.T) {
},
Crowdsec: &CrowdsecServiceCfg{},
},
expectedErr: "while unmarshaling simulation file './testdata/config.yaml': yaml: unmarshal errors",
expectedErr: "while parsing simulation file './testdata/config.yaml': yaml: unmarshal errors",
},
{
name: "basic bad file content",
@ -71,7 +71,7 @@ func TestSimulationLoading(t *testing.T) {
},
Crowdsec: &CrowdsecServiceCfg{},
},
expectedErr: "while unmarshaling simulation file './testdata/config.yaml': yaml: unmarshal errors",
expectedErr: "while parsing simulation file './testdata/config.yaml': yaml: unmarshal errors",
},
}

View file

@ -38,7 +38,7 @@ func (s *PluginSuite) readconfig() PluginConfig {
require.NoError(t, err, "unable to read config file %s", s.pluginConfig)
err = yaml.Unmarshal(orig, &config)
require.NoError(t, err, "unable to unmarshal config file")
require.NoError(t, err, "unable to parse config file")
return config
}
@ -46,7 +46,7 @@ func (s *PluginSuite) readconfig() PluginConfig {
func (s *PluginSuite) writeconfig(config PluginConfig) {
t := s.T()
data, err := yaml.Marshal(&config)
require.NoError(t, err, "unable to marshal config file")
require.NoError(t, err, "unable to serialize config file")
err = os.WriteFile(s.pluginConfig, data, 0o644)
require.NoError(t, err, "unable to write config file %s", s.pluginConfig)

View file

@ -79,7 +79,7 @@ func (h *Hub) parseIndex() error {
}
if err := json.Unmarshal(bidx, &h.items); err != nil {
return fmt.Errorf("failed to unmarshal index: %w", err)
return fmt.Errorf("failed to parse index: %w", err)
}
h.logger.Debugf("%d item types in hub index", len(ItemTypes))

View file

@ -210,7 +210,7 @@ func newLocalItem(h *Hub, path string, info *itemFileInfo) (*Item, error) {
err = yaml.Unmarshal(itemContent, &itemName)
if err != nil {
return nil, fmt.Errorf("failed to unmarshal %s: %w", path, err)
return nil, fmt.Errorf("failed to parse %s: %w", path, err)
}
if itemName.Name != "" {

View file

@ -202,7 +202,7 @@ func (m *Machine) assignValues(columns []string, values []any) error {
return fmt.Errorf("unexpected type %T for field hubstate", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &m.Hubstate); err != nil {
return fmt.Errorf("unmarshal field hubstate: %w", err)
return fmt.Errorf("parsing field hubstate: %w", err)
}
}
case machine.FieldDatasources:
@ -210,7 +210,7 @@ func (m *Machine) assignValues(columns []string, values []any) error {
return fmt.Errorf("unexpected type %T for field datasources", values[i])
} else if value != nil && len(*value) > 0 {
if err := json.Unmarshal(*value, &m.Datasources); err != nil {
return fmt.Errorf("unmarshal field datasources: %w", err)
return fmt.Errorf("parsing field datasources: %w", err)
}
}
default:

View file

@ -13,8 +13,8 @@ var (
ItemNotFound = errors.New("object not found")
ParseTimeFail = errors.New("unable to parse time")
ParseDurationFail = errors.New("unable to parse duration")
MarshalFail = errors.New("unable to marshal")
UnmarshalFail = errors.New("unable to unmarshal")
MarshalFail = errors.New("unable to serialize")
UnmarshalFail = errors.New("unable to parse")
BulkError = errors.New("unable to insert bulk")
ParseType = errors.New("unable to parse type")
InvalidIPOrRange = errors.New("invalid ip address / range")

View file

@ -57,7 +57,7 @@ func (h *HubTest) GetAppsecCoverage() ([]Coverage, error) {
err = yaml.Unmarshal(yamlFile, configFileData)
if err != nil {
return nil, fmt.Errorf("unmarshal: %v", err)
return nil, fmt.Errorf("parsing: %v", err)
}
for _, appsecRulesFile := range configFileData.AppsecRules {
@ -70,7 +70,7 @@ func (h *HubTest) GetAppsecCoverage() ([]Coverage, error) {
err = yaml.Unmarshal(yamlFile, appsecRuleData)
if err != nil {
return nil, fmt.Errorf("unmarshal: %v", err)
return nil, fmt.Errorf("parsing: %v", err)
}
appsecRuleName := appsecRuleData.Name

View file

@ -111,7 +111,7 @@ func NewTest(name string, hubTest *HubTest) (*HubTestItem, error) {
err = yaml.Unmarshal(yamlFile, configFileData)
if err != nil {
return nil, fmt.Errorf("unmarshal: %w", err)
return nil, fmt.Errorf("parsing: %w", err)
}
parserAssertFilePath := filepath.Join(testPath, ParserAssertFileName)
@ -201,7 +201,7 @@ func (t *HubTestItem) InstallHub() error {
b, err := yaml.Marshal(n)
if err != nil {
return fmt.Errorf("unable to marshal overrides: %w", err)
return fmt.Errorf("unable to serialize overrides: %w", err)
}
tgtFilename := fmt.Sprintf("%s/parsers/s00-raw/00_overrides.yaml", t.RuntimePath)

View file

@ -136,7 +136,7 @@ func testOneBucket(t *testing.T, hub *cwhub.Hub, dir string, tomb *tomb.Tomb) er
}
if err := yaml.UnmarshalStrict(out.Bytes(), &stages); err != nil {
t.Fatalf("failed unmarshaling %s : %s", stagecfg, err)
t.Fatalf("failed to parse %s : %s", stagecfg, err)
}
files := []string{}
@ -201,7 +201,7 @@ func testFile(t *testing.T, file string, bs string, holders []BucketFactory, res
var ts time.Time
if err := ts.UnmarshalText([]byte(in.MarshaledTime)); err != nil {
t.Fatalf("Failed to unmarshal time from input event : %s", err)
t.Fatalf("Failed to parse time from input event : %s", err)
}
if latest_ts.IsZero() {

View file

@ -493,7 +493,7 @@ func LoadBucketsState(file string, buckets *Buckets, bucketFactories []BucketFac
}
if err := json.Unmarshal(body, &state); err != nil {
return fmt.Errorf("can't unmarshal state file %s: %w", file, err)
return fmt.Errorf("can't parse state file %s: %w", file, err)
}
for k, v := range state {

View file

@ -132,7 +132,7 @@ func DumpBucketsStateAt(deadline time.Time, outputdir string, buckets *Buckets)
})
bbuckets, err := json.MarshalIndent(serialized, "", " ")
if err != nil {
return "", fmt.Errorf("failed to unmarshal buckets: %s", err)
return "", fmt.Errorf("failed to parse buckets: %s", err)
}
size, err := tmpFd.Write(bbuckets)
if err != nil {
@ -203,7 +203,7 @@ func PourItemToBucket(bucket *Leaky, holder BucketFactory, buckets *Buckets, par
var d time.Time
err = d.UnmarshalText([]byte(parsed.MarshaledTime))
if err != nil {
holder.logger.Warningf("Failed unmarshaling event time (%s) : %v", parsed.MarshaledTime, err)
holder.logger.Warningf("Failed to parse event time (%s) : %v", parsed.MarshaledTime, err)
}
if d.After(lastTs.Add(bucket.Duration)) {
bucket.logger.Tracef("bucket is expired (curr event: %s, bucket deadline: %s), kill", d, lastTs.Add(bucket.Duration))

View file

@ -231,7 +231,7 @@ func EventsFromQueue(queue *types.Queue) []*models.Event {
raw, err := evt.Time.MarshalText()
if err != nil {
log.Warningf("while marshaling time '%s' : %s", evt.Time.String(), err)
log.Warningf("while serializing time '%s' : %s", evt.Time.String(), err)
} else {
*ovflwEvent.Timestamp = string(raw)
}
@ -286,12 +286,12 @@ func NewAlert(leaky *Leaky, queue *types.Queue) (types.RuntimeAlert, error) {
*/
start_at, err := leaky.First_ts.MarshalText()
if err != nil {
log.Warningf("failed to marshal start ts %s : %s", leaky.First_ts.String(), err)
log.Warningf("failed to serialize start ts %s : %s", leaky.First_ts.String(), err)
}
stop_at, err := leaky.Ovflw_ts.MarshalText()
if err != nil {
log.Warningf("failed to marshal ovflw ts %s : %s", leaky.First_ts.String(), err)
log.Warningf("failed to serialize ovflw ts %s : %s", leaky.First_ts.String(), err)
}
capacity := int32(leaky.Capacity)

View file

@ -24,7 +24,7 @@ func TimeMachinePour(l *Leaky, msg types.Event) {
err = d.UnmarshalText([]byte(msg.MarshaledTime))
if err != nil {
log.Warningf("Failed unmarshaling event time (%s) : %v", msg.MarshaledTime, err)
log.Warningf("Failed to parse event time (%s) : %v", msg.MarshaledTime, err)
return
}

View file

@ -23,7 +23,7 @@ func (t *Trigger) OnBucketPour(b *BucketFactory) func(types.Event, *Leaky) *type
err := d.UnmarshalText([]byte(msg.MarshaledTime))
if err != nil {
log.Warningf("Failed unmarshaling event time (%s) : %v", msg.MarshaledTime, err)
log.Warningf("Failed to parse event time (%s) : %v", msg.MarshaledTime, err)
d = now
}

View file

@ -18,7 +18,7 @@ func parseDateWithFormat(date, format string) (string, time.Time) {
}
retstr, err := t.MarshalText()
if err != nil {
log.Warningf("Failed marshaling '%v'", t)
log.Warningf("Failed to serialize '%v'", t)
return "", time.Time{}
}
return string(retstr), t
@ -98,7 +98,7 @@ func ParseDate(in string, p *types.Event, plog *log.Entry) (map[string]string, e
now := time.Now().UTC()
retstr, err := now.MarshalText()
if err != nil {
plog.Warning("Failed marshaling current time")
plog.Warning("Failed to serialize current time")
return ret, err
}
ret["MarshaledTime"] = string(retstr)

View file

@ -11,7 +11,7 @@ import (
func unmarshalJSON(field string, p *types.Event, plog *log.Entry) (map[string]string, error) {
err := json.Unmarshal([]byte(p.Line.Raw), &p.Unmarshaled)
if err != nil {
plog.Errorf("could not unmarshal JSON: %s", err)
plog.Errorf("could not parse JSON: %s", err)
return nil, err
}
plog.Tracef("unmarshaled JSON: %+v", p.Unmarshaled)

View file

@ -132,7 +132,7 @@ func testOneParser(pctx *UnixParserCtx, ectx EnricherCtx, dir string, b *testing
}
if err = yaml.UnmarshalStrict(out.Bytes(), &parser_configs); err != nil {
return fmt.Errorf("failed unmarshaling %s: %w", parser_cfg_file, err)
return fmt.Errorf("failed to parse %s: %w", parser_cfg_file, err)
}
pnodes, err = LoadStages(parser_configs, pctx, ectx)

View file

@ -545,7 +545,7 @@ func Detect(detectReader io.Reader, opts DetectOptions) (Setup, error) {
// }
// err = yaml.Unmarshal(svc.AcquisYAML, svc.DataSource)
// if err != nil {
// return Setup{}, fmt.Errorf("while unmarshaling datasource for service %s: %w", name, err)
// return Setup{}, fmt.Errorf("while parsing datasource for service %s: %w", name, err)
// }
// }

View file

@ -40,7 +40,7 @@ func decodeSetup(input []byte, fancyErrors bool) (Setup, error) {
dec2.KnownFields(true)
if err := dec2.Decode(&ret); err != nil {
return ret, fmt.Errorf("while unmarshaling setup file: %w", err)
return ret, fmt.Errorf("while parsing setup file: %w", err)
}
return ret, nil

View file

@ -819,6 +819,6 @@ update-notifier-motd.timer enabled enabled
setup:
alsdk al; sdf
EOT
assert_output "while unmarshaling setup file: yaml: line 2: could not find expected ':'"
assert_output "while parsing setup file: yaml: line 2: could not find expected ':'"
assert_stderr --partial "invalid setup file"
}