From 094d9faad84fbcab4a9ce7cbe917f9900f47245e Mon Sep 17 00:00:00 2001 From: Kaan Barmore-Genc Date: Sat, 17 Dec 2022 21:38:45 -0500 Subject: [PATCH] Add firefox xml parsing error --- .../2022-12-17.firefox.xml-parsing-error.png | 3 ++ ...refox-xml-parsing-error-no-root-element.md | 44 +++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 content/img/2022-12-17.firefox.xml-parsing-error.png create mode 100644 content/posts/2022.12.17.firefox-xml-parsing-error-no-root-element.md diff --git a/content/img/2022-12-17.firefox.xml-parsing-error.png b/content/img/2022-12-17.firefox.xml-parsing-error.png new file mode 100644 index 0000000..62c9b71 --- /dev/null +++ b/content/img/2022-12-17.firefox.xml-parsing-error.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b8db9e0967b1242773ae909e1f0989b0aac19d289af31d1f4fb85b278b3ffe77 +size 9340 diff --git a/content/posts/2022.12.17.firefox-xml-parsing-error-no-root-element.md b/content/posts/2022.12.17.firefox-xml-parsing-error-no-root-element.md new file mode 100644 index 0000000..dbb837e --- /dev/null +++ b/content/posts/2022.12.17.firefox-xml-parsing-error-no-root-element.md @@ -0,0 +1,44 @@ +--- +title: 'Solving "XML Parsing Error: no root element found" in Firefox' +date: 2022-12-17T21:27:37-05:00 +toc: false +images: +tags: + - dev + - web +--- + +I've been seeing this error a lot while working on my project [Bulgur Cloud](/bulgur-cloud-intro/). +It seems to show up only on Firefox: + +![Error message in Firefox console. "XML Parsing Error: no root element found. Location: http://...701.jpg Line Number 1, Column 1](/img/2022-12-17.firefox.xml-parsing-error.png) + +What is curious was that I was not actually loading the file mentioned in the +error message. I tried looking up what the error might mean, but all that came +up was very specific issues regarding some web frameworks, unrelated to what I'm +using. + +I later realized however, while I wasn't loading the file in the error message, +I was actually sending a `DELETE` request. The Bulgur Cloud server then responds +to this request with an empty `200 OK` response. Turns out, if you send an empty +response to Firefox, it tries to parse the body of the response even though it's +empty and gives you this error. + +To quiet this error, I started just sending an empty JSON response even for +requests that don't actually need it. Here's some rust code to illustrate the +solution: + +```rust +#[derive(Debug, Serialize)] +pub struct EmptySuccess { + status: &'static str, +} + +// Using actix-web +fn empty_ok_response() -> HttpResponse { + HttpResponse::Ok().json(EmptySuccess { status: "ok"}) +} +``` + +This adds a `{"status": "ok"}` json to the response, which seems to be enough to +make Firefox happy.