Artisan Développeur

Qualité, amélioration continue, agilité, professionnalisme.

Results for category "Blog"

37 Articles

Symfony error: 500 Internal Server Error – SyntaxErrorException

This article is at first a reminder for me, and if it can helps someone it’s even better 😉

When you work with a ORM (Doctrine for me, with Symfony) you have to think data as entities, objects instead of  database tables.

You are moving away from database (mariaDB in my case) and his constraints, it is a good thing for severals points, but there is one you can forget about and time to time you fall into his trap, and you get a really pretty error message.

An exception occurred while executing ‘INSERT INTO my_table (createdAt, updatedAt, name, commercialName, VAT,  oneField, anotherField, foo, bar, again, andAgain, default) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)’ with params [« 2018-02-23 13:55:24 », « 2018-02-23 13:55:24 », « my company », « really nice company », « 20 », null, « 1 », « 0 », null, null, null, null, 0]:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘default) VALUES (‘2018-02-23′ at line 1’
500 Internal Server Error – SyntaxErrorException
2 linked Exceptions:

PDOException

No more suspense here, the trap is quite simple and very basic, it’s the reserved keywords.

Reserved Keywords needs to be managed correctly if you want to use them, below see a real life example:

I need to know if a company is the default one for my user, I add a property name « default » (I use annotations for the doctrine mapping) and bam, SQL is broken.

    /**
     * @ORM\Column(type="boolean", nullable=false)
     */
    private $default = false;
doctrine field

The above  error message is pretty clear when you think about the keywords, because Doctrine use the property name to create the database field, the new field is:

`default` tinyint(1) NOT NULL

And when you want to insert a company:

INSERT INTO my_table (createdAt, updatedAt, [...], default ) 

« default » is not quoted, and mariaDb rise an error.

Fortunately we have several solutions, and my personal (subjective) choice:

Rename your property to something not reserved like « defaultCompany »

$company->isDefaultCompany();

I don’t like that, because the entity is a Company, if you name your variable $company to store it, it is not nice to read.

Quote the field name (in the annotations – doc here)

    /**
     * @ORM\Column(name="`default`", type="boolean", nullable=false)
     */
    private $default = false;

I don’t like this one either, it is better than the first but it can lead to complications (see the linked documentation)

Force a field name with the annotations

    /**
     * @ORM\Column(name="defaultCompany", type="boolean", nullable=false)
     */
    private $default = false;

Since we need to add the name of the database field if we want to quote it, I prefer have a non reserved keyword, unquoted, and never be worried by some obscure bug or malfunction because I want so bad to use this field name.

With Doctrine you are almost never in the database, it is not a big deal to have a « defaultCompany » field in the « company » table.

It is bother me when I read my code, but I don’t spend time in the SQL, I prefer have this little ugliness in my DB than in my code.

 

Jenkins log is huge, dns log errors …

If like me you have the bad surprise to have a full partition on your disk, with the consequences we can imagine, you perhaps found that Jenkins have a log file outrageously big…

Full of:

[DNSQuestion@809381925 type: TYPE_IGNORE index 0, class: CLASS_UNKNOWN index 0, name: ]

After a quick research it is really Jenkins fault because of an annoying bug :

Jenkins dns error log bug

As you can see it’s an old bug:

Created:
Updated:

And since it’s minor no one seams to work on it…

Workaround here, thanks as always to the stackoverflow community 😉

https://stackoverflow.com/questions/31719756/how-to-stop-jenkins-log-from-becoming-huge

You can disable the logging of these DNS errors by adjusting the logging settings within Jenkins.

From the Jenkins web interface go to:

 Manage Jenkins -> System Log -> Log Levels (on the left)
Add the following entry:

Name: javax.jmdns

Level: off
This way you can keep the Multicast DNS feature but without all the logging data.

And to claim your space on your disk 😉

Before:

udev               3,9G       0  3,9G   0% /dev
tmpfs              803M     79M  724M  10% /run
/dev/xvda2          54G     54G     0 100% /
tmpfs              4,0G       0  4,0G   0% /dev/shm
tmpfs              5,0M       0  5,0M   0% /run/lock
tmpfs              4,0G       0  4,0G   0% /sys/fs/cgroup
service jenkins stop
rm /var/log/jenkins/jenkins.log
df -h #to check your space left

After:

udev               3,9G       0  3,9G   0% /dev
tmpfs              803M     79M  724M  10% /run
/dev/xvda2          54G     13G   39G  25% /
tmpfs              4,0G       0  4,0G   0% /dev/shm
tmpfs              5,0M       0  5,0M   0% /run/lock
tmpfs              4,0G       0  4,0G   0% /sys/fs/cgroup

Feels good !

 

Using mylvmbackup, debian 9 with mariadb

If you run mylvmbackup with mariadb on debian9 with the defaults values, you will have this:

mycnf=/etc/mysql/my.cnf

But it is a symlink pointing to :

/etc/alternatives/my.cnf

And mylvmbackup can’t work with that:

Could not copy /etc/mysql/my.cnf to /var/cache/mylvmbackup/mnt/backup-cnf-20171025_151739_mysql: File exists

Here is a bug report mylvmbackup symlink my.cnf

 

You just need to setup the mycnf as follow, in the /etc/mylvmbackup.conf or directly in the command line (with –mycnf= ):

mycnf=/etc/mysql/mariadb.cnf

Done ! Now mylvmbackup stop complaining 🙂