mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed? Refactor: use new `serviceerror.New...f` constructors. ## Why? Most of service errors now supports `fmt.Sprintf` format and they should be used instead of `fmt.Sprintf`. ## How did you test it? - [ ] built - [ ] run locally and tested manually - [x] covered by existing tests - [ ] added new unit test(s) - [ ] added new functional test(s)
42 lines
846 B
Go
42 lines
846 B
Go
package query
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
|
|
"go.temporal.io/api/serviceerror"
|
|
)
|
|
|
|
type (
|
|
ConverterError struct {
|
|
message string
|
|
}
|
|
)
|
|
|
|
var (
|
|
MalformedSqlQueryErrMessage = "malformed SQL query"
|
|
NotSupportedErrMessage = "operation is not supported"
|
|
InvalidExpressionErrMessage = "invalid expression"
|
|
)
|
|
|
|
func NewConverterError(format string, a ...interface{}) error {
|
|
message := fmt.Sprintf(format, a...)
|
|
return &ConverterError{message: message}
|
|
}
|
|
|
|
func (c *ConverterError) Error() string {
|
|
return c.message
|
|
}
|
|
|
|
func (c *ConverterError) ToInvalidArgument() error {
|
|
return serviceerror.NewInvalidArgumentf("invalid query: %v", c)
|
|
}
|
|
|
|
func wrapConverterError(message string, err error) error {
|
|
var converterErr *ConverterError
|
|
if errors.As(err, &converterErr) {
|
|
return NewConverterError("%s: %v", message, converterErr)
|
|
}
|
|
return err
|
|
}
|