Skip to content

Better error message in Upsert Block #5303

@MichelDiz

Description

@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

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.
{
  "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

{
   "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

{
   "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"
         }
      }
   ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Stalearea/upsertIssues related to upsert operations.area/usabilityIssues with usability and error messagesdgraphIssue or PR created by an internal Dgraph contributor.kind/enhancementSomething could be better.status/acceptedWe accept to investigate/work on it.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions