Address some staticcheck issues (#823)

* address some staticcheck issues

* address some staticcheck issues

* address some staticcheck issues

* address some staticcheck issues
This commit is contained in:
John Kerl 2022-01-01 14:28:19 -05:00 committed by GitHub
parent a343741b73
commit a977617797
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
83 changed files with 316 additions and 641 deletions

View file

@ -59,11 +59,6 @@ bench-input:
regression-test:
go test -v regression_test.go
# ----------------------------------------------------------------
# Experimental executables:
scan:
go build github.com/johnkerl/miller/cmd/scan
# ----------------------------------------------------------------
# Formatting
# go fmt ./... finds experimental C files which we want to ignore.
@ -121,4 +116,4 @@ release_tarball: build check
# ================================================================
# Go does its own dependency management, outside of make.
.PHONY: build mlr scan check unit_test regression_test bench fmt staticcheck dev docs
.PHONY: build mlr check unit_test regression_test bench fmt staticcheck dev docs

View file

@ -62,14 +62,6 @@ func Dispatch(args []string) {
// Else, return control to main for the rest of Miller.
}
// auxListUsage shows the available auxents.
func auxListUsage(verbName string, o *os.File, exitCode int) {
fmt.Fprintf(o, "Usage: mlr %s [options]\n", verbName)
fmt.Fprintf(o, "Options:\n")
fmt.Fprintf(o, "-h or --help: print this message\n")
os.Exit(exitCode)
}
// auxListMain is the handler for 'mlr aux-list'.
func auxListMain(args []string) int {
ShowAuxEntries(os.Stdout)

View file

@ -24,7 +24,6 @@ func RunMillerCommand(
stdout string,
stderr string,
exitCode int,
executionError error, // failure to even start the process
) {
argsString = strings.TrimRight(argsString, "\n")
argsString = strings.TrimRight(argsString, "\r")
@ -59,7 +58,7 @@ func RunMillerCommand(
}
}
return stdout, stderr, exitCode, nil
return stdout, stderr, exitCode
}
// RunDiffCommandOnStrings runs either diff or fc (not-Windows / Windows

View file

@ -57,7 +57,6 @@ package regtest
import (
"container/list"
"errors"
"fmt"
"io/ioutil"
"os"
@ -422,14 +421,6 @@ func (regtester *RegTester) executeSingleCmdFile(
expectFailFileName := caseDir + slash + ShouldFailName
postCompareFileName := caseDir + slash + PostCompareName
cmd, err = regtester.loadFile(cmdFilePath, caseDir)
if err != nil {
if verbosityLevel >= 2 {
fmt.Printf("%s: %v\n", cmdFilePath, err)
}
return false
}
if verbosityLevel >= 2 {
fmt.Println("Command:")
fmt.Println(cmd)
@ -502,7 +493,7 @@ func (regtester *RegTester) executeSingleCmdFile(
// ****************************************************************
// HERE IS WHERE WE RUN THE MILLER COMMAND LINE FOR THE TEST CASE
actualStdout, actualStderr, actualExitCode, err := RunMillerCommand(regtester.exeName, cmd)
actualStdout, actualStderr, actualExitCode := RunMillerCommand(regtester.exeName, cmd)
// ****************************************************************
// Unset any case-specific environment variables after running the case.
@ -859,11 +850,9 @@ func (regtester *RegTester) loadEnvFile(
}
fields := strings.SplitN(line, "=", 2)
if len(fields) != 2 {
return nil, errors.New(
fmt.Sprintf(
"mlr: could not parse line \"%s\" from file \"%s\".\n",
line, filename,
),
return nil, fmt.Errorf(
"mlr: could not parse line \"%s\" from file \"%s\".\n",
line, filename,
)
}
keyValuePairs.Put(fields[0], fields[1])
@ -898,11 +887,9 @@ func (regtester *RegTester) loadStringPairFile(
}
fields := strings.SplitN(line, " ", 2) // TODO: split on multi-space
if len(fields) != 2 {
return nil, errors.New(
fmt.Sprintf(
"mlr: could not parse line \"%s\" from file \"%s\".\n",
line, filename,
),
return nil, fmt.Errorf(
"mlr: could not parse line \"%s\" from file \"%s\".\n",
line, filename,
)
}
pair := stringPair{first: fields[0], second: fields[1]}

View file

@ -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
}

View file

@ -6,7 +6,7 @@
package cst
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/dsl"
"github.com/johnkerl/miller/internal/pkg/lib"
@ -70,7 +70,7 @@ func (root *RootNode) BuildReturnNode(astNode *dsl.ASTNode) (*ReturnNode, error)
} else {
lib.InternalCodingErrorIf(true)
}
return nil, errors.New("Internal coding error: Statement should not be reached.")
return nil, fmt.Errorf("internal coding error: statement should not be reached.")
}
func (node *ReturnNode) Execute(state *runtime.State) (*BlockExitPayload, error) {

View file

@ -5,7 +5,6 @@
package cst
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/bifs"
@ -53,9 +52,9 @@ func (root *RootNode) BuildBuiltinFunctionCallsiteNode(
} else if builtinFunctionInfo.variadicFuncWithState != nil {
return root.BuildVariadicFunctionWithStateCallsiteNode(astNode, builtinFunctionInfo)
} else {
return nil, errors.New(
"CST BuildFunctionCallsiteNode: builtin function not implemented yet: " +
functionName,
return nil, fmt.Errorf(
"at CST BuildFunctionCallsiteNode: builtin function not implemented yet: %s",
functionName,
)
}
}
@ -79,11 +78,9 @@ func (root *RootNode) BuildMultipleArityFunctionCallsiteNode(
return root.BuildTernaryFunctionCallsiteNode(astNode, builtinFunctionInfo)
}
return nil, errors.New(
fmt.Sprintf(
"CST BuildMultipleArityFunctionCallsiteNode: function name not found: " +
builtinFunctionInfo.name,
),
return nil, fmt.Errorf(
"at CST BuildMultipleArityFunctionCallsiteNode: function name not found: " +
builtinFunctionInfo.name,
)
}
@ -99,14 +96,12 @@ func (root *RootNode) BuildZaryFunctionCallsiteNode(
callsiteArity := len(astNode.Children)
expectedArity := 0
if callsiteArity != expectedArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
),
return nil, fmt.Errorf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
)
}
@ -134,14 +129,12 @@ func (root *RootNode) BuildUnaryFunctionCallsiteNode(
callsiteArity := len(astNode.Children)
expectedArity := 1
if callsiteArity != expectedArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
),
return nil, fmt.Errorf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
)
}
@ -175,14 +168,12 @@ func (root *RootNode) BuildUnaryFunctionWithContextCallsiteNode(
callsiteArity := len(astNode.Children)
expectedArity := 1
if callsiteArity != expectedArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
),
return nil, fmt.Errorf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
)
}
@ -217,14 +208,12 @@ func (root *RootNode) BuildBinaryFunctionCallsiteNode(
callsiteArity := len(astNode.Children)
expectedArity := 2
if callsiteArity != expectedArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
),
return nil, fmt.Errorf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
)
}
@ -293,14 +282,12 @@ func (root *RootNode) BuildBinaryFunctionWithStateCallsiteNode(
callsiteArity := len(astNode.Children)
expectedArity := 2
if callsiteArity != expectedArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
),
return nil, fmt.Errorf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
)
}
@ -345,14 +332,12 @@ func (root *RootNode) BuildTernaryFunctionWithStateCallsiteNode(
callsiteArity := len(astNode.Children)
expectedArity := 3
if callsiteArity != expectedArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
),
return nil, fmt.Errorf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
)
}
@ -433,14 +418,12 @@ func (root *RootNode) BuildRegexCaptureBinaryFunctionCallsiteNode(
callsiteArity := len(astNode.Children)
expectedArity := 2
if callsiteArity != expectedArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
),
return nil, fmt.Errorf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
)
}
@ -487,14 +470,12 @@ func (root *RootNode) BuildDotCallsiteNode(
callsiteArity := len(astNode.Children)
expectedArity := 2
if callsiteArity != expectedArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s invoked with %d argument%s; expected %d",
".",
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
),
return nil, fmt.Errorf(
"mlr: function %s invoked with %d argument%s; expected %d",
".",
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
)
}
@ -551,14 +532,12 @@ func (root *RootNode) BuildTernaryFunctionCallsiteNode(
callsiteArity := len(astNode.Children)
expectedArity := 3
if callsiteArity != expectedArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
),
return nil, fmt.Errorf(
"mlr: function %s invoked with %d argument%s; expected %d",
builtinFunctionInfo.name,
callsiteArity,
lib.Plural(callsiteArity),
expectedArity,
)
}
@ -618,25 +597,21 @@ func (root *RootNode) BuildVariadicFunctionCallsiteNode(
callsiteArity := len(astNode.Children)
if callsiteArity < builtinFunctionInfo.minimumVariadicArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s takes minimum argument count %d; got %d.\n",
builtinFunctionInfo.name,
builtinFunctionInfo.minimumVariadicArity,
callsiteArity,
),
return nil, fmt.Errorf(
"mlr: function %s takes minimum argument count %d; got %d.\n",
builtinFunctionInfo.name,
builtinFunctionInfo.minimumVariadicArity,
callsiteArity,
)
}
if builtinFunctionInfo.maximumVariadicArity != 0 {
if callsiteArity > builtinFunctionInfo.maximumVariadicArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s takes maximum argument count %d; got %d.\n",
builtinFunctionInfo.name,
builtinFunctionInfo.maximumVariadicArity,
callsiteArity,
),
return nil, fmt.Errorf(
"mlr: function %s takes maximum argument count %d; got %d.\n",
builtinFunctionInfo.name,
builtinFunctionInfo.maximumVariadicArity,
callsiteArity,
)
}
}
@ -680,25 +655,21 @@ func (root *RootNode) BuildVariadicFunctionWithStateCallsiteNode(
callsiteArity := len(astNode.Children)
if callsiteArity < builtinFunctionInfo.minimumVariadicArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s takes minimum argument count %d; got %d.\n",
builtinFunctionInfo.name,
builtinFunctionInfo.minimumVariadicArity,
callsiteArity,
),
return nil, fmt.Errorf(
"mlr: function %s takes minimum argument count %d; got %d.\n",
builtinFunctionInfo.name,
builtinFunctionInfo.minimumVariadicArity,
callsiteArity,
)
}
if builtinFunctionInfo.maximumVariadicArity != 0 {
if callsiteArity > builtinFunctionInfo.maximumVariadicArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s takes maximum argument count %d; got %d.\n",
builtinFunctionInfo.name,
builtinFunctionInfo.maximumVariadicArity,
callsiteArity,
),
return nil, fmt.Errorf(
"mlr: function %s takes maximum argument count %d; got %d.\n",
builtinFunctionInfo.name,
builtinFunctionInfo.maximumVariadicArity,
callsiteArity,
)
}
}

View file

@ -6,7 +6,7 @@
package cst
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/dsl"
"github.com/johnkerl/miller/internal/pkg/lib"
@ -57,7 +57,7 @@ func (node *CondBlockNode) Execute(
boolValue = false
} else if !isBool {
// TODO: line-number/token info for the DSL expression.
return nil, errors.New("mlr: conditional expression did not evaluate to boolean.")
return nil, fmt.Errorf("mlr: conditional expression did not evaluate to boolean.")
}
if boolValue == true {

View file

@ -17,7 +17,6 @@ package cst
import (
"bytes"
"errors"
"fmt"
"os"
"strings"
@ -138,12 +137,7 @@ func (root *RootNode) buildDumpxStatementNode(
} 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))
}
}
}
@ -216,11 +210,9 @@ func (node *DumpStatementNode) dumpToFileOrPipe(
) 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()

View file

@ -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()

View file

@ -6,7 +6,6 @@
package cst
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/dsl"
@ -120,12 +119,7 @@ func (root *RootNode) BuildEmitFStatementNode(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))
}
}
}
@ -169,12 +163,7 @@ func getNameFromNamedNode(astNode *dsl.ASTNode, description string) (string, err
} else if astNode.Type == dsl.NodeTypeDirectFieldValue {
return string(astNode.Token.Lit), nil
}
return "", errors.New(
fmt.Sprintf(
"%s: can't get name of node type \"%s\" for %s.",
"mlr", string(astNode.Type), description,
),
)
return "", fmt.Errorf("mlr: can't get name of node type \"%s\" for %s.", string(astNode.Type), description)
}
// ----------------------------------------------------------------
@ -198,12 +187,7 @@ func (node *EmitFStatementNode) emitfToFileOrPipe(
) 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()

View file

@ -7,7 +7,6 @@
package cst
import (
"errors"
"fmt"
"os"
@ -80,8 +79,8 @@ func (root *RootNode) BuildEvaluableNode(astNode *dsl.ASTNode) (IEvaluable, erro
return root.BuildUnnamedUDFNode(astNode)
}
return nil, errors.New(
"CST BuildEvaluableNode: unhandled AST node type " + string(astNode.Type),
return nil, fmt.Errorf(
"at CST BuildEvaluableNode: unhandled AST node type %s", string(astNode.Type),
)
}

View file

@ -5,7 +5,7 @@
package cst
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/dsl"
"github.com/johnkerl/miller/internal/pkg/lib"
@ -195,11 +195,9 @@ func (node *ForLoopOneVariableNode) Execute(state *runtime.State) (*BlockExitPay
// silent zero-pass. But maybe we should surface it as an error. Maybe
// with a "mlr put --errors" flag or something.
// } else {
// return nil, errors.New(
// fmt.Sprintf(
// "mlr: looped-over item is not a map or array; got %s",
// indexMlrval.GetTypeName(),
// ),
// return nil, fmt.Errorf(
// "mlr: looped-over item is not a map or array; got %s",
// indexMlrval.GetTypeName(),
// )
return nil, nil
@ -390,11 +388,9 @@ func (node *ForLoopTwoVariableNode) Execute(state *runtime.State) (*BlockExitPay
// silent zero-pass. But maybe we should surface it as an error. Maybe
// with a "mlr put --errors" flag or something.
// } else {
// return nil, errors.New(
// fmt.Sprintf(
// "mlr: looped-over item is not a map or array; got %s",
// indexMlrval.GetTypeName(),
// ),
// return nil, fmt.Errorf(
// "mlr: looped-over item is not a map or array; got %s",
// indexMlrval.GetTypeName(),
// )
return nil, nil
@ -605,11 +601,9 @@ func (node *ForLoopMultivariableNode) executeOuter(
// silent zero-pass. But maybe we should surface it as an error. Maybe
// with a "mlr put --errors" flag or something.
// } else {
// return nil, errors.New(
// fmt.Sprintf(
// "mlr: looped-over item is not a map or array; got %s",
// mv.GetTypeName(),
// ),
// return nil, fmt.Errorf(
// "mlr: looped-over item is not a map or array; got %s",
// mv.GetTypeName(),
// )
return nil, nil
@ -702,11 +696,9 @@ func (node *ForLoopMultivariableNode) executeInner(
// silent zero-pass. But maybe we should surface it as an error. Maybe
// with a "mlr put --errors" flag or something.
// } else {
// return nil, errors.New(
// fmt.Sprintf(
// "mlr: looped-over item is not a map or array; got %s",
// mv.GetTypeName(),
// ),
// return nil, fmt.Errorf(
// "mlr: looped-over item is not a map or array; got %s",
// mv.GetTypeName(),
// )
return nil, nil
@ -808,7 +800,7 @@ func (root *RootNode) BuildTripleForLoopNode(astNode *dsl.ASTNode) (*TripleForLo
precontinuationAssignments = make([]IExecutable, n-1)
for i := 0; i < n-1; i++ {
if continuationExpressionASTNode.Children[i].Type != dsl.NodeTypeAssignment {
return nil, errors.New(
return nil, fmt.Errorf(
"mlr: the non-final triple-for continutation statements must be assignments.",
)
}
@ -825,11 +817,11 @@ func (root *RootNode) BuildTripleForLoopNode(astNode *dsl.ASTNode) (*TripleForLo
bareBooleanASTNode := continuationExpressionASTNode.Children[n-1]
if bareBooleanASTNode.Type != dsl.NodeTypeBareBoolean {
if n == 1 {
return nil, errors.New(
return nil, fmt.Errorf(
"mlr: the triple-for continutation statement must be a bare boolean.",
)
} else {
return nil, errors.New(
return nil, fmt.Errorf(
"mlr: the final triple-for continutation statement must be a bare boolean.",
)
}
@ -902,7 +894,7 @@ func (node *TripleForLoopNode) Execute(state *runtime.State) (*BlockExitPayload,
boolValue, isBool := continuationValue.GetBoolValue()
if !isBool {
// TODO: propagate line-number context
return nil, errors.New("mlr: for-loop continuation did not evaluate to boolean.")
return nil, fmt.Errorf("mlr: for-loop continuation did not evaluate to boolean.")
}
if boolValue == false {
break

View file

@ -5,7 +5,7 @@
package cst
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/dsl"
"github.com/johnkerl/miller/internal/pkg/lib"
@ -127,7 +127,7 @@ func (node *IfChainNode) Execute(state *runtime.State) (*BlockExitPayload, error
boolValue, isBool := condition.GetBoolValue()
if !isBool {
// TODO: line-number/token info for the DSL expression.
return nil, errors.New("mlr: conditional expression did not evaluate to boolean.")
return nil, fmt.Errorf("mlr: conditional expression did not evaluate to boolean.")
}
if boolValue == true {
blockExitPayload, err := ifItem.statementBlockNode.Execute(state)

View file

@ -5,7 +5,7 @@
package cst
import (
"errors"
"fmt"
"math"
"github.com/johnkerl/miller/internal/pkg/dsl"
@ -97,9 +97,7 @@ func (root *RootNode) BuildLeafNode(
break
}
return nil, errors.New(
"CST BuildLeafNode: unhandled AST node " + string(astNode.Type),
)
return nil, fmt.Errorf("at CST BuildLeafNode: unhandled AST node %s", string(astNode.Type))
}
// ----------------------------------------------------------------
@ -443,9 +441,7 @@ func (root *RootNode) BuildContextVariableNode(astNode *dsl.ASTNode) (IEvaluable
}
return nil, errors.New(
"CST BuildContextVariableNode: unhandled context variable " + sval,
)
return nil, fmt.Errorf("at CST BuildContextVariableNode: unhandled context variable %s", sval)
}
// ----------------------------------------------------------------
@ -620,9 +616,7 @@ func (root *RootNode) BuildConstantNode(astNode *dsl.ASTNode) (IEvaluable, error
}
return nil, errors.New(
"CST BuildContextVariableNode: unhandled context variable " + sval,
)
return nil, fmt.Errorf("at CST BuildContextVariableNode: unhandled context variable %s", sval)
}
// ----------------------------------------------------------------

View file

@ -6,7 +6,6 @@
package cst
import (
"errors"
"fmt"
"os"
@ -54,12 +53,12 @@ func (root *RootNode) BuildAssignableNode(
break
case dsl.NodeTypeArrayOrMapPositionalNameAccess:
return nil, errors.New(
return nil, fmt.Errorf(
"mlr: '[[...]]' is allowed on assignment left-hand sides only when immediately preceded by '$'.",
)
break
case dsl.NodeTypeArrayOrMapPositionalValueAccess:
return nil, errors.New(
return nil, fmt.Errorf(
"mlr: '[[[...]]]' is allowed on assignment left-hand sides only when immediately preceded by '$'.",
)
break
@ -77,8 +76,8 @@ func (root *RootNode) BuildAssignableNode(
break
}
return nil, errors.New(
"CST BuildAssignableNode: unhandled AST node " + string(astNode.Type),
return nil, fmt.Errorf(
"at CST BuildAssignableNode: unhandled AST node " + string(astNode.Type),
)
}
@ -121,7 +120,7 @@ func (node *DirectFieldValueLvalueNode) AssignIndexed(
// print inrec attributes. Also, a UDF/UDS invoked from begin/end could try
// to access the inrec, and that would get past the validator.
if state.Inrec == nil {
return errors.New("There is no current record to assign to.")
return fmt.Errorf("there is no current record to assign to.")
}
// AssignmentNode checks for absent, so we just assign whatever we get
@ -220,7 +219,7 @@ func (node *IndirectFieldValueLvalueNode) AssignIndexed(
// print inrec attributes. Also, a UDF/UDS invoked from begin/end could try
// to access the inrec, and that would get past the validator.
if state.Inrec == nil {
return errors.New("There is no current record to assign to.")
return fmt.Errorf("there is no current record to assign to.")
}
lhsFieldName := node.lhsFieldNameExpression.Evaluate(state)
@ -313,7 +312,7 @@ func (node *PositionalFieldNameLvalueNode) Assign(
// print inrec attributes. Also, a UDF/UDS invoked from begin/end could try
// to access the inrec, and that would get past the validator.
if state.Inrec == nil {
return errors.New("There is no current record to assign to.")
return fmt.Errorf("there is no current record to assign to.")
}
lhsFieldIndex := node.lhsFieldIndexExpression.Evaluate(state)
@ -324,11 +323,9 @@ func (node *PositionalFieldNameLvalueNode) Assign(
state.Inrec.PutNameWithPositionalIndex(index, rvalue)
return nil
} else {
return errors.New(
fmt.Sprintf(
"mlr: positional index for $[[...]] assignment must be integer; got %s.",
lhsFieldIndex.GetTypeName(),
),
return fmt.Errorf(
"mlr: positional index for $[[...]] assignment must be integer; got %s.",
lhsFieldIndex.GetTypeName(),
)
}
}
@ -340,7 +337,7 @@ func (node *PositionalFieldNameLvalueNode) AssignIndexed(
) error {
// TODO: reconsider this if /when we decide to allow string-slice
// assignments.
return errors.New(
return fmt.Errorf(
"mlr: $[[...]] = ... expressions are not indexable.",
)
}
@ -433,7 +430,7 @@ func (node *PositionalFieldValueLvalueNode) AssignIndexed(
// print inrec attributes. Also, a UDF/UDS invoked from begin/end could try
// to access the inrec, and that would get past the validator.
if state.Inrec == nil {
return errors.New("There is no current record to assign to.")
return fmt.Errorf("there is no current record to assign to.")
}
lhsFieldIndex := node.lhsFieldIndexExpression.Evaluate(state)
@ -450,11 +447,9 @@ func (node *PositionalFieldValueLvalueNode) AssignIndexed(
state.Inrec.PutCopyWithPositionalIndex(index, rvalue)
return nil
} else {
return errors.New(
fmt.Sprintf(
"mlr: positional index for $[[[...]]] assignment must be integer; got %s.",
lhsFieldIndex.GetTypeName(),
),
return fmt.Errorf(
"mlr: positional index for $[[[...]]] assignment must be integer; got %s.",
lhsFieldIndex.GetTypeName(),
)
}
} else {
@ -536,7 +531,7 @@ func (node *FullSrecLvalueNode) AssignIndexed(
// print inrec attributes. Also, a UDF/UDS invoked from begin/end could try
// to access the inrec, and that would get past the validator.
if state.Inrec == nil {
return errors.New("There is no current record to assign to.")
return fmt.Errorf("there is no current record to assign to.")
}
// AssignmentNode checks for absentness of the rvalue, so we just assign
@ -1095,12 +1090,10 @@ func (node *EnvironmentVariableLvalueNode) Assign(
}
if !name.IsString() {
return errors.New(
fmt.Sprintf(
"ENV[...] assignments must have string names; got %s \"%s\"\n",
name.GetTypeName(),
name.String(),
),
return fmt.Errorf(
"assignments to ENV[...] must have string names; got %s \"%s\"\n",
name.GetTypeName(),
name.String(),
)
}
@ -1118,7 +1111,7 @@ func (node *EnvironmentVariableLvalueNode) AssignIndexed(
indices []*mlrval.Mlrval,
state *runtime.State,
) error {
return errors.New("mlr: ENV[...] cannot be indexed.")
return fmt.Errorf("mlr: ENV[...] cannot be indexed.")
}
func (node *EnvironmentVariableLvalueNode) Unassign(

View file

@ -6,7 +6,6 @@ package cst
import (
"bytes"
"errors"
"fmt"
"os"
@ -281,12 +280,7 @@ func (root *RootNode) buildPrintxStatementNode(
} 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))
}
}
}
@ -362,12 +356,7 @@ func (node *PrintStatementNode) printToFileOrPipe(
) 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()

View file

@ -7,7 +7,6 @@ package cst
import (
"container/list"
"errors"
"fmt"
"os"
"strings"
@ -148,7 +147,7 @@ func (root *RootNode) IngestAST(
warningsAreFatal bool,
) error {
if ast.RootNode == nil {
return errors.New("Cannot build CST from nil AST root")
return fmt.Errorf("cannot build CST from nil AST root")
}
// Check for things that are syntax errors but not done in the AST for
@ -283,9 +282,7 @@ func (root *RootNode) regexProtectPrePassAux(astNode *dsl.ASTNode) {
func (root *RootNode) buildMainPass(ast *dsl.AST, isReplImmediate bool) error {
if ast.RootNode.Type != dsl.NodeTypeStatementBlock {
return errors.New(
"CST root build: non-statement-block AST root node unhandled",
)
return fmt.Errorf("at CST root build: non-statement-block AST root node unhandled")
}
astChildren := ast.RootNode.Children
@ -411,9 +408,7 @@ func (root *RootNode) resolveSubroutineCallsites() error {
return err
}
if uds == nil {
return errors.New(
"mlr: subroutine name not found: " + subroutineName,
)
return fmt.Errorf("mlr: subroutine name not found: " + subroutineName)
}
unresolvedSubroutineCallsite.uds = uds

View file

@ -6,7 +6,7 @@
package cst
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/dsl"
)
@ -67,13 +67,9 @@ func (root *RootNode) BuildStatementNode(
return root.BuildEmitPStatementNode(astNode)
case dsl.NodeTypeBeginBlock:
return nil, errors.New(
"mlr: begin blocks may only be declared at top level.",
)
return nil, fmt.Errorf("mlr: begin blocks may only be declared at top level.")
case dsl.NodeTypeEndBlock:
return nil, errors.New(
"mlr: end blocks may only be declared at top level.",
)
return nil, fmt.Errorf("mlr: end blocks may only be declared at top level.")
case dsl.NodeTypeIfChain:
return root.BuildIfChainNode(astNode)
@ -93,13 +89,9 @@ func (root *RootNode) BuildStatementNode(
return root.BuildTripleForLoopNode(astNode)
case dsl.NodeTypeNamedFunctionDefinition:
return nil, errors.New(
"mlr: functions may only be declared at top level.",
)
return nil, fmt.Errorf("mlr: functions may only be declared at top level.")
case dsl.NodeTypeSubroutineDefinition:
return nil, errors.New(
"mlr: subroutines may only be declared at top level.",
)
return nil, fmt.Errorf("mlr: subroutines may only be declared at top level.")
case dsl.NodeTypeSubroutineCallsite:
return root.BuildSubroutineCallsiteNode(astNode)
@ -111,9 +103,7 @@ func (root *RootNode) BuildStatementNode(
return root.BuildReturnNode(astNode)
default:
return nil, errors.New(
"CST BuildStatementNode: unhandled AST node " + string(astNode.Type),
)
return nil, fmt.Errorf("at CST BuildStatementNode: unhandled AST node %s", string(astNode.Type))
break
}
return statement, nil

View file

@ -5,7 +5,6 @@
package cst
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/dsl"
@ -122,12 +121,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))
}
}
@ -144,12 +138,7 @@ func (root *RootNode) BuildTeeStatementNode(astNode *dsl.ASTNode) (IExecutable,
func (node *TeeStatementNode) Execute(state *runtime.State) (*BlockExitPayload, error) {
expression := node.expressionEvaluable.Evaluate(state)
if !expression.IsMap() {
return nil, errors.New(
fmt.Sprintf(
"%s: tee-evaluaiton yielded %s, not map.",
"mlr", expression.GetTypeName(),
),
)
return nil, fmt.Errorf("mlr: tee-evaluaiton yielded %s, not map.", expression.GetTypeName())
}
err := node.teeToRedirectFunc(expression.GetMap(), state)
return nil, err
@ -162,12 +151,7 @@ func (node *TeeStatementNode) teeToFileOrPipe(
) 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()

View file

@ -5,7 +5,6 @@
package cst
import (
"errors"
"fmt"
"os"
@ -324,14 +323,12 @@ func (manager *UDFManager) LookUp(functionName string, callsiteArity int) (*UDF,
return nil, nil
}
if udf.signature.arity != callsiteArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: function %s invoked with %d argument%s; expected %d",
functionName,
callsiteArity,
lib.Plural(callsiteArity),
udf.signature.arity,
),
return nil, fmt.Errorf(
"mlr: function %s invoked with %d argument%s; expected %d",
functionName,
callsiteArity,
lib.Plural(callsiteArity),
udf.signature.arity,
)
}
return udf, nil
@ -391,21 +388,17 @@ func (root *RootNode) BuildAndInstallUDF(astNode *dsl.ASTNode) error {
functionName := string(astNode.Token.Lit)
if BuiltinFunctionManagerInstance.LookUp(functionName) != nil {
return errors.New(
fmt.Sprintf(
"mlr: function named \"%s\" must not override a built-in function of the same name.",
functionName,
),
return fmt.Errorf(
"mlr: function named \"%s\" must not override a built-in function of the same name.",
functionName,
)
}
if !root.allowUDFUDSRedefinitions {
if root.udfManager.ExistsByName(functionName) {
return errors.New(
fmt.Sprintf(
"mlr: function named \"%s\" has already been defined.",
functionName,
),
return fmt.Errorf(
"mlr: function named \"%s\" has already been defined.",
functionName,
)
}
}

View file

@ -5,7 +5,6 @@
package cst
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/dsl"
@ -174,14 +173,12 @@ func (manager *UDSManager) LookUp(subroutineName string, callsiteArity int) (*UD
return nil, nil
}
if uds.signature.arity != callsiteArity {
return nil, errors.New(
fmt.Sprintf(
"mlr: subroutine %s invoked with %d argument%s; expected %d",
subroutineName,
callsiteArity,
lib.Plural(callsiteArity),
uds.signature.arity,
),
return nil, fmt.Errorf(
"mlr: subroutine %s invoked with %d argument%s; expected %d",
subroutineName,
callsiteArity,
lib.Plural(callsiteArity),
uds.signature.arity,
)
}
return uds, nil
@ -244,11 +241,9 @@ func (root *RootNode) BuildAndInstallUDS(astNode *dsl.ASTNode) error {
if !root.allowUDFUDSRedefinitions {
if root.udsManager.ExistsByName(subroutineName) {
return errors.New(
fmt.Sprintf(
"mlr: subroutine named \"%s\" has already been defined.",
subroutineName,
),
return fmt.Errorf(
"mlr: subroutine named \"%s\" has already been defined.",
subroutineName,
)
}
}

View file

@ -7,7 +7,6 @@
package cst
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/dsl"
@ -32,7 +31,7 @@ func ValidateAST(
// But filter '' is an error.
if ast.RootNode.Children == nil || len(ast.RootNode.Children) == 0 {
if dslInstanceType == DSLInstanceTypeFilter {
return errors.New("mlr: filter statement must not be empty.")
return fmt.Errorf("mlr: filter statement must not be empty.")
}
}
@ -82,7 +81,7 @@ func validateASTAux(
if astNode.Type == dsl.NodeTypeFilterStatement {
if dslInstanceType == DSLInstanceTypeFilter {
return errors.New(
return fmt.Errorf(
"mlr: filter expressions must not also contain the \"filter\" keyword.",
)
}
@ -91,21 +90,21 @@ func validateASTAux(
// Check: begin/end/func/subr must be at top-level
if astNode.Type == dsl.NodeTypeBeginBlock {
if !atTopLevel {
return errors.New(
return fmt.Errorf(
"mlr: begin blocks can only be at top level.",
)
}
nextLevelInBeginOrEnd = true
} else if astNode.Type == dsl.NodeTypeEndBlock {
if !atTopLevel {
return errors.New(
return fmt.Errorf(
"mlr: end blocks can only be at top level.",
)
}
nextLevelInBeginOrEnd = true
} else if astNode.Type == dsl.NodeTypeNamedFunctionDefinition {
if !atTopLevel {
return errors.New(
return fmt.Errorf(
"mlr: func blocks can only be at top level.",
)
}
@ -114,7 +113,7 @@ func validateASTAux(
nextLevelInUDF = true
} else if astNode.Type == dsl.NodeTypeSubroutineDefinition {
if !atTopLevel {
return errors.New(
return fmt.Errorf(
"mlr: subr blocks can only be at top level.",
)
}
@ -136,7 +135,7 @@ func validateASTAux(
if astNode.Type == dsl.NodeTypeDirectFieldValue ||
astNode.Type == dsl.NodeTypeIndirectFieldValue ||
astNode.Type == dsl.NodeTypeFullSrec {
return errors.New(
return fmt.Errorf(
"mlr: begin/end blocks cannot refer to records via $x, $*, etc.",
)
}
@ -145,7 +144,7 @@ func validateASTAux(
// Check: break/continue outside of loop
if !inLoop {
if astNode.Type == dsl.NodeTypeBreak {
return errors.New(
return fmt.Errorf(
"mlr: break statements are only valid within for/do/while loops.",
)
}
@ -153,7 +152,7 @@ func validateASTAux(
if !inLoop {
if astNode.Type == dsl.NodeTypeContinue {
return errors.New(
return fmt.Errorf(
"mlr: break statements are only valid within for/do/while loops.",
)
}
@ -171,7 +170,7 @@ func validateASTAux(
// Check: return outside of func/subr
if !inUDF && !inUDS {
if astNode.Type == dsl.NodeTypeReturn {
return errors.New(
return fmt.Errorf(
"mlr: return statements are only valid within func/subr blocks.",
)
}
@ -181,14 +180,14 @@ func validateASTAux(
if astNode.Type == dsl.NodeTypeReturn {
if inUDF {
if len(astNode.Children) != 1 {
return errors.New(
return fmt.Errorf(
"mlr: return statements in func blocks must return a value.",
)
}
}
if inUDS {
if len(astNode.Children) != 0 {
return errors.New(
return fmt.Errorf(
"mlr: return statements in subr blocks must not return a value.",
)
}
@ -199,11 +198,9 @@ func validateASTAux(
if isAssignmentLHS {
ok := VALID_LHS_NODE_TYPES[astNode.Type]
if !ok {
return errors.New(
fmt.Sprintf(
"mlr: %s is not valid on the left-hand side of an assignment.",
astNode.Type,
),
return fmt.Errorf(
"mlr: %s is not valid on the left-hand side of an assignment.",
astNode.Type,
)
}
}
@ -212,11 +209,9 @@ func validateASTAux(
if isUnset {
ok := VALID_LHS_NODE_TYPES[astNode.Type]
if !ok {
return errors.New(
fmt.Sprintf(
"mlr: %s is not valid for unset statement.",
astNode.Type,
),
return fmt.Errorf(
"mlr: %s is not valid for unset statement.",
astNode.Type,
)
}
}
@ -268,13 +263,7 @@ func validateForLoopTwoVariableUniqueNames(astNode *dsl.ASTNode) error {
keyVarName := string(keyVarNode.Token.Lit)
valVarName := string(valVarNode.Token.Lit)
if keyVarName == valVarName {
return errors.New(
fmt.Sprintf(
"%s: redefinition of variable %s in the same scope.",
"mlr",
keyVarName,
),
)
return fmt.Errorf("mlr: redefinition of variable %s in the same scope.", keyVarName)
} else {
return nil
}
@ -304,26 +293,14 @@ func validateForLoopMultivariableUniqueNames(astNode *dsl.ASTNode) error {
name := string(keyVarNode.Token.Lit)
_, present := seen[name]
if present {
return errors.New(
fmt.Sprintf(
"%s: redefinition of variable %s in the same scope.",
"mlr",
name,
),
)
return fmt.Errorf("mlr: redefinition of variable %s in the same scope.", name)
}
seen[name] = true
}
valVarName := string(valVarNode.Token.Lit)
if seen[valVarName] {
return errors.New(
fmt.Sprintf(
"%s: redefinition of variable %s in the same scope.",
"mlr",
valVarName,
),
)
return fmt.Errorf("mlr: redefinition of variable %s in the same scope.", valVarName)
}
return nil

View file

@ -5,7 +5,7 @@
package cst
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/dsl"
"github.com/johnkerl/miller/internal/pkg/lib"
@ -54,7 +54,7 @@ func (node *WhileLoopNode) Execute(state *runtime.State) (*BlockExitPayload, err
boolValue, isBool := condition.GetBoolValue()
if !isBool {
// TODO: line-number/token info for the DSL expression.
return nil, errors.New("mlr: conditional expression did not evaluate to boolean.")
return nil, fmt.Errorf("mlr: conditional expression did not evaluate to boolean.")
}
if boolValue != true {
break
@ -144,7 +144,7 @@ func (node *DoWhileLoopNode) Execute(state *runtime.State) (*BlockExitPayload, e
boolValue, isBool := condition.GetBoolValue()
if !isBool {
// TODO: line-number/token info for the DSL expression.
return nil, errors.New("mlr: conditional expression did not evaluate to boolean.")
return nil, fmt.Errorf("mlr: conditional expression did not evaluate to boolean.")
}
if boolValue == false {
break

View file

@ -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
}

View file

@ -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

View file

@ -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

View file

@ -1,7 +1,6 @@
package input
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/cli"
@ -26,6 +25,6 @@ func Create(readerOptions *cli.TReaderOptions, recordsPerBatch int) (IRecordRead
case "gen":
return NewPseudoReaderGen(readerOptions, recordsPerBatch)
default:
return nil, errors.New(fmt.Sprintf("input file format \"%s\" not found", readerOptions.InputFileFormat))
return nil, fmt.Errorf("input file format \"%s\" not found", readerOptions.InputFileFormat)
}
}

View file

@ -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
}

View file

@ -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")
}
}

View file

@ -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:

View file

@ -2,7 +2,6 @@ package mlrval
import (
"bytes"
"errors"
"fmt"
"strconv"
@ -84,9 +83,7 @@ func (mlrmap *Mlrmap) PutReferenceMaybeDedupe(key string, value *Mlrval, dedupe
return newKey, nil
}
}
return key, errors.New(
fmt.Sprintf("record has too many input fields named \"%s\"", key),
)
return key, fmt.Errorf("record has too many input fields named \"%s\"", key)
}
// PutCopy copies the key and value (deep-copying in case the value is array/map).
@ -250,8 +247,8 @@ func (mlrmap *Mlrmap) PutCopyWithMlrvalIndex(key *Mlrval, value *Mlrval) error {
mlrmap.PutCopy(key.String(), value)
return nil
} else {
return errors.New(
"mlr: record/map indices must be string, int, or array thereof; got " + key.GetTypeName(),
return fmt.Errorf(
"mlr: record/map indices must be string, int, or array thereof; got %s", key.GetTypeName(),
)
}
}
@ -352,9 +349,7 @@ func (mlrmap *Mlrmap) getWithMlrvalArrayIndex(index *Mlrval) (*Mlrval, error) {
}
if i < n-1 {
if !next.IsMap() {
return nil, errors.New(
"mlr: cannot multi-index non-map.",
)
return nil, fmt.Errorf("mlr: cannot multi-index non-map.")
}
current = next.mapval
} else {
@ -371,8 +366,8 @@ func (mlrmap *Mlrmap) getWithMlrvalSingleIndex(index *Mlrval) (*Mlrval, error) {
} else if index.IsInt() {
return mlrmap.Get(index.String()), nil
} else {
return nil, errors.New(
"Record/map indices must be string, int, or array thereof; got " + index.GetTypeName(),
return nil, fmt.Errorf(
"Record/map indices must be string, int, or array thereof; got %s", index.GetTypeName(),
)
}
}

View file

@ -1,7 +1,6 @@
package mlrval
import (
"errors"
"fmt"
"strconv"
"strings"
@ -85,13 +84,11 @@ func newFormatter(
) (IFormatter, error) {
numPercents := strings.Count(userLevelFormatString, "%")
if numPercents < 1 {
return nil, errors.New(
fmt.Sprintf("unhandled format string \"%s\": no leading \"%%\"", userLevelFormatString),
)
return nil, fmt.Errorf("unhandled format string \"%s\": no leading \"%%\"", userLevelFormatString)
}
if numPercents > 1 {
return nil, errors.New(
fmt.Sprintf("unhandled format string \"%s\": needs no \"%%\" after the first", userLevelFormatString),
return nil, fmt.Errorf(
"unhandled format string \"%s\": needs no \"%%\" after the first", userLevelFormatString,
)
}

View file

@ -11,7 +11,7 @@ package mlrval
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"github.com/johnkerl/miller/internal/pkg/colorizer"
@ -105,7 +105,7 @@ func (mv *Mlrval) UnmarshalJSON(inputBytes []byte) error {
decoder := json.NewDecoder(bytes.NewReader(inputBytes))
pmv, eof, err := MlrvalDecodeFromJSON(decoder)
if eof {
return errors.New("Miller JSON parser: unexpected premature EOF.")
return fmt.Errorf("mlr: JSON parser: unexpected premature EOF.")
}
if err != nil {
return err
@ -155,8 +155,8 @@ func MlrvalDecodeFromJSON(decoder *json.Decoder) (
return mlrval, false, nil
}
return nil, false, errors.New(
"Miller JSON reader internal coding error: non-delimiter token unhandled",
return nil, false, fmt.Errorf(
"mlr: JSON reader internal coding error: non-delimiter token unhandled",
)
} else {
@ -173,8 +173,8 @@ func MlrvalDecodeFromJSON(decoder *json.Decoder) (
expectedClosingDelimiter = '}'
collectionType = "JSON object`"
} else {
return nil, false, errors.New(
"Miller JSON reader: Unhandled opening delimiter \"" + string(delimiter) + "\"",
return nil, false, fmt.Errorf(
"mlr: JSON reader: Unhandled opening delimiter \"%s\"", string(delimiter),
)
}
@ -186,7 +186,7 @@ func MlrvalDecodeFromJSON(decoder *json.Decoder) (
element, eof, err := MlrvalDecodeFromJSON(decoder)
if eof {
// xxx constify
return nil, false, errors.New("Miller JSON parser: unexpected premature EOF.")
return nil, false, fmt.Errorf("mlr: JSON parser: unexpected premature EOF.")
}
if err != nil {
return nil, false, err
@ -201,22 +201,22 @@ func MlrvalDecodeFromJSON(decoder *json.Decoder) (
key, eof, err := MlrvalDecodeFromJSON(decoder)
if eof {
// xxx constify
return nil, false, errors.New("Miller JSON parser: unexpected premature EOF.")
return nil, false, fmt.Errorf("mlr: JSON parser: unexpected premature EOF.")
}
if err != nil {
return nil, false, err
}
if !key.IsString() {
return nil, false, errors.New(
return nil, false, fmt.Errorf(
// TODO: print out what was gotten
"Miller JSON reader: obejct keys must be string-valued.",
"mlr JSON reader: obejct keys must be string-valued.",
)
}
value, eof, err := MlrvalDecodeFromJSON(decoder)
if eof {
// xxx constify
return nil, false, errors.New("Miller JSON parser: unexpected premature EOF.")
return nil, false, fmt.Errorf("mlr: JSON parser: unexpected premature EOF.")
}
if err != nil {
return nil, false, err
@ -227,16 +227,15 @@ func MlrvalDecodeFromJSON(decoder *json.Decoder) (
}
}
imbalanceError := errors.New(
"Miller JSON reader: did not find closing token '" +
string(expectedClosingDelimiter) +
"' for " +
collectionType,
imbalanceError := fmt.Errorf(
"mlr: JSON reader: did not find closing token \"%s\" for %s",
string(expectedClosingDelimiter),
collectionType,
)
endToken, err := decoder.Token()
if err == io.EOF {
return nil, false, errors.New("Miller JSON parser: unexpected premature EOF.")
return nil, false, fmt.Errorf("mlr: JSON parser: unexpected premature EOF.")
}
if err != nil {
return nil, false, err
@ -255,7 +254,7 @@ func MlrvalDecodeFromJSON(decoder *json.Decoder) (
return mv, false, nil
}
return nil, false, errors.New("unimplemented")
return nil, false, fmt.Errorf("mlr: unimplemented")
}
// ================================================================
@ -274,41 +273,30 @@ func (mv *Mlrval) marshalJSONAux(
switch mv.Type() {
case MT_PENDING:
return mv.marshalJSONPending(outputIsStdout)
break
case MT_ERROR:
return mv.marshalJSONError(outputIsStdout)
break
case MT_ABSENT:
return mv.marshalJSONAbsent(outputIsStdout)
break
case MT_NULL:
return mv.marshalJSONNull(outputIsStdout)
break
case MT_VOID:
return mv.marshalJSONVoid(outputIsStdout)
break
case MT_STRING:
return mv.marshalJSONString(outputIsStdout)
break
case MT_INT:
return mv.marshalJSONInt(outputIsStdout)
break
case MT_FLOAT:
return mv.marshalJSONFloat(outputIsStdout)
break
case MT_BOOL:
return mv.marshalJSONBool(outputIsStdout)
break
case MT_ARRAY:
return mv.marshalJSONArray(jsonFormatting, elementNestingDepth, outputIsStdout)
break
case MT_MAP:
return mv.marshalJSONMap(jsonFormatting, elementNestingDepth, outputIsStdout)
break
case MT_DIM: // MT_DIM is one past the last valid type
return "", errors.New("mlr: internal coding error detected")
return "", fmt.Errorf("mlr: internal coding error detected")
}
return "", errors.New("mlr: Internal coding error detected")
return "", fmt.Errorf("mlr: Internal coding error detected")
}
// ================================================================
@ -317,8 +305,8 @@ func (mv *Mlrval) marshalJSONAux(
// ----------------------------------------------------------------
func (mv *Mlrval) marshalJSONPending(outputIsStdout bool) (string, error) {
lib.InternalCodingErrorIf(mv.mvtype != MT_PENDING)
return "", errors.New(
"Miller internal coding error: pending-values should not have been produced",
return "", fmt.Errorf(
"mlr: internal coding error: pending-values should not have been produced",
)
}
@ -331,8 +319,8 @@ func (mv *Mlrval) marshalJSONError(outputIsStdout bool) (string, error) {
// ----------------------------------------------------------------
func (mv *Mlrval) marshalJSONAbsent(outputIsStdout bool) (string, error) {
lib.InternalCodingErrorIf(mv.mvtype != MT_ABSENT)
return "", errors.New(
"Miller internal coding error: absent-values should not have been assigned",
return "", fmt.Errorf(
"mlr: internal coding error: absent-values should not have been assigned",
)
}

View file

@ -42,33 +42,27 @@ func (mv *Mlrval) setPrintRep() {
// clearly visually if it should (buggily) slip through to
// user-level visibility.
mv.printrep = "(bug-if-you-see-this:case=3)" // xxx constdef at top of file
break
case MT_ERROR:
mv.printrep = "(error)" // xxx constdef at top of file
break
case MT_ABSENT:
// Callsites should be using absence to do non-assigns, so flag
// this clearly visually if it should (buggily) slip through to
// user-level visibility.
mv.printrep = "(bug-if-you-see-this:case=4)" // xxx constdef at top of file
break
case MT_VOID:
mv.printrep = "" // xxx constdef at top of file
break
case MT_STRING:
break
case MT_INT:
mv.printrep = strconv.Itoa(mv.intval)
break
case MT_FLOAT:
mv.printrep = strconv.FormatFloat(mv.floatval, 'f', -1, 64)
break
case MT_BOOL:
if mv.boolval == true {
@ -76,7 +70,6 @@ func (mv *Mlrval) setPrintRep() {
} else {
mv.printrep = "false"
}
break
case MT_ARRAY:
bytes, err := mv.MarshalJSON(JSON_MULTILINE, false)
@ -87,8 +80,6 @@ func (mv *Mlrval) setPrintRep() {
}
mv.printrep = string(bytes)
break
case MT_MAP:
bytes, err := mv.MarshalJSON(JSON_MULTILINE, false)
// maybe just InternalCodingErrorIf(err != nil)
@ -97,8 +88,6 @@ func (mv *Mlrval) setPrintRep() {
os.Exit(1)
}
mv.printrep = string(bytes)
break
}
mv.printrepValid = true
}

View file

@ -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(

View file

@ -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,

View file

@ -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)
}
}

View file

@ -9,8 +9,6 @@ import (
type RecordWriterNIDX struct {
writerOptions *cli.TWriterOptions
ofs string
ors string
}
func NewRecordWriterNIDX(writerOptions *cli.TWriterOptions) (*RecordWriterNIDX, error) {

View file

@ -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 {

View file

@ -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
}

View file

@ -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,
)
}
}

View file

@ -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]

View file

@ -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()

View file

@ -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.")
}
}

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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,
)
}
}

View file

@ -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(

View file

@ -6,7 +6,6 @@
package types
import (
"errors"
"fmt"
"github.com/johnkerl/miller/internal/pkg/mlrval"
@ -25,11 +24,7 @@ func NewTypeGatedMlrvalName(
) (*TypeGatedMlrvalName, error) {
typeMask, ok := mlrval.TypeNameToMask(typeName)
if !ok {
return nil, errors.New(
fmt.Sprintf(
"mlr: couldn't resolve type name \"%s\".", typeName,
),
)
return nil, fmt.Errorf("mlr: couldn't resolve type name \"%s\".", typeName)
}
return &TypeGatedMlrvalName{
Name: name,
@ -43,11 +38,9 @@ func (tname *TypeGatedMlrvalName) Check(value *mlrval.Mlrval) error {
if bit&tname.TypeMask != 0 {
return nil
} else {
return errors.New(
fmt.Sprintf(
"mlr: couldn't assign variable %s %s from value %s %s\n",
tname.TypeName, tname.Name, value.GetTypeName(), value.String(),
),
return fmt.Errorf(
"mlr: couldn't assign variable %s %s from value %s %s\n",
tname.TypeName, tname.Name, value.GetTypeName(), value.String(),
)
}
}

View file

@ -1,2 +1 @@
mlr stats1: accumulator "nonesuch" not found.