Why do minor errors crash my SproutCore application?

77 Views Asked by At

While developing, these errors end up in the console, and a lot of them don't impact my application. But once I get in production, any minor error will bring up the "this application crashed!" message and the only option is to reload. Why does SproutCore crash my app out at the drop of a hat?

2

There are 2 best solutions below

1
On BEST ANSWER

Web developers are used to being able to let minor errors go unnoticed. This is appropriate: since short-lived websites often have minimal local state to maintain, many minor errors won't impact the user experience, so it may not be worth the development time required to fix them.

Application developers, on the other hand, are used to having to carefully handle errors. In desktop .NET or Cocoa, for example, the operating system will proactively crash an application that throws an unhandled error. This is because applications generally assume that they are long-lived, and have to manage an internally-consistent state. An error is a sign that this internal state has likely become unmanaged & unstable, and in order to prevent unexpected (or worse) behavior, the application must be terminated.

SproutCore is a collection of full-featured application development frameworks for use in the browser, and a SproutCore web app differs from short-lived, largely stateless web pages in a number of ways. Most importantly to this discussion, they are very application-y in terms of their long lifetime and robust internal state. As with desktop applications, unhandled errors are an indication that your SproutCore app's internal state has likely become unmanaged and unpredictable. Since SproutCore has no way to determine whether a particular error is benign or problematic, it shuts the whole thing down – just like other application systems.

SproutCore doesn't crash the app as aggressively in development mode in order to give you a chance to examine the error's cause and fallout to determine how to handle it. So to build robust, stable web applications, just keep an eye on your console, and either prevent or handle any errors that pop up.

1
On

Dave's answer is perfect, but I'll just add one bit of technical detail:

When in a production build, Sproutcore attaches a handler to the browser's javascript onerror event. This way, the user gets visual feedback that there was an issue, rather than have the app just suddenly stop responding to any input.

However, in some browsers the onerror handler can prevent a developer from seeing the full stack trace of the original issue. Thus in development mode (using sc-server or similar), the handler is not used and the exception is not addressed at all by Sproutcore. Then the browser will do something like log it to the console where you can see the original cause. I also recommend setting the developer console to 'break on uncaught exception', so that it lets you inspect the context where the error occurred.