Skip to content

Commit 559f983

Browse files
committed
prettify error messages
Change `"%s"` to `%q` in validate_variable.lua. Inspired by tarantool/cartridge@086d401
1 parent 11cb8c3 commit 559f983

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

graphql/validate_variables.lua

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ local function checkVariableValue(variableName, value, variableType)
1717
if isNonNull then
1818
variableType = types.nullable(variableType)
1919
if value == nil then
20-
error(('Variable "%s" expected to be non-null'):format(variableName))
20+
error(('Variable %q expected to be non-null'):format(variableName))
2121
end
2222
end
2323

@@ -32,11 +32,11 @@ local function checkVariableValue(variableName, value, variableType)
3232

3333
if isList then
3434
if type(value) ~= 'table' then
35-
error(('Variable "%s" for a List must be a Lua ' ..
35+
error(('Variable %q for a List must be a Lua ' ..
3636
'table, got %s'):format(variableName, type(value)))
3737
end
3838
if not util.is_array(value) then
39-
error(('Variable "%s" for a List must be an array, ' ..
39+
error(('Variable %q for a List must be an array, ' ..
4040
'got map'):format(variableName))
4141
end
4242
assert(variableType.ofType ~= nil, 'variableType.ofType must not be nil')
@@ -49,7 +49,7 @@ local function checkVariableValue(variableName, value, variableType)
4949

5050
if isInputObject then
5151
if type(value) ~= 'table' then
52-
error(('Variable "%s" for the InputObject "%s" must ' ..
52+
error(('Variable %q for the InputObject %q must ' ..
5353
'be a Lua table, got %s'):format(variableName, variableType.name,
5454
type(value)))
5555
end
@@ -66,13 +66,13 @@ local function checkVariableValue(variableName, value, variableType)
6666
for fieldName, _ in pairs(fieldNameSet) do
6767
local fieldValue = value[fieldName]
6868
if type(fieldName) ~= 'string' then
69-
error(('Field key of the variable "%s" for the ' ..
70-
'InputObject "%s" must be a string, got %s'):format(variableName,
69+
error(('Field key of the variable %q for the ' ..
70+
'InputObject %q must be a string, got %s'):format(variableName,
7171
variableType.name, type(fieldName)))
7272
end
7373
if type(variableType.fields[fieldName]) == 'nil' then
74-
error(('Unknown field "%s" of the variable "%s" ' ..
75-
'for the InputObject "%s"'):format(fieldName, variableName,
74+
error(('Unknown field %q of the variable %q ' ..
75+
'for the InputObject %q'):format(fieldName, variableName,
7676
variableType.name))
7777
end
7878

@@ -90,27 +90,27 @@ local function checkVariableValue(variableName, value, variableType)
9090
return
9191
end
9292
end
93-
error(('Wrong variable "%s" for the Enum "%s" with value %s'):format(
93+
error(('Wrong variable %q for the Enum "%s" with value %q'):format(
9494
variableName, variableType.name, value))
9595
end
9696

9797
if isScalar then
9898
check(variableType.isValueOfTheType, 'isValueOfTheType', 'function')
9999
if not variableType.isValueOfTheType(value) then
100-
error(('Wrong variable "%s" for the Scalar "%s"'):format(
100+
error(('Wrong variable %q for the Scalar %q'):format(
101101
variableName, variableType.name))
102102
end
103103
return
104104
end
105105

106-
error(('Unknown type of the variable "%s"'):format(variableName))
106+
error(('Unknown type of the variable %q'):format(variableName))
107107
end
108108

109109
local function validate_variables(context)
110110
-- check that all variable values have corresponding variable declaration
111111
for variableName, _ in pairs(context.variables or {}) do
112112
if context.variableTypes[variableName] == nil then
113-
error(('There is no declaration for the variable "%s"')
113+
error(('There is no declaration for the variable %q')
114114
:format(variableName))
115115
end
116116
end

0 commit comments

Comments
 (0)