From e95086ba702eb8104928a84658033799ae035b07 Mon Sep 17 00:00:00 2001 From: Jim Kalafut Date: Thu, 11 Feb 2021 19:51:12 -0800 Subject: [PATCH] Improve error messages (#10843) - Fix: "bytes" should be less than %!s(int=131072) message - Also add a missing openapi type that was throwing warnings --- builtin/logical/transit/path_random.go | 4 ++-- sdk/framework/openapi.go | 3 +++ vault/logical_system.go | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/builtin/logical/transit/path_random.go b/builtin/logical/transit/path_random.go index 4ad2d714f8..7f4c9fc39c 100644 --- a/builtin/logical/transit/path_random.go +++ b/builtin/logical/transit/path_random.go @@ -64,14 +64,14 @@ func (b *backend) pathRandomWrite(ctx context.Context, req *logical.Request, d * } if bytes > maxBytes { - return logical.ErrorResponse(`"bytes" should be less than %s`, maxBytes), nil + return logical.ErrorResponse(`"bytes" should be less than %d`, maxBytes), nil } switch format { case "hex": case "base64": default: - return logical.ErrorResponse(fmt.Sprintf("unsupported encoding format %s; must be \"hex\" or \"base64\"", format)), nil + return logical.ErrorResponse("unsupported encoding format %q; must be \"hex\" or \"base64\"", format), nil } randBytes, err := uuid.GenerateRandomBytes(bytes) diff --git a/sdk/framework/openapi.go b/sdk/framework/openapi.go index d723d38f96..282d06d591 100644 --- a/sdk/framework/openapi.go +++ b/sdk/framework/openapi.go @@ -575,6 +575,9 @@ func convertType(t FieldType) schemaType { case TypeTime: ret.baseType = "string" ret.format = "date-time" + case TypeFloat: + ret.baseType = "number" + ret.format = "float" default: log.L().Warn("error parsing field type", "type", t) ret.format = "unknown" diff --git a/vault/logical_system.go b/vault/logical_system.go index aa4d9d2c47..2f79779528 100644 --- a/vault/logical_system.go +++ b/vault/logical_system.go @@ -3158,14 +3158,14 @@ func (b *SystemBackend) pathRandomWrite(ctx context.Context, req *logical.Reques } if bytes > maxBytes { - return logical.ErrorResponse(`"bytes" should be less than %s`, maxBytes), nil + return logical.ErrorResponse(`"bytes" should be less than %d`, maxBytes), nil } switch format { case "hex": case "base64": default: - return logical.ErrorResponse(fmt.Sprintf("unsupported encoding format %s; must be \"hex\" or \"base64\"", format)), nil + return logical.ErrorResponse("unsupported encoding format %q; must be \"hex\" or \"base64\"", format), nil } randBytes, err := uuid.GenerateRandomBytes(bytes)