In the event of a breach of the formalities prescribed by law on pain of nullity or failure to observe essential formalities, the liberty and custody judge to whom an application on this ground is made or who notes such an irregularity of his own motion may only order the release of the detainee or his continued detention where this has had the effect of infringing the rights of the foreign national.