  Whether it is at the fabrication stage or during the course of the quantum
computation, e.g. because of high-energy events like cosmic rays, the qubits
constituting an error correcting code may be rendered inoperable. Such defects
may correspond to individual qubits or to clusters and could potentially
disrupt the code sufficiently to generate logical errors. In this paper, we
explore a novel adaptive approach for surface code quantum error correction on
a defective lattice. We show that combining an appropriate defect detection
algorithm and a quarantine of the identified zone allows one to preserve the
advantage of quantum error correction at finite code sizes, at the cost of a
qubit overhead that scales with the size of the defect. Our numerics indicate
that the code's threshold need not be significantly affected; for example, for
a certain scenario where small defects repeatedly arise in each logical qubit,
the noise threshold is $2.7\%$ (versus the defect-free case of $2.9\%$). These
results pave the way to the experimental implementation of large-scale quantum
computers where defects will be inevitable.
