How to use the weblate.utils.errors.report_error function in weblate

To help you get started, we’ve selected a few weblate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github WeblateOrg / weblate / weblate / trans / models / translation.py View on Github external
    @transaction.atomic
    def update_units(self, author_name, author_id):
        """Update backend file and unit."""
        updated = False
        for unit in self.unit_set.filter(pending=True).select_for_update():
            # Skip changes by other authors
            change_author = unit.get_last_content_change()[0]
            if change_author.id != author_id:
                continue

            try:
                pounit, add = self.store.find_unit(unit.context, unit.source)
            except UnitNotFound as error:
                report_error(error, prefix='String disappeared')
                pounit = None

            unit.pending = False

            # Bail out if we have not found anything
            if pounit is None:
                self.log_error('disappeared string: %s', unit)
                unit.save(update_fields=['pending'], same_content=True)
                continue

            # Check for changes
            if (
                (not add or unit.target == '')
                and unit.target == pounit.target
                and unit.approved == pounit.is_approved(unit.approved)
                and unit.fuzzy == pounit.is_fuzzy()
github WeblateOrg / weblate / weblate / trans / models / component.py View on Github external
self.repository.update_remote()
                timediff = time.time() - start
                self.log_info("update took %.2f seconds", timediff)
                if previous:
                    self.log_info(
                        "repository updated from %s to %s",
                        previous,
                        self.repository.last_remote_revision,
                    )
                for line in self.repository.last_output.splitlines():
                    self.log_debug("update: %s", line)
                if self.id:
                    self.delete_alert("UpdateFailure")
            return True
        except RepositoryException as error:
            report_error(error, prefix="Could not update the repository")
            error_text = self.error_text(error)
            if validate:
                self.handle_update_error(error_text, retry)
                return self.update_remote_branch(True, False)
            if self.id:
                self.add_alert("UpdateFailure", error=error_text)
            return False
github WeblateOrg / weblate / weblate / utils / backup.py View on Github external
def borg(cmd, env=None):
    """Wrapper to execute borgbackup."""
    SSH_WRAPPER.create()
    try:
        return subprocess.check_output(
            ["borg", "--rsh", SSH_WRAPPER.filename] + cmd,
            stderr=subprocess.STDOUT,
            env=get_clean_env(env),
        ).decode("utf-8")
    except EnvironmentError as error:
        report_error(error)
        raise BackupError("Could not execute borg program: {}".format(error))
    except subprocess.CalledProcessError as error:
        report_error(error, extra_data={'stdout': error.stdout.decode("utf-8")})
        raise BackupError(error.stdout.decode("utf-8"))
github WeblateOrg / weblate / weblate / trans / models / component.py View on Github external
kwargs = {"message": render_template(self.merge_message, component=self)}

        with self.repository.lock:
            try:
                previous_head = self.repository.last_revision
                # Try to merge it
                method_func(**kwargs)
                self.log_info(
                    "%s remote into repo %s..%s",
                    method,
                    previous_head,
                    self.repository.last_revision,
                )
            except RepositoryException as error:
                # Report error
                report_error(error, prefix="Failed {}".format(method))

                # In case merge has failer recover
                error = self.error_text(error)
                status = self.repository.status()

                # Log error
                if self.id:
                    Change.objects.create(
                        component=self,
                        action=action_failed,
                        target=error,
                        user=request.user if request else None,
                        details={"error": error, "status": status},
                    )
                    self.add_alert("MergeFailure", error=error)
github WeblateOrg / weblate / weblate / utils / backup.py View on Github external
def borg(cmd, env=None):
    """Wrapper to execute borgbackup."""
    SSH_WRAPPER.create()
    try:
        return subprocess.check_output(
            ["borg", "--rsh", SSH_WRAPPER.filename] + cmd,
            stderr=subprocess.STDOUT,
            env=get_clean_env(env),
        ).decode("utf-8")
    except EnvironmentError as error:
        report_error(error)
        raise BackupError("Could not execute borg program: {}".format(error))
    except subprocess.CalledProcessError as error:
        report_error(error, extra_data={'stdout': error.stdout.decode("utf-8")})
        raise BackupError(error.stdout.decode("utf-8"))
github WeblateOrg / weblate / weblate / trans / views / files.py View on Github external
message = _("No strings were imported from the uploaded file.")
        else:
            message = ungettext(
                "Processed {0} string from the uploaded files "
                "(skipped: {1}, not found: {2}, updated: {3}).",
                "Processed {0} strings from the uploaded files "
                "(skipped: {1}, not found: {2}, updated: {3}).",
                total,
            ).format(total, skipped, not_found, accepted)
        if accepted == 0:
            messages.warning(request, message)
        else:
            messages.success(request, message)
    except Exception as error:
        messages.error(request, _("File upload has failed: %s") % force_text(error))
        report_error(error, request, prefix="Upload error")

    return redirect(obj)
github WeblateOrg / weblate / weblate / trans / models / component.py View on Github external
def repo_needs_push(self):
        """Check for something to push to remote repository."""
        try:
            return self.repository.needs_push()
        except RepositoryException as error:
            report_error(error, prefix="Could check push needed")
            self.add_alert("PushFailure", error=self.error_text(error))
            return False
github WeblateOrg / weblate / weblate / runner.py View on Github external
def main(argv=None):
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "weblate.settings")
    os.environ['DJANGO_IS_MANAGEMENT_COMMAND'] = '1'

    from django.core.management import execute_from_command_line

    if argv is None:
        argv = sys.argv
    try:
        execute_from_command_line(argv)
    except Exception as error:
        from weblate.utils.errors import report_error
        report_error(error)
        raise