#2133 Errs on Service.start()

SlimerDude Sat 13 Apr 2013

I find the following behaviour quite annoying - if a service throws an error on startup, it continues to behave as if everything is / was okay.

For example:

class CupOfTea {
  static Void main(Str[] args) {
    service := BoomService().start
    if (service.isInstalled && service.isRunning)
      echo("Service is running... every is okay")
  }
}

const class BoomService : Service {
  override Void onStart() {
    throw Err("BOOM! I just died a horrible death!")
  }
}

prints Service is running... every is okay

May I ask for Service.start() to rethrow any Errs that occurred during onStart()? Or at the very least not to set the running flag and pretend everything is okay.

For at the moment, there is no (generic) programmatic way to tell if a Service started properly or not.

brian Sat 13 Apr 2013

It is sort of a breaking change, but I'm comfortable making it as long as there are no objections. So the change would be that if onStart raises an exception, then the server is not marked started and the start method raises the exception too. And the same for onStop? Not sure I like it for onStop, but if we don't do it there a bit inconsistent.

SlimerDude Sat 13 Apr 2013

Yeah, I think it should be the same for onStop() too. For if an Err is thrown, then in all probability the service hasn't stopped! (Regardless of what isRunning says.)

brian Thu 18 Apr 2013

Promoted to ticket #2133 and assigned to brian

brian Mon 20 May 2013

Ticket resolved in 1.0.65

I decided that there is too many ugly boundary conditions with onStop not causing a real stop or real uninstall - its sort of like how OutStream.close doesn't ever raise an exception. But I fixed an exception raised by onStart to not transition the service to the running state.

Login or Signup to reply.