aws / aws/aws-appsync-community
util.error is silently ignored if its arguments are not strings
- Dominant language
- HTML
- Stars
- 507
- Forks
- 37
- PR merge metrics
- No merged PRs in 30d
Description
If the call to `util.error` is getting a non-string argument then it is silently ignored. All these calls are no-ops:
```js
util.error(25);
util.error(true);
util.error("abc", 25);
```
For example, naively checking an HTTP data source's result code is broken as it will never error even if the `statusCode` is outside the 2xx range:
```js
if (ctx.result.statusCode < 200 || ctx.result.statusCode >= 300) {
util.error(ctx.result.statusCode);
}
return JSON.parse(ctx.result.body);
```
Here's a reproduction:
* repository: [appsync-error-bug](https://github.com/sashee/appsync-error-bug)
* `terraform init`
* `terraform apply`
Send the query:
```graphql
query MyQuery {
getObject {
value
}
}
```
Returns a successful response even though [there are multiple](https://github.com/sashee/appsync-error-bug/blob/main/main.tf#L104) `util.error` calls in the resolver:
```json
{
"data": {
"getObject": {
"value": "test"
}
}
}
```
This bug [was mentioned before](https://repost.aws/questions/QUFJ_G0GnNRVeQxmndWZj5ew/appsync-javascript-resolvers-util-error-not-working).
Contributor guide
Research direction
Start with the linked appsync-error-bug reproduction and follow the Terraform setup in main.tf, then run terraform init and terraform apply. Send the documented MyQuery request and verify whether util.error calls with numeric or boolean arguments cause an error response instead of the successful response shown.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, javascript, terraform
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100