mirror of
https://github.com/johnkerl/miller.git
synced 2026-08-03 04:52:24 +00:00
address some staticcheck issues
This commit is contained in:
parent
f12966c878
commit
bf71f20560
23 changed files with 75 additions and 185 deletions
|
|
@ -6,7 +6,6 @@
|
|||
package dsl
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/lib"
|
||||
|
|
@ -255,12 +254,7 @@ func (node *ASTNode) CheckArity(
|
|||
arity int,
|
||||
) error {
|
||||
if len(node.Children) != arity {
|
||||
return errors.New(
|
||||
fmt.Sprintf(
|
||||
"AST node arity %d, expected %d",
|
||||
len(node.Children), arity,
|
||||
),
|
||||
)
|
||||
return fmt.Errorf("expected AST node arity %d, got %d", arity, len(node.Children))
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@
|
|||
package cst
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/cli"
|
||||
|
|
@ -171,11 +170,9 @@ func (root *RootNode) buildEmitXStatementNode(
|
|||
retval.topLevelEvaluableMap = evaluable
|
||||
|
||||
} else {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"mlr: unlashe-demit node types must be local variables, field names, oosvars, or maps; got %s.",
|
||||
childNode.Type,
|
||||
),
|
||||
return nil, fmt.Errorf(
|
||||
"mlr: unlashed-emit node types must be local variables, field names, oosvars, or maps; got %s.",
|
||||
childNode.Type,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -183,11 +180,9 @@ func (root *RootNode) buildEmitXStatementNode(
|
|||
retval.isLashed = true
|
||||
for _, childNode := range emittablesNode.Children {
|
||||
if !EMITX_NAMED_NODE_TYPES[childNode.Type] {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"mlr: lashed-emit node types must be local variables, field names, or oosvars; got %s.",
|
||||
childNode.Type,
|
||||
),
|
||||
return nil, fmt.Errorf(
|
||||
"mlr: lashed-emit node types must be local variables, field names, or oosvars; got %s.",
|
||||
childNode.Type,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -276,12 +271,7 @@ func (root *RootNode) buildEmitXStatementNode(
|
|||
} else if redirectorNode.Type == dsl.NodeTypeRedirectPipe {
|
||||
retval.outputHandlerManager = output.NewPipeWriteHandlerManager(root.recordWriterOptions)
|
||||
} else {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"%s: unhandled redirector node type %s.",
|
||||
"mlr", string(redirectorNode.Type),
|
||||
),
|
||||
)
|
||||
return nil, fmt.Errorf("mlr: unhandled redirector node type %s.", string(redirectorNode.Type))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -999,12 +989,7 @@ func (node *EmitXStatementNode) emitRecordToFileOrPipe(
|
|||
) error {
|
||||
redirectorTarget := node.redirectorTargetEvaluable.Evaluate(state)
|
||||
if !redirectorTarget.IsString() {
|
||||
return errors.New(
|
||||
fmt.Sprintf(
|
||||
"%s: output redirection yielded %s, not string.",
|
||||
"mlr", redirectorTarget.GetTypeName(),
|
||||
),
|
||||
)
|
||||
return fmt.Errorf("mlr: output redirection yielded %s, not string.", redirectorTarget.GetTypeName())
|
||||
}
|
||||
outputFileName := redirectorTarget.String()
|
||||
|
||||
|
|
|
|||
|
|
@ -122,12 +122,7 @@ func (root *RootNode) BuildTeeStatementNode(astNode *dsl.ASTNode) (IExecutable,
|
|||
} else if redirectorNode.Type == dsl.NodeTypeRedirectPipe {
|
||||
retval.outputHandlerManager = output.NewPipeWriteHandlerManager(root.recordWriterOptions)
|
||||
} else {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"%s: unhandled redirector node type %s.",
|
||||
"mlr", string(redirectorNode.Type),
|
||||
),
|
||||
)
|
||||
return nil, fmt.Errorf("mlr: unhandled redirector node type %s.", string(redirectorNode.Type))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package input
|
|||
|
||||
import (
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/bifs"
|
||||
|
|
@ -124,9 +123,7 @@ func (reader *PseudoReaderGen) tryParse(
|
|||
) (*mlrval.Mlrval, error) {
|
||||
mvalue := mlrval.FromDeferredType(svalue)
|
||||
if mvalue == nil || !mvalue.IsNumeric() {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf("mlr: gen: %s \"%s\" is not parseable as number", name, svalue),
|
||||
)
|
||||
return nil, fmt.Errorf("mlr: gen: %s \"%s\" is not parseable as number", name, svalue)
|
||||
}
|
||||
return mvalue, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import (
|
|||
"bytes"
|
||||
"container/list"
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
|
|
@ -33,10 +32,10 @@ func NewRecordReaderCSV(
|
|||
recordsPerBatch int,
|
||||
) (*RecordReaderCSV, error) {
|
||||
if readerOptions.IRS != "\n" && readerOptions.IRS != "\r\n" {
|
||||
return nil, errors.New("CSV IRS cannot be altered; LF vs CR/LF is autodetected")
|
||||
return nil, fmt.Errorf("for CSV, IRS cannot be altered; LF vs CR/LF is autodetected")
|
||||
}
|
||||
if len(readerOptions.IFS) != 1 {
|
||||
return nil, errors.New("CSV IFS can only be a single character")
|
||||
return nil, fmt.Errorf("for CSV, IFS can only be a single character")
|
||||
}
|
||||
return &RecordReaderCSV{
|
||||
readerOptions: readerOptions,
|
||||
|
|
@ -236,12 +235,10 @@ func (reader *RecordReaderCSV) getRecordBatch(
|
|||
|
||||
} else {
|
||||
if !reader.readerOptions.AllowRaggedCSVInput {
|
||||
err := errors.New(
|
||||
fmt.Sprintf(
|
||||
"mlr: CSV header/data length mismatch %d != %d "+
|
||||
"at filename %s row %d.\n",
|
||||
nh, nd, reader.filename, reader.rowNumber,
|
||||
),
|
||||
err := fmt.Errorf(
|
||||
"mlr: CSV header/data length mismatch %d != %d "+
|
||||
"at filename %s row %d.\n",
|
||||
nh, nd, reader.filename, reader.rowNumber,
|
||||
)
|
||||
errorChannel <- err
|
||||
return
|
||||
|
|
|
|||
|
|
@ -20,7 +20,6 @@ package input
|
|||
|
||||
import (
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
|
|
@ -228,12 +227,10 @@ func getRecordBatchExplicitCSVHeader(
|
|||
// Get data lines on subsequent loop iterations
|
||||
} else {
|
||||
if !reader.readerOptions.AllowRaggedCSVInput && len(reader.headerStrings) != len(fields) {
|
||||
err := errors.New(
|
||||
fmt.Sprintf(
|
||||
"mlr: CSV header/data length mismatch %d != %d "+
|
||||
"at filename %s line %d.\n",
|
||||
len(reader.headerStrings), len(fields), filename, reader.inputLineNumber,
|
||||
),
|
||||
err := fmt.Errorf(
|
||||
"mlr: CSV header/data length mismatch %d != %d "+
|
||||
"at filename %s line %d.\n",
|
||||
len(reader.headerStrings), len(fields), filename, reader.inputLineNumber,
|
||||
)
|
||||
errorChannel <- err
|
||||
return
|
||||
|
|
@ -348,12 +345,10 @@ func getRecordBatchImplicitCSVHeader(
|
|||
}
|
||||
} else {
|
||||
if !reader.readerOptions.AllowRaggedCSVInput && len(reader.headerStrings) != len(fields) {
|
||||
err := errors.New(
|
||||
fmt.Sprintf(
|
||||
"mlr: CSV header/data length mismatch %d != %d "+
|
||||
"at filename %s line %d.\n",
|
||||
len(reader.headerStrings), len(fields), filename, reader.inputLineNumber,
|
||||
),
|
||||
err := fmt.Errorf(
|
||||
"mlr: CSV header/data length mismatch %d != %d "+
|
||||
"at filename %s line %d.\n",
|
||||
len(reader.headerStrings), len(fields), filename, reader.inputLineNumber,
|
||||
)
|
||||
errorChannel <- err
|
||||
return
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package input
|
|||
import (
|
||||
"bufio"
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
|
@ -126,7 +125,7 @@ func (reader *RecordReaderJSON) processHandle(
|
|||
// TODO: make a helper method
|
||||
record := mlrval.GetMap()
|
||||
if record == nil {
|
||||
errorChannel <- errors.New("Internal coding error detected in JSON record-reader")
|
||||
errorChannel <- fmt.Errorf("internal coding error detected in JSON record-reader")
|
||||
return
|
||||
}
|
||||
context.UpdateForInputRecord()
|
||||
|
|
@ -140,24 +139,22 @@ func (reader *RecordReaderJSON) processHandle(
|
|||
} else if mlrval.IsArray() {
|
||||
records := mlrval.GetArray()
|
||||
if records == nil {
|
||||
errorChannel <- errors.New("Internal coding error detected in JSON record-reader")
|
||||
errorChannel <- fmt.Errorf("internal coding error detected in JSON record-reader")
|
||||
return
|
||||
}
|
||||
|
||||
for _, mlrval := range records {
|
||||
if !mlrval.IsMap() {
|
||||
// TODO: more context
|
||||
errorChannel <- errors.New(
|
||||
fmt.Sprintf(
|
||||
"Valid but unmillerable JSON. Expected map (JSON object); got %s.",
|
||||
mlrval.GetTypeName(),
|
||||
),
|
||||
errorChannel <- fmt.Errorf(
|
||||
"valid but unmillerable JSON. Expected map (JSON object); got %s.",
|
||||
mlrval.GetTypeName(),
|
||||
)
|
||||
return
|
||||
}
|
||||
record := mlrval.GetMap()
|
||||
if record == nil {
|
||||
errorChannel <- errors.New("Internal coding error detected in JSON record-reader")
|
||||
errorChannel <- fmt.Errorf("internal coding error detected in JSON record-reader")
|
||||
return
|
||||
}
|
||||
context.UpdateForInputRecord()
|
||||
|
|
@ -170,11 +167,9 @@ func (reader *RecordReaderJSON) processHandle(
|
|||
}
|
||||
|
||||
} else {
|
||||
errorChannel <- errors.New(
|
||||
fmt.Sprintf(
|
||||
"Valid but unmillerable JSON. Expected map (JSON object); got %s.",
|
||||
mlrval.GetTypeName(),
|
||||
),
|
||||
errorChannel <- fmt.Errorf(
|
||||
"valid but unmillerable JSON. Expected map (JSON object); got %s.",
|
||||
mlrval.GetTypeName(),
|
||||
)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package input
|
|||
import (
|
||||
"bufio"
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
|
@ -311,7 +311,7 @@ func (s *tXTABIPSSplitter) Split(input string) (key, value string, err error) {
|
|||
// Empty string is a length-0 return value.
|
||||
n := len(input)
|
||||
if n == 0 {
|
||||
return "", "", errors.New("mlr: internal coding error in XTAB reader")
|
||||
return "", "", fmt.Errorf("internal coding error in XTAB reader")
|
||||
}
|
||||
|
||||
// ' abc 123' splits as key '', value 'abc 123'.
|
||||
|
|
@ -360,12 +360,12 @@ type tXTABIPSRegexSplitter struct {
|
|||
func (s *tXTABIPSRegexSplitter) Split(input string) (key, value string, err error) {
|
||||
kv := lib.RegexSplitString(s.ipsRegex, input, 2)
|
||||
if len(kv) == 0 {
|
||||
return "", "", errors.New("mlr: internal coding error in XTAB reader")
|
||||
return "", "", fmt.Errorf("internal coding error in XTAB reader")
|
||||
} else if len(kv) == 1 {
|
||||
return kv[0], "", nil
|
||||
} else if len(kv) == 2 {
|
||||
return kv[0], kv[1], nil
|
||||
} else {
|
||||
return "", "", errors.New("mlr: internal coding error in XTAB reader")
|
||||
return "", "", fmt.Errorf("internal coding error in XTAB reader")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import (
|
|||
"compress/bzip2"
|
||||
"compress/gzip"
|
||||
"compress/zlib"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
|
|
@ -236,10 +236,10 @@ func IsUpdateableInPlace(
|
|||
if strings.HasPrefix(filename, "http://") ||
|
||||
strings.HasPrefix(filename, "https://") ||
|
||||
strings.HasPrefix(filename, "file://") {
|
||||
return errors.New("http://, https://, and file:// URLs are not updateable in place.")
|
||||
return fmt.Errorf("http://, https://, and file:// URLs are not updateable in place.")
|
||||
}
|
||||
if prepipe != "" {
|
||||
return errors.New("input with --prepipe or --prepipex is not updateable in place.")
|
||||
return fmt.Errorf("input with --prepipe or --prepipex is not updateable in place.")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -281,7 +281,7 @@ func WrapOutputHandle(
|
|||
) (io.WriteCloser, bool, error) {
|
||||
switch inputFileEncoding {
|
||||
case FileInputEncodingBzip2:
|
||||
return fileWriteHandle, false, errors.New("bzip2 is not currently supported for in-place mode.")
|
||||
return fileWriteHandle, false, fmt.Errorf("bzip2 is not currently supported for in-place mode.")
|
||||
case FileInputEncodingGzip:
|
||||
return gzip.NewWriter(fileWriteHandle), true, nil
|
||||
case FileInputEncodingZlib:
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ package output
|
|||
import (
|
||||
"bufio"
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
|
@ -283,13 +282,7 @@ func NewPipeWriteOutputHandler(
|
|||
) (*FileOutputHandler, error) {
|
||||
writePipe, err := lib.OpenOutboundHalfPipe(commandString)
|
||||
if err != nil {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"%s: could not launch command \"%s\" for pipe-to.",
|
||||
"mlr",
|
||||
commandString,
|
||||
),
|
||||
)
|
||||
return nil, fmt.Errorf("could not launch command \"%s\" for pipe-to.", commandString)
|
||||
}
|
||||
|
||||
return newOutputHandlerCommon(
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package output
|
|||
import (
|
||||
"bufio"
|
||||
"encoding/csv"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/cli"
|
||||
|
|
@ -23,10 +23,10 @@ type RecordWriterCSV struct {
|
|||
|
||||
func NewRecordWriterCSV(writerOptions *cli.TWriterOptions) (*RecordWriterCSV, error) {
|
||||
if len(writerOptions.OFS) != 1 {
|
||||
return nil, errors.New("CSV OFS can only be a single character")
|
||||
return nil, fmt.Errorf("for CSV, OFS can only be a single character")
|
||||
}
|
||||
if writerOptions.ORS != "\n" && writerOptions.ORS != "\r\n" {
|
||||
return nil, errors.New("CSV ORS cannot be altered")
|
||||
return nil, fmt.Errorf("for CSV, ORS cannot be altered")
|
||||
}
|
||||
return &RecordWriterCSV{
|
||||
writerOptions: writerOptions,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
package output
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/cli"
|
||||
|
|
@ -26,6 +25,6 @@ func Create(writerOptions *cli.TWriterOptions) (IRecordWriter, error) {
|
|||
case "xtab":
|
||||
return NewRecordWriterXTAB(writerOptions)
|
||||
default:
|
||||
return nil, errors.New(fmt.Sprintf("output file format \"%s\" not found", writerOptions.OutputFileFormat))
|
||||
return nil, fmt.Errorf("output file format \"%s\" not found", writerOptions.OutputFileFormat)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ package runtime
|
|||
|
||||
import (
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
|
||||
"github.com/johnkerl/miller/internal/pkg/lib"
|
||||
|
|
@ -407,11 +406,9 @@ func (frame *StackFrame) defineTyped(
|
|||
frame.namesToOffsets[stackVariable.name] = offsetInFrame
|
||||
return nil
|
||||
} else {
|
||||
return errors.New(
|
||||
fmt.Sprintf(
|
||||
"%s: variable %s has already been defined in the same scope.",
|
||||
"mlr", stackVariable.name,
|
||||
),
|
||||
return fmt.Errorf(
|
||||
"%s: variable %s has already been defined in the same scope.",
|
||||
"mlr", stackVariable.name,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
@ -431,11 +428,9 @@ func (frame *StackFrame) setIndexed(
|
|||
newval.PutIndexed(indices, mv)
|
||||
return frame.set(stackVariable, newval)
|
||||
} else {
|
||||
return errors.New(
|
||||
fmt.Sprintf(
|
||||
"%s: map indices must be int or string; got %s.\n",
|
||||
"mlr", leadingIndex.GetTypeName(),
|
||||
),
|
||||
return fmt.Errorf(
|
||||
"%s: map indices must be int or string; got %s.\n",
|
||||
"mlr", leadingIndex.GetTypeName(),
|
||||
)
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package transformers
|
|||
|
||||
import (
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -108,12 +107,7 @@ func NewTransformerLabel(
|
|||
for _, newName := range newNames {
|
||||
_, ok := uniquenessChecker[newName]
|
||||
if ok {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"mlr label: labels must be unique; got duplicate \"%s\"\n",
|
||||
newName,
|
||||
),
|
||||
)
|
||||
return nil, fmt.Errorf("mlr label: labels must be unique; got duplicate \"%s\"\n", newName)
|
||||
}
|
||||
uniquenessChecker[newName] = true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package transformers
|
|||
|
||||
import (
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
|
|
@ -257,11 +256,9 @@ func NewTransformerMergeFields(
|
|||
|
||||
for _, accumulatorName := range accumulatorNameList {
|
||||
if !utils.ValidateStats1AccumulatorName(accumulatorName) {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"%s %s: accumulator \"%s\" not found.\n",
|
||||
"mlr", verbNameMergeFields, accumulatorName,
|
||||
),
|
||||
return nil, fmt.Errorf(
|
||||
"mlr %s: accumulator \"%s\" not found.\n",
|
||||
verbNameMergeFields, accumulatorName,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package transformers
|
|||
|
||||
import (
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -447,12 +446,7 @@ func NewTransformerPut(
|
|||
for _, preset := range presets {
|
||||
pair := strings.SplitN(preset, "=", 2)
|
||||
if len(pair) != 2 {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"mlr: missing \"=\" in preset expression \"%s\".",
|
||||
preset,
|
||||
),
|
||||
)
|
||||
return nil, fmt.Errorf("missing \"=\" in preset expression \"%s\".", preset)
|
||||
}
|
||||
key := pair[0]
|
||||
svalue := pair[1]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package transformers
|
|||
|
||||
import (
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
|
|
@ -149,7 +148,7 @@ func NewTransformerRename(
|
|||
doGsub bool,
|
||||
) (*TransformerRename, error) {
|
||||
if len(names)%2 != 0 {
|
||||
return nil, errors.New("Rename: names string must have even length.")
|
||||
return nil, fmt.Errorf("mlr rename: names string must have even length")
|
||||
}
|
||||
|
||||
oldToNewNames := lib.NewOrderedMap()
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package transformers
|
|||
|
||||
import (
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -140,32 +139,17 @@ func NewTransformerSeqgen(
|
|||
|
||||
fstart, startIsNumeric := start.GetNumericToFloatValue()
|
||||
if !startIsNumeric {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"mlr seqgen: start value should be number; got \"%s\"",
|
||||
startString,
|
||||
),
|
||||
)
|
||||
return nil, fmt.Errorf("mlr seqgen: start value should be number; got \"%s\"", startString)
|
||||
}
|
||||
|
||||
fstop, stopIsNumeric := stop.GetNumericToFloatValue()
|
||||
if !stopIsNumeric {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"mlr seqgen: stop value should be number; got \"%s\"",
|
||||
stopString,
|
||||
),
|
||||
)
|
||||
return nil, fmt.Errorf("mlr seqgen: stop value should be number; got \"%s\"", stopString)
|
||||
}
|
||||
|
||||
fstep, stepIsNumeric := step.GetNumericToFloatValue()
|
||||
if !stepIsNumeric {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"mlr seqgen: step value should be number; got \"%s\"",
|
||||
stepString,
|
||||
),
|
||||
)
|
||||
return nil, fmt.Errorf("mlr seqgen: step value should be number; got \"%s\"", stepString)
|
||||
}
|
||||
|
||||
if fstep > 0 {
|
||||
|
|
@ -176,9 +160,7 @@ func NewTransformerSeqgen(
|
|||
if fstart == fstop {
|
||||
doneComparator = bifs.BIF_equals
|
||||
} else {
|
||||
return nil, errors.New(
|
||||
"mlr seqgen: step must not be zero unless start == stop.",
|
||||
)
|
||||
return nil, fmt.Errorf("mlr seqgen: step must not be zero unless start == stop.")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package transformers
|
|||
import (
|
||||
"bytes"
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
|
|
@ -316,12 +315,7 @@ func NewTransformerStats1(
|
|||
) (*TransformerStats1, error) {
|
||||
for _, name := range accumulatorNameList {
|
||||
if !utils.ValidateStats1AccumulatorName(name) {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"%s stats1: accumulator \"%s\" not found.\n",
|
||||
"mlr", name,
|
||||
),
|
||||
)
|
||||
return nil, fmt.Errorf("mlr stats1: accumulator \"%s\" not found.", name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package transformers
|
|||
|
||||
import (
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -210,12 +209,7 @@ func NewTransformerStats2(
|
|||
) (*TransformerStats2, error) {
|
||||
for _, name := range accumulatorNameList {
|
||||
if !utils.ValidateStats2AccumulatorName(name) {
|
||||
return nil, errors.New(
|
||||
fmt.Sprintf(
|
||||
"%s stats2: accumulator \"%s\" not found.\n",
|
||||
"mlr", name,
|
||||
),
|
||||
)
|
||||
return nil, fmt.Errorf("mlr stats2: accumulator \"%s\" not found.", name)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ package transformers
|
|||
|
||||
import (
|
||||
"container/list"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strings"
|
||||
|
|
@ -180,16 +179,12 @@ func NewTransformerStep(
|
|||
) (*TransformerStep, error) {
|
||||
|
||||
if len(stepperNames) == 0 || len(valueFieldNames) == 0 {
|
||||
return nil, errors.New(
|
||||
// TODO: parameterize verb here somehow
|
||||
"mlr step: -a and -f are both required arguments.",
|
||||
)
|
||||
return nil, fmt.Errorf("mlr %s: -a and -f are both required arguments.", verbNameStep)
|
||||
}
|
||||
if len(stringAlphas) != 0 && len(ewmaSuffixes) != 0 {
|
||||
if len(ewmaSuffixes) != len(stringAlphas) {
|
||||
return nil, errors.New(
|
||||
// TODO: parameterize verb here somehow
|
||||
"mlr step: If -d and -o are provided, their values must have the same length.",
|
||||
return nil, fmt.Errorf(
|
||||
"mlr %s: If -d and -o are provided, their values must have the same length.", verbNameStep,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -219,16 +219,13 @@ func (factory *Stats1AccumulatorFactory) MakeNamedAccumulator(
|
|||
valueFieldName,
|
||||
doInterpolatedPercentiles,
|
||||
)
|
||||
// We don't return errors.New here. The nominal case is that the stats1
|
||||
// verb has already pre-validated accumulator names, and this is just a
|
||||
// fallback. The accumulators are instantiated for every unique combination
|
||||
// of group-by field values in the record stream, only as those values are
|
||||
// encountered: for example, with 'mlr stats1 -a count,sum -f x,y -g
|
||||
// color,shape', we make a new accumulator the first time we find a record
|
||||
// with 'color=blue,shape=square' and another the first time we find a
|
||||
// record with 'color=red,shape=circle', and so on. The right thing is to
|
||||
// pre-validate names once when the stats1 transformer is being
|
||||
// instantiated.
|
||||
// We don't return an error here -- we fatal. The nominal case is that the stats1 verb has already
|
||||
// pre-validated accumulator names, and this is just a fallback. The accumulators are instantiated for
|
||||
// every unique combination of group-by field values in the record stream, only as those values are
|
||||
// encountered: for example, with 'mlr stats1 -a count,sum -f x,y -g color,shape', we make a new
|
||||
// accumulator the first time we find a record with 'color=blue,shape=square' and another the first time
|
||||
// we find a record with 'color=red,shape=circle', and so on. The right thing is to pre-validate names
|
||||
// once when the stats1 transformer is being instantiated.
|
||||
lib.InternalCodingErrorIf(accumulator == nil)
|
||||
|
||||
return NewStats1NamedAccumulator(
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
mlr stats1: accumulator "nonesuch" not found.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue