# Better error message in Upsert Block

**URL:** <https://discuss.dgraph.io/t/better-error-message-in-upsert-block/8515>\
**Category:** Dgraph\
**Tags:** dgraph, kind:enhancement, status:accepted, area:usability, area:upsert\
**Created:** [April 27, 2020, 5:44pm UTC](https://discuss.dgraph.io/t/better-error-message-in-upsert-block/8515 "2020-04-27T17:44:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [April 27, 2020, 5:44pm UTC](https://discuss.dgraph.io/t/better-error-message-in-upsert-block/8515/1 "2020-04-27T17:44:00Z")

</div>

**Moved from GitHub [dgraph/5303](https://github.com/dgraph-io/dgraph/issues/5303)**

_Posted by_ [MichelDiz](https://github.com/MichelDiz):

## Experience Report

> This could be useful to create error UI instead of a JSON response.

### What you wanted to do

An upsert mutation.

The error model we currently have can be bad to read when making big queries. There are users (mainly customers) who make huge queries with many variables. The error message can get big and confusing. In addition to containing characters that hinder reading.

### What you actually did

A wrong upsert block

```auto
upsert {
  query {
    me(func: eq(email, "user@company1.io")) {
      u as uid
      n as name
      a as age
      e as email
    }
  }

  mutation @if(eq(n, "Animesh")) {
    set {
      _:newNode <name> val(name) .
      _:newNode <age> val(age) .
      _:newNode <email> val(email) .
    }
  }
}

```

### Why that wasn’t great, with examples

##### This error is bad for some cases.

```auto
{
  "name": "t",
  "url": "http://localhost:8080/mutate?commitNow=true",
  "errors": [
    {
      "message": "Some variables are defined but not used\nDefined:[__dgraph__ 0 a e n u]\nUsed:[__dgraph__ 0 age email name]\n",
      "extensions": {
        "code": "ErrorInvalidRequest"
      }
    }
  ]
}

```

#### The answer should be something like

```auto
{
   "name": "t",
   "url": "http://localhost:8080/mutate?commitNow=true",
   "errors": [
      {
         "message": "Some variables are defined but not used",
         "Defined": "a e n u",
         "Used": "age email name",
         "extensions": {
            "code": "ErrorInvalidRequest"
         }
      }
   ]
}

```

Or something similar to

```auto
{
   "name": "t",
   "url": "http://localhost:8080/mutate?commitNow=true",
   "errors": [
      {
         "message": "Some variables are defined but not use",
         "Details": {
            "Defined": "a e n u",
            "Used": "age email name"
         },
         "extensions": {
            "code": "ErrorInvalidRequest"
         }
      }
   ]
}

```

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [May 4, 2020, 9:12pm UTC](https://discuss.dgraph.io/t/better-error-message-in-upsert-block/8515/2 "2020-05-04T21:12:34Z")

</div>

[manishrjain](https://github.com/manishrjain) _commented_ :

Would like @MichaelJCompton 's take on this.

---

<div class="post-metadata">

**Author:** ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)\
**Post date:** [May 4, 2020, 10:18pm UTC](https://discuss.dgraph.io/t/better-error-message-in-upsert-block/8515/3 "2020-05-04T22:18:58Z")

</div>

[MichaelJCompton](https://github.com/MichaelJCompton) _commented_ :

I’m always a yes for better error messages! As long as it more quickly helps a user solve the problem with their query, then I’m for it.

This message looks like it tells you what’s wrong pretty nicely, but yes could be formatted better.

I think in terms of the structure of the message, GraphQL spec would want things moved into extensions. I also think error locations really help.

The other thing I’d wonder is it better to have “unused” - that’s what’s important, right? Why do I have to infer the actual error from the two lists?

```auto
   "errors": [
      {
         "message": "Some variables are defined but not used",
         "locations": [{"line": x, "column": y}, ... these can really help!...]
         "extensions": {
            "code": "ErrorInvalidRequest"
            "details": {
               "defined": ["age", "email", "name"],
               "used": ["ag", "email", "name"],
               "unused": ["age"]
            },
         }
      }
   ]

```
