How to view static content deploy errors in Magento 2?

Magento users when running php bin/magento setup:static-content:deploy have had some errors in their theme and they have to go through all the LESS file to check for errors manually. In fact, there are several types of errors that can be triggered by the deployment.

First you can see that Exception is handled directly in the execution in Magento/Deploy/Console/Command/DeployStaticContentCommand.php:

catch (\Exception $e) {
        $output->writeln('<error>' . $e->getMessage() . '</error>>');
        if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
            $output->writeln($e->getTraceAsString());
        }
        return;
}

To regard the errors that are counted, you need to look into the Magento/Deploy/Model/Deployer class, and the output you got is written by the deploy() method:

$this->output->writeln("\nSuccessful: {$this->count} files; errors: {$this->errorCount}\n---\n");

Now if you check when this errorCount variable is incremented, we will find the in the deployFile() method as below:

catch (\Exception $exception) {
        $this->output->write('.');
        $this->verboseLog($exception->getTraceAsString());
        $this->errorCount++;
}

And the verboseLog() method will just outputs when the command is run on verbose mode:

private function verboseLog($message)
{
    if ($this->output->isVerbose()) {
        $this->output->writeln($message);
    }
}

And then you need to run following command to see the errors:

php bin/magento setup:static-content:deploy -v

If it doesn't work, you will try the extra verbose:

php bin/magento setup:static-content:deploy -vv
php bin/magento setup:static-content:deploy -vvv

This tutorial will help you save time much when finding static content errors in your Magento 2 website.