Posts Tagged ‘errors’

PHP complains date.timezone is not set

Wednesday, November 28th, 2012 | Programming, Tech

Sometimes, PHP will kick up a fuss complaining about date.timezone not being set. We found this on the Symfony framework and were able to replicate it on standalone scripts.

[Exception]
DateTime::__construct(): It is not safe to rely on the system's timezone settings.
You are required to use the date.timezone setting or the date_default_timezone_set()
function. In case you used any of those methods and you are still getting this
warning, you most likely misspelled the timezone identifier.
We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead

Normally, you would fix this by editing your php.ini file and adding a declaration there.

date.timezone = "Europe/Berlin"

But we had already done this and it still wasn’t working! After some further investigation, it seemed that PHP simply couldn’t access the value.

echo(ini_get("date.timezone"));

This doesn’t make any sense, and we never got to the bottom of what was going on, but there are two ways around the problem. Firstly, you could modify your PHP script so that it makes a call to set the system timezone.

date_default_timezone_set("Europe/Berlin");

However, this involves having to modify your code, which is bad as you don’t want to have to set the timezone manually, especially in a piece of code which could be deployed to servers in different timezones.

A better approach is to set it in the vhosts directive in Apache.

php_value "date.timezone" "Europe/Berlin"

This isn’t the cleanest solution but allowed us to solve an otherwise unexplainable error.

Not “Go”ing anywhere

Friday, March 16th, 2012 | Tech

I recently requested an evaluation of Go, an agile release management tool from ThoughtWorks Studios.

I filed out the form but unfortunately it insisted I hadn’t filled out my city, even though I had. So I sent a support request to them and a few hours later, someone emailed me back asking where I was based so they could direct my query. I told them, but never heard back from them.

A month later I got an email from one of their sales guys asking me how I had got on with my evaluation. I emailed them back saying I never actually had an evaluation because they had never got in touch. He apologised and sent through my license key. However, at this time I was on my Mac, so I had to download the Mac client. I went to the website and this time I managed to register and download the software. Great, I thought.

Unfortunately, I didn’t get time to look at it until I was back in the office and by that time I was back on my Windows machine, so I needed to download the Windows version. I went to the website and tried to enter my email address I had used last time I registered to download.

But I just got an error. So I tried again. Another error, different this time. So I tried to go through the whole registration process again, but this once again went back to telling me that I hadn’t entered my city when in fact I had.

I sent their support another email asking for the direct download links and having been sent them, I was finally able to download and install the server. Huzzah! So I did that, but then didn’t really know what to do. It said it had started the sever, which was fine, but there was no indication of what to do next.

After some googling, I eventually found the URL I was supposed to access the dashboard with and entered that into my browser, but didn’t get anything. I tried restarting the server, no luck. I tried running it from the jar. No luck. I even tried uninstalling and reinstalling it. Still nothing.

I decided to boot up my CentOS virtual machine and try installing it there. I downloaded it and tried to run the installer but it told me I needed JDK 1.6 or greater. A quick search through yum and I had it installed. I tried to run the installer again and I got the same error, even though I now had JDK installed.

Eventually, after searching the web for awhile, I found out that they didn’t support OpenJDK yet (you know, the JDK that everyone on Linux uses) so you have to install it using the ignore dependencies flag. Finally, it installed.

It then said that Go Server was up and running and so I tried to access the URL, but it did not work. I tried Apache, and that was working fine, so my virtual machine was working fine, it was just Go Server. By this time it was quite late so I turned everything off and headed home.

The next day I got in early to have a play around with it. I booted up the virtual machine and tried to start Go Server using the service command. All I got was “Error starting Go Server”. I tried googling the phrase, but apparently, it had never before been seen on the internet.

I tried googling some more and eventually found a post that seemed to have the same problem that I had. They eventually found that the problem was to do with the hostname. I couldn’t find any way to change the hostname though, so decided to try the Windows approach and remove and reinstall it. This didn’t work either.

I tried to go look it up in the online documentation, but their website was down again with a 500 error. I waited a few minutes and did a couple of refreshes and eventually it reappeared, but I couldn’t find a solution.

By this point, I had wasted far too much time on this, so I gave up. My advice is, go elsewhere for such software.

Trapping errors in Visual Basic

Thursday, December 30th, 2004 | Programming, Tech

If you keep coming up with problems in your applications and you don’t want error messages to be popping up when the user causes an error then all you need to do is add an error handler. In fact, you should be doing this anyway, just in case errors come up.

On Error

There are two options from here. You can either get it to ignore the error or do something else that sorts the error out. If you just want the error to be ignored use this.

On Error Resume Next

This will simply execute the next line of code after one with the error on. This could stop your application doing something important but lets face it, however there are times when you legitimately want to stop an error and ignore it. Usually it is just used then there is a problem such as when you are using the web browser control and a user clicks back when there is no page to go back to. This would normally bring up an error box but by adding in the code it stops this from happening.

Your other alternative is to add in a GOTO command to send the code to do something else if it finds an error. Take a look at this example.

On Error Goto 10
WebBrowser1.GoBack
Exit Sub
10 ' error bit
MsgBox ("Error!")
' some code to sort it out
End Sub

Suppressing JavaScript errors

Thursday, December 30th, 2004 | Programming, Tech

What is the most annoying thing you cant think of? Well ok, JavaScript error aren’t that annoying but nobody likes them. What we need is a simple script that stops all the JavaScript erros from appearing. This is a pretty simple script which is short so lets dive straight into the code.

<script>
function stoperror(){
return true
}
window.onerror=stoperror
</script>

Just stick the script into the head tag. Although the above alert method is invalid (no closing quotations), no errors will be generated. This script will suppress all potential errors in a page, so be sure to turn it off while test running a script.

Of course, a much better solution, is to actually write JavaScript that works.