After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 605387 - Web sync should check HTTP error code instead of immediately trying to parse response as JSON
Web sync should check HTTP error code instead of immediately trying to parse ...
Status: RESOLVED NOTGNOME
Product: tomboy
Classification: Applications
Component: General
1.1.x
Other All
: Normal major
: 1.6.0
Assigned To: Tomboy Maintainers
Tomboy Maintainers
gnome[moved-to-github]
: 606367 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-12-24 19:56 UTC by Joel VanderWerf
Modified: 2017-07-31 12:48 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Crass extra debugging patch (1.03 KB, patch)
2010-10-29 06:45 UTC, Sandy Armstrong
rejected Details | Review
Improve error handling/reporting during sync (16.93 KB, patch)
2010-11-12 07:50 UTC, Aaron D Borden
none Details | Review

Description Joel VanderWerf 2009-12-24 19:56:58 UTC
tomboy 1.1.0 on windows 7

recreating the error:
  start with blank set of notes
  create a note named "foo" with one line of text below the title
  sync to ubuntu one -> no error
  add formatting to the note, say boldface on the one line of text
  sync to ubuntu one -> tomboy.log shows the backtrace below
  this happens with other kinds of formatting as well
  delete the note and sync -> sync completes with no error

12/24/2009 11:25:17 AM [ERROR]: Synchronization failed with the following exception: Unexpected character '<' at [1:1]
   at Hyena.Json.Tokenizer.UnexpectedCharacter(Char ch) in c:\Users\Sandy Armstrong\Desktop\gnome-git\tomboy\Tomboy\Addins\WebSyncService\Hyena.Json\Tokenizer.cs:line 84
   at Hyena.Json.Tokenizer.InnerScan() in c:\Users\Sandy Armstrong\Desktop\gnome-git\tomboy\Tomboy\Addins\WebSyncService\Hyena.Json\Tokenizer.cs:line 320
   at Hyena.Json.Tokenizer.Scan() in c:\Users\Sandy Armstrong\Desktop\gnome-git\tomboy\Tomboy\Addins\WebSyncService\Hyena.Json\Tokenizer.cs:line 265
   at Hyena.Json.Deserializer.CheckScan(TokenType expected, Boolean eofok) in c:\Users\Sandy Armstrong\Desktop\gnome-git\tomboy\Tomboy\Addins\WebSyncService\Hyena.Json\Deserializer.cs:line 141
   at Hyena.Json.Deserializer.Deserialize() in c:\Users\Sandy Armstrong\Desktop\gnome-git\tomboy\Tomboy\Addins\WebSyncService\Hyena.Json\Deserializer.cs:line 63
   at Tomboy.WebSync.Api.UserInfo.ParseJsonNotes(String jsonString, Nullable`1& latestSyncRevision) in c:\Users\Sandy Armstrong\Desktop\gnome-git\tomboy\Tomboy\Addins\WebSyncService\Api\UserInfo.cs:line 160
   at Tomboy.WebSync.Api.UserInfo.UpdateNotes(IList`1 noteUpdates, Int32 expectedNewRevision) in c:\Users\Sandy Armstrong\Desktop\gnome-git\tomboy\Tomboy\Addins\WebSyncService\Api\UserInfo.cs:line 138
   at Tomboy.WebSync.WebSyncServer.CommitSyncTransaction() in c:\Users\Sandy Armstrong\Desktop\gnome-git\tomboy\Tomboy\Addins\WebSyncService\WebSyncServer.cs:line 80
   at Tomboy.Sync.SyncManager.SynchronizationThread() in c:\Users\Sandy Armstrong\Desktop\gnome-git\tomboy\Tomboy\Synchronization\SyncManager.cs:line 465
Comment 1 Sandy Armstrong 2009-12-24 20:05:14 UTC
This is probably actually a bug in Ubuntu One, not Tomboy, but I'll have to investigate.
Comment 2 Joel VanderWerf 2009-12-24 21:14:19 UTC
Yep, that seems possible.

More info:

I've been using tomboy notes (v1.0.0) and Ubuntu One from two linux systems since early Nov. without this problem.

I started using tomboy v1.0.1 on windows a few weeks ago, and it worked ok.

Yesterday I started using v1.1.0 and this problem started happening.

But now, I can't even sync formatted notes from linux (same error about '<' unexpected by json tokenizer).

This still happens even when I clear out all my notes (using either tomboy or the ubuntu web interface). This suggests that there is some bad state in my ubuntu one account.

However: when I rm my .local/share/tomboy, things go back to normal at least on linux: I can add notes with formatting and sync them without error.
Comment 3 Sandy Armstrong 2010-03-08 15:21:24 UTC
So there are two things going on here.  The first was a bug in Ubuntu One that caused an HTML response to be sent due to some internal error.  The second bug is that Tomboy didn't check the HTTP error code on the response, and just assumed it would be a lovely JSON response, as expected.

The formatting issues are undoubtedly U1 bugs, too, but I'm sure they've been fixed by now.  Changing the summary of this bug to reflect the real issue in Tomboy.
Comment 4 Sandy Armstrong 2010-03-08 15:25:50 UTC
See Tomboy/Addins/WebSyncService/Api/OAuth.cs, line 259:

using (var responseReader = new StreamReader (webRequest.GetResponse ().GetResponseStream ())) {
	responseData = responseReader.ReadToEnd ();

We end up returning the responseData without ever checking the response's HTTP status code.

We need to either change our internal API to return both, or (more likely here) throw an exception when a non-success code is returned.
Comment 5 Benjamin Podszun 2010-08-07 09:11:13 UTC
Well, exposing the status code could give it more meaning in the future (unchanged, note redirected) and depending on the status code (4xx or 5xx) it could be presented to the user either as temporary error ("Retry later") or fatal server error ("Ubuntu one is currently down"). Bad idea?

Also, resetting platform to "All" again, since this isn't specific to Windows.
Comment 6 Sandy Armstrong 2010-10-19 23:45:52 UTC
*** Bug 606367 has been marked as a duplicate of this bug. ***
Comment 7 Sandy Armstrong 2010-10-19 23:46:12 UTC
From the dupe:

During a sync with Ubuntu One, tomboy fails because of an error at the
U1 end. The U1 servers return an HTTP 500 error which Tomboy appears to
attempt to interpret. It was suggested by the U1 guys that it might be
useful to file a bug requesting that Tomboy only interprets 200
responses, but others such as 4xx and 5xx get logged or displayed somehow for
diagnostic purposes.

BTW, great info about how this is impacting users here:
https://bugs.launchpad.net/ubuntuone-servers/+bug/479417
Comment 8 Aaron D Borden 2010-10-29 04:57:27 UTC
I'll take a shot. On first look, we're using the generic WebResponse which doesn't support status codes. Is it safe to assume all our sync URIs are going to be HTTP?

Also, I can test against a generic http server, but I'm not sure how I'm going to force a 500 on a U1 server.
Comment 9 Sandy Armstrong 2010-10-29 06:43:55 UTC
(In reply to comment #8)
> I'll take a shot. On first look, we're using the generic WebResponse which
> doesn't support status codes. Is it safe to assume all our sync URIs are going
> to be HTTP?

Yes.  I've had this change applied locally from time to time, using HttpWebResponse:

http://armstrong-clan.net/dump/better-websync-debugging.diff

> Also, I can test against a generic http server, but I'm not sure how I'm going
> to force a 500 on a U1 server.

Well, you'd be better of setting up a local install of Snowy.  I'll have to look at api/handlers.py in Snowy to see how to get what errors, although there is also Snowy bug #591456 filed saying that we don't return useful enough errors (need to make them part of the websync API spec, really)
Comment 10 Sandy Armstrong 2010-10-29 06:45:31 UTC
Created attachment 173462 [details] [review]
Crass extra debugging patch

Attaching the patch just for completeness.

All it does it print stuff to the log, which is nice, but not as useful as having errors that Tomboy understands and can explain to the user.
Comment 11 Sandy Armstrong 2010-10-29 06:46:25 UTC
And obviously, my patch does not check the status code ahead of time, but after the fact...another reason why it's not really correct.
Comment 12 Aaron D Borden 2010-11-07 21:26:34 UTC
[ERROR 13:09:56.055] Caught exception. Message: The remote server returned an error: (503) SERVICE UNAVAILABLE.
[ERROR 13:09:56.056] Stack trace for previous exception:   at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x002b1] in /var/tmp/portage/dev-lang/mono-2.6.7/work/mono-2.6.7/mcs/class/System/System.Net/HttpWebRequest.cs:1448 

Apparently HttpWebRequest has a CheckFinalStatus () that throws an exception when the status code >=400 (and I can't find an info on changing this behavior). So we already handle this case in our top-level try-catch. However, we could be improve this by having different messages depending on the status code. I can think of 2:
4xx "Error contacting <domain> please check your settings and try again"
5xx "Internal server error, please try again later"

For this scenario described in the trace above, we're basically handling a case where Snowy returns a valid status code, but the response is no good. We can improve the error handling here by 
1. Checking response is JSON
2. If we get an error on parsing, show "Internal server error, please try again later"

For handling the GUI part of it, I suggest extending SyncDialog so we can set the message text.
Comment 13 Aaron D Borden 2010-11-12 07:50:55 UTC
Created attachment 174308 [details] [review]
Improve error handling/reporting during sync

I can split this into smaller patches if necessary.

The idea is we use TomboySyncException to communicate messages to the user. The SyncUI is extended so the message text can be set on failure to display any exception messages.
Comment 14 Sandy Armstrong 2010-11-12 10:04:34 UTC
Thanks for the recent patches.  I am behind on Tomboy patch review as I try to get some Snowy work merged for an upcoming release.  Just want to let you know that this patch is totally on my radar and I'll get to it as soon as I can.
Comment 15 Aaron D Borden 2011-02-20 06:16:59 UTC
bump: patch contains new strings, needs review before string freeze
Comment 16 André Klapper 2017-07-31 12:48:21 UTC
The Tomboy team has moved from GNOME Bugzilla to GitHub for bug reports and feature requests: 
      https://github.com/tomboy-notes/tomboy/issues/
Closing this report as NOTGNOME as part of Bugzilla Housekeeping (bug 781054) to keep tasks in one place. Please feel free to transfer this task to GitHub if this task is still valid in a recent Tomboy version. 
We are sorry for the inconvenience.