Skip to content

Commit

Permalink
fix(condo): DOMA-10232 wrong argument error type
Browse files Browse the repository at this point in the history
  • Loading branch information
pahaz committed Oct 8, 2024
1 parent 965509c commit 09307f1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ const RegisterMetersReadingsService = new GQLCustomSchema('RegisterMetersReading
const valuesList = errorValuesKeys.map((errKey) => {
const column = i18n(`meter.import.column.${errKey}`, { locale })
return `"${column}"="${errorValues[errKey]}"`
})
}).join(', ')
resultRows.push(new GQLError(
{ ...ERRORS.INVALID_METER_VALUES, messageInterpolation: { valuesList } },
context,
Expand Down
27 changes: 27 additions & 0 deletions packages/keystone/apolloErrorFormatter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,33 @@ describe('safeFormatError hide=false', () => {
},
})
})
test('safeFormatError(GQLError) with messageInterpolation with existing keys', () => {
const message1 = '{foo} and {bar}'
const error = new GQLError({
code: 'INTERNAL_ERROR',
type: 'SOME_TYPE',
message: message1,
messageInterpolation: {
foo: 'string',
bar: 1,
},
})
expect(safeFormatError(error)).toEqual({
'name': 'GQLError',
'message': 'string and 1',
'stack': expect.stringMatching(new RegExp('^GQLError: string and 1')),
'extensions': {
code: 'INTERNAL_ERROR',
type: 'SOME_TYPE',
'message': 'string and 1',
'messageTemplate': message1,
messageInterpolation: {
foo: 'string',
bar: 1,
},
},
})
})
test('safeFormatError(GQLError) with context', () => {
const message1 = Date.now().toString()
const message2 = 'GQL' + (Date.now() % 100).toString()
Expand Down
2 changes: 1 addition & 1 deletion packages/keystone/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class GQLError extends Error {
}
for (const [key, value] of Object.entries(fields.messageInterpolation)) {
if (typeof key !== 'string') throw new Error(`GQLError: messageInterpolation key is not a string; key = ${key}`)
if (typeof value !== 'string' && typeof value !== 'number') throw new Error(`GQLError: messageInterpolation value is not a string|number; key = ${key}; value = ${value}`)
if (typeof value !== 'string' && typeof value !== 'number') throw new Error(`GQLError: messageInterpolation value is not a string|number; key = ${key}; value = ${value}; type = ${typeof value}`)
}
}
super(extensions.message)
Expand Down

0 comments on commit 09307f1

Please sign in to comment.