e: java.lang.IllegalStateException: Backend Internal error: Exception during file facade code generation(Kotlin)

Viewed 734

In my android app I am using a suspendCoroutine to wrap volley's (android's HTTP library) callbacks in a Kotlin coroutine.

Here is my function

private suspend fun requestManger(
    url: String,
    method: Int,
    body: JSONObject?) = suspendCoroutine<Int> { continuation ->

    val queue = Volley.newRequestQueue(applicationContext)
    val request = object : JsonObjectRequest(method, url, body,
        Response.Listener { response ->
          Log.d(TAG, "doWork: $response")
          continuation.resume(1)
        },
        Response.ErrorListener { error ->
          Log.e(TAG, "doWork: error is", error)
          continuation.resume(0)
        }) {
            override fun getHeaders(): MutableMap<String, String> {
               val params = HashMap<String, String>()
                   params["Content-Type"] = "application/json"
                   params["Authorization"] = "$idToken"

                   return params
                }
             }

                queue.add(request)
        }

But When I try to build it, It gives me this error

e: java.lang.IllegalStateException: Backend Internal error: Exception during file facade code generation

It this worth noting that this error only appear when i use the continuation object inside the Response.ErrorListener(I get this error even if I type continuation without calling any methods e.g: resume, resumeWithException, etc ) If I don't use it the error disappear but i don't want my function to suspended forever when there is an error

1 Answers

I know it's too late to answer this question, and I also don't have a great answer, but I managed to get this exact error just now, using Volley, creating an anonymous object inheriting from JsonObjectRequest, even overriding getHeaders as you did.

In my case though, I was not using continuations at all. I am also not entirely certain what fixed it, though the problem that I ended up "fixing" was that I was creating two of these objects inheriting from JsonObjectRequest, except that the second was being created inside the Response.Listener callback.

As in, in code it looked a little like this:

val request = object : JsonObjectRequest(method, url, body,
    Response.Listener { response ->
        ...
        val nestedRequest = object : JsonObjectRequest(method2, url2, body2,
            Response.Listener { response ->
                ...
            },
            errorListener) {
            override fun getHeaders(): MutableMap<String, String> {
                ...
                return params
            }
        }
        queue.add(nestedRequest)
    },
    errorListener) {
    override fun getHeaders(): MutableMap<String, String> {
        ...
        return params
    }
}
queue.add(request)

The fix which ended up working was just to move the nested object creation out, and doing the work in another function instead.

Something like this:

fun doWork(response: JsonObject) {
    ...
    val nestedRequest = object : JsonObjectRequest(method2, url2, body2,
    Response.Listener { response ->
        ...
    },
    errorListener) {
        override fun getHeaders(): MutableMap<String, String> {
            ...
            return params
        }
    }
    queue.add(nestedRequest)
}
val request = object : JsonObjectRequest(method, url, body,
    Response.Listener { response ->
        doWork(response)
    },
    errorListener) {
    override fun getHeaders(): MutableMap<String, String> {
        ...
        return params
    }
}
queue.add(request)
Related